[ZODB-Dev] Undo alternatives

Jim Fulton jim at zope.com
Thu Dec 24 09:37:22 EST 2009


As I mentioned in another message, undo is staying, but, as many also
mentioned in that thread, undo often doesn't work due to conflicts. I
thought I'd mention some alternatives:

- Time travel

  ZODB has a number of facilities for time travel:

  - Object history

    There's an API for looking at changes over time. For simple
    objects, recovering from a misshap can often be as simple as
    copying state from an old revision. Zope 2 has (or had) a built
    in view for this.

  - Time traveling database connections

    In ZODB 3.9, the database open method grew a optional 'at' and
    'before' keyword arguments to open a connection with a view of the
    database as of a particular point in time.

  - zc.beforestorage

    This is a storage wrapper that provides a read-only unchanging
    view of a database as of a particular time.  (We use it with
    DemoStorage for staging new releases with customer data without
    having to copy customer databases.)

- Truncation

  Although there isn't an API, truncating a file-storage database as
  of a particular time is pretty easy:

  >>> import ZODB.FileStorage, ZODB.TimeStamp
  >>> tid = repr(ZODB.TimeStamp.TimeStamp(y, m, d, h, min, s))
  >>> it = ZODB.FileStorage.FileIterator(path, tid)
  >>> f = open(path, 'r+b')
  >>> f.seek(it._pos)
  >>> f.truncate()

  This is certainly easier and more precise than restoring from a
  backup.

  Maybe FileStorage should get an API for this.  I'm working on a
  storage implementation based on Berkeley DB and it has a truncate
  function, mainly because truncation isn't so easy for this
  implementation and I need it for some benchmarking I'm doing.

Jim

--
Jim Fulton


More information about the ZODB-Dev mailing list