Skip to content
Snippets Groups Projects
  • Todd Gamblin's avatar
    b3a5f2e3
    lock transactions: ensure that nested write transactions write · b3a5f2e3
    Todd Gamblin authored
    If a write transaction was nested inside a read transaction, it would not
    write properly on release, e.g., in a sequence like this, inside our
    `LockTransaction` class:
    
    ```
    1  with spack.store.db.read_transaction():
    2    with spack.store.db.write_transaction():
    3      ...
    4  with spack.store.db.read_transaction():
       ...
    ```
    
    The WriteTransaction on line 2 had no way of knowing that its
    `__exit__()` call was the last *write* in the nesting, and it would skip
    calling its write function.
    
    The `__exit__()` call of the `ReadTransaction` on line 1 wouldn't know
    how to write, and the file would never be written.
    
    The DB would be correct in memory, but the `ReadTransaction` on line 4
    would re-read the whole DB assuming that other processes may have
    modified it.  Since the DB was never written, we got stale data.
    
    - [x] Make `Lock.release_write()` return `True` whenever we release the
          *last write* in a nest.
    lock transactions: ensure that nested write transactions write
    Todd Gamblin authored
    If a write transaction was nested inside a read transaction, it would not
    write properly on release, e.g., in a sequence like this, inside our
    `LockTransaction` class:
    
    ```
    1  with spack.store.db.read_transaction():
    2    with spack.store.db.write_transaction():
    3      ...
    4  with spack.store.db.read_transaction():
       ...
    ```
    
    The WriteTransaction on line 2 had no way of knowing that its
    `__exit__()` call was the last *write* in the nesting, and it would skip
    calling its write function.
    
    The `__exit__()` call of the `ReadTransaction` on line 1 wouldn't know
    how to write, and the file would never be written.
    
    The DB would be correct in memory, but the `ReadTransaction` on line 4
    would re-read the whole DB assuming that other processes may have
    modified it.  Since the DB was never written, we got stale data.
    
    - [x] Make `Lock.release_write()` return `True` whenever we release the
          *last write* in a nest.