• Kirill Smelkov's avatar
    go/zodb/fs1: Teach it to support notifications on database change · db852511
    Kirill Smelkov authored
    Following-up on 4d2c8b1d (go/zodb: Require drivers to provide
    notifications for database change events) let's teach FileStorage to
    support watching for database changes:
    
    - add watcher who observes changes to data file via fsnotify.
    
    - when we see that the file was updated - there is a tricky case to distinguish
      in-progress writes from just some garbage added at tail. See comments in
      _watcher for details.
    
    - if the watcher sees there is indeed new transactions, the watcher
      updates index & txnh{Min,Max} and sends corresponding event to watchq.
    
    - since index / txnh{Min,Max} can now be changed (by watcher) -> they
      are now protected by mu.
    
    - consequently operations like LastTid, LastOid, Load, ... are all taught to
      observe index / txnh{Min,Max} state in read-snapshot way.
    
    - add down & friends to indicate that the storage is no longer
      operational, if watcher sees there is a problem with data file.
    
    - Open is reworked to start from loading/rebuilding index first, and then tail
      to watcher to detect whether what's after found topPos is garbage or another
      in-progress transaction. Consequently it is now possible to correctly open
      filestorage that is being currently written to and has in-progress transaction
      at tail.
    
    The patch is a bit big, but the changes here are all tightly
    interrelated.
    db852511
url.go 1.34 KB