-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix child batches and introduce callback for processing loaded trie nodes #1499
Conversation
…gome into feature/trie-proof-callback
for (auto &[child, kv] : child_batches_) { | ||
OUTCOME_TRY(root, kv->commit(version)); | ||
OUTCOME_TRY(current_batch_->put(child, common::BufferView{root})); | ||
outcome::result<std::reference_wrapper<const storage::trie::TrieBatch>> | ||
TrieStorageProviderImpl::getChildBatchAt(const common::Buffer &root_path) { | ||
OUTCOME_TRY(batch_ptr, getOrCreateChildBatchAt(root_path)); | ||
return *batch_ptr; | ||
} | ||
|
||
outcome::result<std::reference_wrapper<storage::trie::TrieBatch>> | ||
TrieStorageProviderImpl::getMutableChildBatchAt( | ||
const common::Buffer &root_path) { | ||
// if the batch for this child trie can be found in the current transaction, | ||
// just return it | ||
if (!transaction_stack_.empty()) { | ||
if (auto it = transaction_stack_.back().child_batches.find(root_path); | ||
it != transaction_stack_.back().child_batches.end()) { | ||
return *it->second; | ||
} | ||
// if there are no open transactions, just a base batch is sufficient | ||
} else { | ||
OUTCOME_TRY(batch_ptr, getOrCreateChildBatchAt(root_path)); | ||
return *batch_ptr; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Revert, we need to write children roots back to top trie
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what you mean, the child roots are written to the main trie in the commit() method of a batch.
outcome::result<std::reference_wrapper<storage::trie::TrieBatch>> | ||
TrieStorageProviderImpl::getMutableChildBatchAt( | ||
const common::Buffer &root_path) { | ||
// if the batch for this child trie can be found in the current transaction, | ||
// just return it | ||
if (!transaction_stack_.empty()) { | ||
if (auto it = transaction_stack_.back().child_batches.find(root_path); | ||
it != transaction_stack_.back().child_batches.end()) { | ||
return *it->second; | ||
} | ||
// if there are no open transactions, just a base batch is sufficient | ||
} else { | ||
OUTCOME_TRY(batch_ptr, getOrCreateChildBatchAt(root_path)); | ||
return *batch_ptr; | ||
} | ||
if (persistent_batch_) { | ||
return persistent_batch_->commit(version); | ||
// otherwise we need to create a new overlay batch in the current | ||
// transaction | ||
OUTCOME_TRY(batch_ptr, getOrCreateChildBatchAt(root_path)); | ||
|
||
SL_DEBUG(logger_, | ||
"Creating new overlay batch for child storage {}", | ||
root_path.toHex()); | ||
auto child_batch = | ||
std::make_shared<storage::trie::TopperTrieBatchImpl>(batch_ptr); | ||
transaction_stack_.back().child_batches.emplace(root_path, child_batch); | ||
return *child_batch; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like (unnecessary) duplicate of (complex) getOrCreateChildBatchAt
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not a duplicate, it uses getOrCreateChildBatchAt to obtain the existing batch which is possibly on another transaction level, and then if the batch is not on the current transaction level it creates a batch on top of the obtained batch on the current transaction level.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's necessary, then getConstChildBatchAt
must return readonly batch, which errors on write attempt
Referenced issues
Description of the Change
Benefits
Possible Drawbacks