Skip to content

Commit

Permalink
Catch on snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
tvorogme committed Feb 14, 2024
1 parent a07635d commit c4130a9
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 19 deletions.
8 changes: 6 additions & 2 deletions tddb/td/db/RocksDb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ Result<RocksDb> RocksDb::open(std::string path, bool read_only) {
}

std::unique_ptr<KeyValueReader> RocksDb::snapshot() {
if (!last_catch_timeout_ || last_catch_timeout_.is_in_past()) {
db_->TryCatchUpWithPrimary();
last_catch_timeout_ = td::Timestamp::at(0.2);
}

auto res = std::make_unique<RocksDb>(clone());
res->begin_snapshot().ensure();
return std::move(res);
Expand All @@ -119,7 +124,7 @@ Result<RocksDb::GetStatus> RocksDb::get(Slice key, std::string &value) {
if (read_only_) {
if (!last_catch_timeout_ || last_catch_timeout_.is_in_past()) {
db_->TryCatchUpWithPrimary();
last_catch_timeout_ = td::Timestamp::at(1.0);
last_catch_timeout_ = td::Timestamp::at(0.2);
}
}
rocksdb::Status status;
Expand Down Expand Up @@ -184,7 +189,6 @@ Result<size_t> RocksDb::count(Slice prefix) {
return res;
}


Status RocksDb::begin_write_batch() {
CHECK(!transaction_);
write_batch_ = std::make_unique<rocksdb::WriteBatch>();
Expand Down
6 changes: 5 additions & 1 deletion validator/db/celldb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ void CellDbIn::start_up() {
boc_->set_celldb_compress_depth(opts_->get_celldb_compress_depth());
boc_->set_loader(std::make_unique<vm::CellLoader>(cell_db_->snapshot(), on_load_callback_)).ensure();
td::actor::send_closure(parent_, &CellDb::update_snapshot, cell_db_->snapshot());

last_catch_timeout_ = td::Timestamp::at(0.2);
alarm_timestamp() = td::Timestamp::in(10.0);

auto empty = get_empty_key_hash();
Expand All @@ -105,6 +105,10 @@ void CellDbIn::start_up() {
}

void CellDbIn::load_cell(RootHash hash, td::Promise<td::Ref<vm::DataCell>> promise) {
if (read_only_ && last_catch_timeout_.is_in_past()) {
td::actor::send_closure(parent_, &CellDb::update_snapshot, cell_db_->snapshot());
last_catch_timeout_ = td::Timestamp::at(0.2);
}
boc_->load_cell_async(hash.as_slice(), async_executor, std::move(promise));
}

Expand Down
1 change: 1 addition & 0 deletions validator/db/celldb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class CellDbIn : public CellDbBase {

td::actor::ActorId<RootDb> root_db_;
td::actor::ActorId<CellDb> parent_;
td::Timestamp last_catch_timeout_;

std::string path_;
td::Ref<ValidatorManagerOptions> opts_;
Expand Down
25 changes: 9 additions & 16 deletions validator/manager-disk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -771,22 +771,15 @@ void ValidatorManagerImpl::get_shard_state_from_db_short(BlockIdExt block_id,
});
get_block_handle(block_id, false, std::move(P));
} else {
auto P = td::PromiseCreator::lambda([SelfId = actor_id(this), db = db_.get(), promise = std::move(promise),
block_id](td::Result<BlockHandle> R) mutable {
if (R.is_error()) {
auto x = R.move_as_error();
if (x.code() == 57) { // cell not found
LOG(ERROR) << "Cell not found in readonly mode, try one more time";
td::actor::send_closure(SelfId, &ValidatorManagerImpl::get_shard_state_from_db_short, block_id,
std::move(promise));
} else {
promise.set_error(std::move(x));
}
} else {
auto handle = R.move_as_ok();
td::actor::send_closure(db, &Db::get_block_state, std::move(handle), std::move(promise));
}
});
auto P = td::PromiseCreator::lambda(
[SelfId = actor_id(this), db = db_.get(), promise = std::move(promise)](td::Result<BlockHandle> R) mutable {
if (R.is_error()) {
promise.set_error(R.move_as_error());
} else {
auto handle = R.move_as_ok();
td::actor::send_closure(db, &Db::get_block_state, std::move(handle), std::move(promise));
}
});
get_block_handle(block_id, false, std::move(P));
}
}
Expand Down

0 comments on commit c4130a9

Please sign in to comment.