[Checkins] [zopefoundation/ZODB] f01451: Make TransactionMetaData in charge of (de)serializ...

GitHub noreply at github.com
Mon Sep 3 21:03:40 CEST 2018


  Branch: refs/heads/extension_bytes
  Home:   https://github.com/zopefoundation/ZODB
  Commit: f01451bdcb63f925eca7e788cc3b98f12596b90c
      https://github.com/zopefoundation/ZODB/commit/f01451bdcb63f925eca7e788cc3b98f12596b90c
  Author: Julien Muchembled <jm at nexedi.com>
  Date:   2018-09-03 (Mon, 03 Sep 2018)

  Changed paths:
    M src/ZODB/BaseStorage.py
    M src/ZODB/Connection.py
    M src/ZODB/FileStorage/FileStorage.py
    M src/ZODB/fsrecover.py
    M src/ZODB/interfaces.py
    M src/ZODB/tests/IteratorStorage.py
    M src/ZODB/tests/StorageTestBase.py
    M src/ZODB/tests/testFileStorage.py
    M src/ZODB/tests/test_TransactionMetaData.py

  Log Message:
  -----------
  Make TransactionMetaData in charge of (de)serializing extension data

IStorage implementations used to do this task themselves which leads to code
duplication and sometimes bugs (one was fixed recently in NEO). Like for object
serialization, this should be done by the upper layer (Connection).

This commit also provides a way to get raw extensions data while iterating
over transactions (this is actually the original purpose[2]). So far, extension
data could only be retrieved unpickled, which caused several problems:

- tools like `zodb dump` [1] cannot dump data exactly as stored on a
  storage. This makes database potentially not bit-to-bit identical to
  its original after restoring from such dump.

- `zodb dump` output could be changing from run to run on the same
  database. This comes from the fact that e.g. python dictionaries are
  unordered and so when pickling a dict back to bytes the result could
  be not the same as original.

  ( this problem can be worked-around partly to work reliably for e.g.
    dict with str keys - by always emitting items in key sorted order,
    but it is hard to make it work reliably for arbitrary types )

Both issues make it hard to verify integrity of database at the lowest
possible level after restoration, and make it hard to verify bit-to-bit
compatibility with non-python ZODB implementations.

For this, TransactionMetaData gets a new 'extension_bytes' attribute and
and common usage becomes:

* Application committing a transaction:

  - 'extension' is set with a dictionary
  - the storage gets the bytes via 'extension_bytes'

* Iteration:

  - the storage passes bytes as 'extension' parameter of TransactionMetaData
  - the application can get extension data either as bytes ('extension_bytes')
    or deserialized ('extension'): in the former case, no deserialization
    happens and the returned value is exactly what was passed by the storage

Conversion between 'extension' and 'extension_bytes' is automatic and lazy,
so that these attributes remain writable.

[1] https://lab.nexedi.com/nexedi/zodbtools
[2] https://github.com/zopefoundation/ZODB/pull/183

Co-Authored-By: Kirill Smelkov <kirr at nexedi.com>



      **NOTE:** This service has been marked for deprecation: https://developer.github.com/changes/2018-04-25-github-services-deprecation/

      Functionality will be removed from GitHub.com on January 31st, 2019.


More information about the checkins mailing list