feat(server): Use new journal format (#563)

This commit is contained in:
Vladislav 2022-12-20 16:38:19 +03:00 committed by GitHub
parent cdc31fc98c
commit 2386b02234
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
30 changed files with 302 additions and 179 deletions

View file

@ -80,6 +80,7 @@ Transaction::~Transaction() {
OpStatus Transaction::InitByArgs(DbIndex index, CmdArgList args) {
db_index_ = index;
cmd_with_full_args_ = args;
if (IsGlobal()) {
unique_shard_cnt_ = shard_set->size();
@ -372,6 +373,9 @@ bool Transaction::RunInShard(EngineShard* shard) {
/*************************************************************************/
if (!was_suspended && should_release) // Check last hop & non suspended.
LogJournalOnShard(shard);
// at least the coordinator thread owns the reference.
DCHECK_GE(use_count(), 1u);
@ -771,6 +775,8 @@ void Transaction::RunQuickie(EngineShard* shard) {
LOG(FATAL) << "Unexpected exception " << e.what();
}
LogJournalOnShard(shard);
sd.local_mask &= ~ARMED;
cb_ = nullptr; // We can do it because only a single shard runs the callback.
}
@ -1194,6 +1200,30 @@ bool Transaction::NotifySuspended(TxId committed_txid, ShardId sid) {
return false;
}
void Transaction::LogJournalOnShard(EngineShard* shard) {
// TODO: For now, we ignore non shard coordination.
if (shard == nullptr)
return;
if ((cid_->opt_mask() & CO::WRITE) == 0)
return;
auto journal = shard->journal();
if (journal == nullptr)
return;
// TODO: Handle complex commands like LMPOP correctly once they are implemented.
journal::Entry::Payload entry_payload;
if (unique_shard_cnt_ == 1 || args_.empty()) {
CHECK(!cmd_with_full_args_.empty());
entry_payload = cmd_with_full_args_;
} else {
entry_payload =
make_pair(facade::ToSV(cmd_with_full_args_.front()), ShardArgsInShard(shard->shard_id()));
}
journal->RecordEntry(journal::Entry{txid_, db_index_, entry_payload});
}
void Transaction::BreakOnShutdown() {
if (coordinator_state_ & COORD_BLOCKED) {
coordinator_state_ |= COORD_CANCELLED;