Re: Migrating to BTrees 4.x
Jason Madden <[email protected]>
| Newsgroups | gmane.comp.web.zope.zodb |
|---|---|
| Message-ID | <[email protected]> |
> On Nov 19, 2016, at 14:21, David Glick <[email protected]> wrote: > > I'm working on updating Plone to support ZODB 4 and 5. > ... > > Any ideas about how I can write a migration script to fix these BTree instances *after* the BTrees package has been updated? I guess I'm looking for a hook to adjust the state for a particular class before __setstate__ is called, since BTrees are extension types and I can't override __setstate__. If you've got a way to override __setstate__ that will do what you want, then you may have an option. BTrees 4 now ships with a pure-python implementation that should allow you to replace __setstate__. It will be used if the C extension isn't available, or, more helpfully, if the PURE_PYTHON environment variable is set at startup. If that's not an option, then with a little bit of work, it can be swapped in at runtime and later swapped back out. If you replace __setstate__ an the pure-python implementation, you could swap it in, unpickle the BTrees in the database to perform your fixes, pickle them back, and reverse the swap. Note that you'll need the BTrees 4.3.0 release to make sure that the pickles are correct. from BTrees import OOBTree # Patch __setstate__ OOBTree.OOBTreePy.__setstate__ = # XXX # Save original values orig_values = dict(vars(OOBTree)) # Swap in Python implementation OOBTree.OOBTree = OOBTree.OOBTreePy ... # Unpickle and do stuff ... # Restore original implementation for k, v in orig_values.values(): if getattr(OOBTree, k) is not V: setattr(OOBTree, k, v) I haven't tried anything exactly like this, but it seems perfectly possible to me, despite being a hack. I know that the pickles are compatible and can work with each implementation because there are tests for that. Jason -- You received this message because you are subscribed to the Google Groups "zodb" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.