• Kirill Smelkov's avatar
    go/zodb: LastTid -> Sync + Head · 151d8b79
    Kirill Smelkov authored
    Today LastTid is ambiguous: does it return locally cached last transaction ID,
    or it performs round-trip to server to get more uptodate view of what has been
    last committed? As the result of this ambiguity some drivers (e.g. FileStorage,
    ZEO) return cached view, while other drivers (upcoming NEO, living on t branch)
    was doing the full round-trip.
    
    There are also situations where whether or not LastTid performs syncing to
    server affects semantics: for example if there are two ERP5 nodes and one
    node commits something into ZODB and conveys the fact that something has been
    committed via another channel, the second ERP5 node should have a reliable way
    to observe committed data. But currently there is no such way: on next DB.Open,
    even with at=0 meaning "use latest transaction" and with opt.NoSync=false,
    DB.Open uses storage.LastTid() as a way to sync and oops - for some drivers it
    won't result in real synchronization and thus opened connection could
    potentially have older view with not yet latest data.
    
    To fix this ambiguity require drivers to provide Sync functionality only. That
    should return ID of last transaction committed to storage data as observed from
    some time _afterwards_ Sync call was made. In other words for particular
    client-server case, Sync cannot return cached view of storage and has to
    perform round-trip to the server.
    
    At IStorage level we provide two entry points: Sync, to perform syncing, and
    Head that returns database head (last transaction ID) as viewed by local cache
    without any synchronization.
    
    Please see changes to IStorageDriver and IStorage interfaces for details.
    
    The rest of the changes are:
    
    - teach zodb.storage (the IStorage implementer) to actually implement Sync/Head.
    - adapt zodb.DB to perform Sync for !opt.NoSync case.
    - teach FileStorage to do proper syncing instead of returning local cache.
    - teach ZEO to perform "lastTransaction" RPC call for syncing instead of
      returning local cache.
    - adapt the rest of the tree to interfaces change.
    151d8b79
filestorage_test.go 13.9 KB