ydb-platform / nbs

Network Block Store
Apache License 2.0
50 stars 14 forks source link

issue-1146: preliminary changes: extract some localdb methods to the interface, add stub for index cache #1478

Open debnatkh opened 1 week ago

debnatkh commented 1 week ago

Currently RO transactions access TIndexTabletDatabase via TIndexTabletState methods like

TIndexTabletState::ReadNode(
    TIndexTabletDatabase& db,
    ...

which in turn calls do stuff like db.ReadNode(nodeId, commitId, node).

We want to cache some index data from the Index tables.

For this in-memory cache to implement the same set of methods, TIndexTabletDatabase is replaced with an interface IIndexTabletDatabase, which is implemented by TInMemoryIndexState (which, for now, is a stub). Its superset, IIndexTabletDatabase is also implemented by TIndexTabletDatabase.

To ensure in-memory cache validity, every RW transaction that modifies inode index records all modifying operations, and on completion of those transactions, these operations will be applied to the in-memory state. This is done using TIndexTabletDatabaseProxy : public TIndexTabletDatabase (to be implemented), which forwards all requests to the underlying TIndexTabletDatabase.

classDiagram
TNiceDb <|-- TIndexTabletDatabase
TIndexTabletDatabase : actual implementation that accesses LocalDB
    IIndexTabletDatabase <|-- TInMemoryIndexState
class TInMemoryIndexState {
- ApplyDelta(changes to inmemory state)
}

    IIndexTabletDatabase <|-- TIndexTabletDatabase
    class IIndexTabletDatabase {
      + bool ReadNode()
      + bool ReadNodeVer()
      + bool ReadNodeAttr_s()
      + bool ReadNodeAttrVer_s()
      + bool ReadNodeRef_s()
      + bool PrechargeNodeRefs()
      + bool ReadNodeRefVer_s()
    }

TIndexTabletDatabase<|-- TIndexTabletDatabaseProxy : forwards all DB accesses
TIndexTabletDatabaseProxy: records all modifications of the tables
TInMemoryIndexState<|.. TIndexTabletDatabaseProxy : can apply recorded changes\nto in-memory state
github-actions[bot] commented 1 week ago

[!NOTE] This is an automated comment that will be appended during run.

:green_circle: linux-x86_64-relwithdebinfo: all tests PASSED for commit 3243440ab51c84dc2e93638abfdb5b5cff6b996c. TESTS PASSED ERRORS FAILED SKIPPED MUTED?
1563 1563 0 0 0 0
github-actions[bot] commented 1 week ago

[!NOTE] This is an automated comment that will be appended during run.

:red_circle: linux-x86_64-relwithdebinfo: some tests FAILED for commit 30aef9fc67b82d3a5966434ee45d8f8adc2ca7a5. TESTS PASSED ERRORS FAILED SKIPPED MUTED?
1564 1562 0 2 0 0
github-actions[bot] commented 2 days ago

[!NOTE] This is an automated comment that will be appended during run.

:green_circle: linux-x86_64-relwithdebinfo: all tests PASSED for commit 9225ee4edfd749a2006e1b16ffbaeb045733d637. TESTS PASSED ERRORS FAILED SKIPPED MUTED?
1563 1563 0 0 0 0
github-actions[bot] commented 2 days ago

[!NOTE] This is an automated comment that will be appended during run.

:green_circle: linux-x86_64-relwithdebinfo: all tests PASSED for commit 584851d5a26b48f8234cda69e87829985f9d10bb. TESTS PASSED ERRORS FAILED SKIPPED MUTED?
1634 1634 0 0 0 0