statedb: Restore ability to use Changes with WriteTxn#142
Merged
Conversation
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>
|
dylandreimerink
approved these changes
Feb 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
After:
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].