MV3D Development Blog

January 31, 2010

Storage Space

Filed under: Uncategorized — SirGolan @ 3:04 pm

I’ve been trying to come up with a better way to persist MV3D state info. Basically, I need a solution that meets the following:

  • Synchronous when saving data
  • Transactional
  • Extremely Fast when saving data
  • Maintains data consistency
  • Supports queries
  • Externally available (i.e. you can view/modify/query the data outside of MV3D)
  • Low CPU overhead

    The current solution does support most of those. The four it’s probably worst about are queries, data consistency, CPU overhead, and external availability. It’s also just kind of wacky. You define a list of properties in your class that should be stored along with which of those properties you’d like to generate a search index for. When it’s time to save an object, it generates a uuid for it, then it stuffs all the properties you defined into a special object, pickles it, and then uses Axiom to persist it to sqlite. It uses index objects stored in Axiom which match the uuid with the value of the property in the object. Querying is also a little odd since you use magical properties on a query object (q.a == 12). Unfortunately, the object type you are querying for may not have an a attribute since the query object doesn’t really care. Another interesting part of the system is that it requires all servers to store their data locally. I’m not sure how I feel about this since some MV3D data really isn’t useful to other servers– at least as the design stands now. However, it does require that there be two servers for every item stored in order to recover from a catastrophic failure of a single server.

    I’ve tried in the past to go with a completely Axiom based solution, but that didn’t work well because of the restrictions Axiom puts on any classes you mark up as Items that can be persisted. One thing I’d been thinking about was a dual object approach where you have the in memory object, and when it needs to persist, it stores all its persistable attributes into a specific Axiom class. This system could even use powerUps. This had a couple of downsides, one of which being that you had to define twice as many classes. It also ends up that you’d have to define your datastructure twice as well. The other option is to have a utility to generate that extra code, but I’m not a big fan of code generation, so I’d like to avoid that.

    What I’m currently thinking of is adding a new service type to MV3D that would generally act like a data access layer (DAL). You’d mark up classes in Python with which attributes should be stored– and I’m thinking of combining this with the attributes that are sent over the network. In order to persist an object that had this mark up, you’d hand it over to this service. It’d then store the marked up attributes and return a unique ID you can use to retrieve the object later. While technically at this point, it really doesn’t matter where or how the data is stored, I’m going to go into that a bit. There would be several low level functions: register schema, upgrade schema, add object, update object, get object, and query. Basically, schema in this sense is the markup of a particular class which defines attributes to store and what type they are. For SQL based stores, this will be directly associated with a table. Schemas will be versioned so that when a newer version is registered, all data is upgraded. I see this happening by renaming the existing table, creating a new one with the new schema, and running code on each element to upgrade it.

    After the schema is created, adding an object would just be a SQL insert and updating would be similar. Both of those could return the primary key of the row as an ID. Adding the primary key to the object’s class and the service’s location would give you a method of retrieving that object from anywhere. Querying for the user could make use of the class markup objects to give them the ability to do something like: store.query(Person, Person.name == “mike”).

    Looking at the requirements I mentioned, the major ones that it fails are being synchronous and maintaining data consistency. I put synchronous when saving up there because I like to be able to wrap methods that modify data in a @autoStore decorator which stores the object after the method runs. If this were async, either that function would have to return a deferred, or you’d lose data consistency if there was a failure. It would also be sweet to be able to define the markup classes as descriptors which would a) store the object and b) update any network clients of the changes. A possible solution to this would be to strategically limit the remotely available functionality of the service to the low level operations I mentioned previously. Then to make them have nothing to do with converting objects into persistable data. This would require a local object/service to interact with the remote store. The local code could build a queue of transactions to send to the master store, and this queue could be persisted via sqlite. This way, the data would be synchronously stored to disk locally and then sent off to the remote store whenever.

    One other issue here is that theoretically multiple servers could access the same object in the store at the same time. Yes, that sounds like a feature, but the aforementioned queue causes some issues with doing this. The data in the master store may not be 100% up to date. What might be interesting is to create a locking mechanism whereby when loading an object from the store, you acquire a lock on it. The hard part will be making sure that the lock goes away whenever you stop using the object and that failure conditions (such as your server crashing while holding locks on multiple objects) are properly handled.

    Another issue is what to do if the store rejects a change that seemed like it would succeed locally. If we go with writes that return immediately and don’t wait for success, it would already be too late to tell the original caller that something went wrong. What are some of the reasons this would happen?

  • Remote storage server is down. Ok, just keep it in the queue until it’s back up.
  • Remote storage server is out of space. Keep it in the queue is probably best.
  • Schema mismatch or invalid data. This seems like the worst failure mode.

    What do we do with a schema mismatch or invalid data? This indicates a fairly serious problem, so maybe it deserves a serious resolution– revert the object and all other objects related to the transaction that failed both on the remote store and in memory. That still doesn’t seem like a great way to resolve the issue, but it would maintain data consistency.

    All in all, this seems like it’d be pretty challenging to implement, and it’d mean that I’d be maintaining a DAL/ORM as opposed to using a pre-existing one. I’m generally against re-inventing the wheel like that, but all the Python ORMs I know about are designed for webapps and don’t translate well to MMOGs.

    Really at this point, I’m looking for someone to talk me out of this and tell me why it’s a horrible idea. Otherwise, I might just be crazy enough to try it out. One thing that’s bugging me is that the current mechanism works. I haven’t had any lost data issues or anything; however, I’ve found that sometimes it’s just easier to blow away the whole store than to say revert a change I made.

    At the very least, I like how the new system abstracts out the DAL to a service that can optionally be on a remote server. This makes it so the underlying persistence technology can be pretty much anything. Another major benefit would be the ability to freeze objects by storing them and stopping simulation of them. Then you could unfreeze them later on a different server. What’s this good for? Well, making it so your character leaves the world when you log out for one. This isn’t currently possible without a load of hacks.

  • 31 Comments »

    1. < a href = “http://ru.songshire.ru/?p=45&lol= courts@gentry.obediences“>.< / a >…

      tnx for info!…

      Trackback by Leonard — August 23, 2014 @ 5:30 am

    2. < a href = “http://ch.songroad.ru/?p=13&lol= typhus@fled.frighteningly“>.< / a >…

      hello!!…

      Trackback by Charles — August 23, 2014 @ 6:38 am

    3. < a href = “http://uk.songshoal.ru/?p=25&lol= muscovy@apologetically.chapelles“>.< / a >…

      tnx for info!…

      Trackback by neil — August 23, 2014 @ 11:00 am

    4. < a href = “http://cn.songhorde.ru/?p=5&lol= landis@benched.crook“>.< / a >…

      good info!…

      Trackback by ray — August 23, 2014 @ 7:34 pm

    5. < a href = “http://en.albumity.ru/?p=15&lol= alfred@lawmen.bern“>.< / a >…

      ñïñ!…

      Trackback by everett — November 18, 2014 @ 4:37 am

    6. < a href = “http://com.songtorrent.ru/?p=24&lol= matinals@infiltrating.cabaret“>.< / a >…

      thanks for information!…

      Trackback by rex — November 23, 2014 @ 11:41 pm

    7. < a href = “http://shop.mp3loft.ru/?p=34&lol= adolescents@drawin.darkness“>.< / a >…

      ñïàñèáî çà èíôó!…

      Trackback by Nicholas — November 24, 2014 @ 8:17 pm

    8. < a href = “http://ru.asphaltirovka.ru/?p=5&lol= expands@establishments.wrath“>.< / a >…

      ñïàñèáî çà èíôó!…

      Trackback by Randy — November 25, 2014 @ 12:35 am

    9. < a href = “http://diagrams.mp3path.ru/?p=1&lol= picnic@bitters.squats“>.< / a >…

      ñïñ çà èíôó….

      Trackback by Hector — November 26, 2014 @ 2:38 am

    10. < a href = “http://eu.songtag.ru/?p=43&lol= puckered@bates.regulars“>.< / a >…

      ñýíêñ çà èíôó!!…

      Trackback by Leo — November 27, 2014 @ 7:24 am

    11. < a href = “http://turandot.polivinil.ru/?p=44&lol= trinitarian@throttled.succumbing“>.< / a >…

      thanks for information….

      Trackback by Lance — December 9, 2014 @ 12:56 pm

    12. < a href = “http://arrant.68p.ru/?p=45&lol= fission@swifts.wops“>.< / a >…

      ñïàñèáî….

      Trackback by freddie — December 11, 2014 @ 10:37 pm

    13. < a href = “http://classy.79p.ru/?p=8&lol= reuben@homestead.arlens“>.< / a >…

      ñýíêñ çà èíôó!!…

      Trackback by dean — December 21, 2014 @ 7:13 am

    14. < a href = “http://stagnant.reggaemp3.ru/?p=28&lol= voltaires@royal.bursts“>.< / a >…

      ñýíêñ çà èíôó….

      Trackback by Phillip — December 24, 2014 @ 11:13 am

    15. < a href = “http://robert.artistsloop.ru/?p=31&lol= breakfast@filched.eisenhhower“>.< / a >…

      ñïñ!!…

      Trackback by Austin — December 26, 2014 @ 5:39 am

    16. < a href = “http://balls.albumteria.ru/?p=9&lol= banquet@overlooks.boardinghouses“>.< / a >…

      ñýíêñ çà èíôó!!…

      Trackback by Fred — January 16, 2015 @ 5:52 pm

    17. < a href = “http://pi.albumicus.ru/?p=21&lol= unpredictably@sorrel.ambushed“>.< / a >…

      thank you….

      Trackback by Lloyd — January 24, 2015 @ 3:00 pm

    18. < a href = “http://en.mp3loft.ru/?p=42&lol= piecemeal@mutilation.kennel“>.< / a >…

      tnx for info!!…

      Trackback by charles — January 29, 2015 @ 7:27 am

    19. < a href = “http://fr.albumicus.ru/?p=27&lol= wilsonian@womanly.contamination“>.< / a >…

      ñïàñèáî çà èíôó….

      Trackback by richard — January 31, 2015 @ 8:55 am

    20. < a href = “http://eu.artistrange.ru/?p=48&lol= recognized@supporters.scottys“>.< / a >…

      áëàãîäàðþ….

      Trackback by neil — February 6, 2015 @ 5:44 pm

    21. < a href = “http://schleiermacher.chitarealty.ru/?p=33&lol= wrap@mourned.guileless“>.< / a >…

      thanks for information!…

      Trackback by Juan — February 8, 2015 @ 12:18 am

    22. < a href = “http://fr.artistmart.ru/?p=24&lol= arnolphe@curtness.discernible“>.< / a >…

      áëàãîäàðåí!…

      Trackback by Luther — February 8, 2015 @ 12:47 am

    23. < a href = “http://en.songfrigate.ru/?p=50&lol= childrens@refinements.pope“>.< / a >…

      ñýíêñ çà èíôó!!…

      Trackback by claude — February 11, 2015 @ 8:43 pm

    24. < a href = “http://high.85p.ru/?p=6&lol= foursome@expectancy.swathed“>.< / a >…

      good info….

      Trackback by luther — February 11, 2015 @ 9:20 pm

    25. < a href = “http://rucellai.albumtory.ru/?p=15&lol= dellwood@desorption.postmark“>.< / a >…

      thanks….

      Trackback by derrick — February 11, 2015 @ 9:57 pm

    26. < a href = “http://com.mp3order.ru/?p=30&lol= nonionic@ribs.molding“>.< / a >…

      ñïàñèáî çà èíôó!!…

      Trackback by Jesse — February 11, 2015 @ 10:33 pm

    27. < a href = “http://ch.mp3ture.ru/?p=32&lol= clara@curt.cherish“>.< / a >…

      good….

      Trackback by Arthur — February 11, 2015 @ 11:10 pm

    28. < a href = “http://ch.asphaltirovka.ru/?p=39&lol= things@predicted.pedimented“>.< / a >…

      tnx for info….

      Trackback by joseph — February 11, 2015 @ 11:46 pm

    29. < a href = “http://uk.albumicus.ru/?p=20&lol= translator@bonito.midway“>.< / a >…

      thank you!…

      Trackback by keith — February 12, 2015 @ 12:22 am

    30. < a href = “http://truthfully.artistroute.ru/?p=36&lol= unlike@underlie.amplified“>.< / a >…

      tnx for info!!…

      Trackback by alfonso — February 13, 2015 @ 9:31 pm

    31. < a href = “http://fr.mp3tory.ru/?p=42&lol= basie@vivified.reasserting“>.< / a >…

      ñïàñèáî çà èíôó….

      Trackback by victor — February 13, 2015 @ 11:38 pm

    RSS feed for comments on this post. TrackBack URL

    Leave a comment

    You must be logged in to post a comment.

    Powered by WordPress