You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
statedb: Restore ability to use Changes with WriteTxn
The index refactoring in cd27022 removed
the ability to use ChangeIterator.Next with a WriteTxn targeting the table
being observed. This was done to avoid having to hold onto the old instance
of the tableEntry, but it broke a useful pattern for Changes(): the ability
for a component A to write into a table and component B to be able to observe
and "augment" the objects created by A.
Restore this ability to by keeping a pointer to the old root in the write
transaction.
Before:
BenchmarkDB_WriteTxn_CommitOnly_100Tables-8 1428603 838.6 ns/op 1112 B/op 5 allocs/op
BenchmarkDB_WriteTxn_CommitOnly_1Table-8 2391542 503.3 ns/op 224 B/op 5 allocs/op
BenchmarkDB_NewWriteTxn-8 2607277 458.1 ns/op 200 B/op 4 allocs/op
BenchmarkDB_WriteTxnCommit100-8 1455978 823.8 ns/op 1096 B/op 5 allocs/op
After:
BenchmarkDB_WriteTxn_CommitOnly_100Tables-8 1239177 962.4 ns/op 1112 B/op 5 allocs/op
BenchmarkDB_WriteTxn_CommitOnly_1Table-8 2332510 515.2 ns/op 224 B/op 5 allocs/op
BenchmarkDB_NewWriteTxn-8 2566347 468.2 ns/op 200 B/op 4 allocs/op
BenchmarkDB_WriteTxnCommit100-8 1452818 892.0 ns/op 1096 B/op 5 allocs/op
No practical difference since we keep a pool for writeTxnHandle and thus don't really allocate more memory even though
the writeTxnHandle is larger now. The impact this may have is to workloads that have a huge table and churn through
all objects and now WriteTxn holds onto both the old root and the new root being prepared and thus do not allow GC
to collect old objects. This however seems unlikely to be an issue since we do hold onto the old root via [DB]
and only way for constructing lots of potentially garbage objects is to have two tables churning and have the
two WriteTxn's hold onto "garbage" of the other table that is no longer reachable via [DB.ReadTxn].
Signed-off-by: Jussi Maki <jussi.maki@isovalent.com>
0 commit comments