bug(server): replicate scripts in stable state (#1114)

* bug(server): replicate scripts in stable state

---------

Signed-off-by: adi_holden <adi@dragonflydb.io>
This commit is contained in:
adiholden 2023-04-23 23:46:51 +03:00 committed by GitHub
parent 2d501111ea
commit 7f56a435c4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 81 additions and 8 deletions

View file

@ -83,6 +83,14 @@ void Transaction::InitGlobal() {
sd.local_mask = ACTIVE;
}
void Transaction::InitNoKey() {
// No key command will use the first shard.
unique_shard_cnt_ = 1;
unique_shard_id_ = 0;
shard_data_.resize(1);
shard_data_.front().local_mask |= ACTIVE;
}
void Transaction::BuildShardIndex(KeyIndex key_index, bool rev_mapping,
std::vector<PerShardCache>* out) {
auto args = full_args_;
@ -310,6 +318,11 @@ OpStatus Transaction::InitByArgs(DbIndex index, CmdArgList args) {
return OpStatus::OK;
}
if ((cid_->opt_mask() & CO::NO_KEY_JOURNAL) > 0) {
InitNoKey();
return OpStatus::OK;
}
DCHECK_EQ(unique_shard_cnt_, 0u);
DCHECK(args_.empty());
@ -916,6 +929,7 @@ KeyLockArgs Transaction::GetLockArgs(ShardId sid) const {
res.db_index = db_index_;
res.key_step = cid_->key_arg_step();
res.args = GetShardArgs(sid);
DCHECK(!res.args.empty() || (cid_->opt_mask() & CO::NO_KEY_JOURNAL));
return res;
}
@ -947,6 +961,7 @@ bool Transaction::ScheduleUniqueShard(EngineShard* shard) {
sd.pq_pos = shard->txq()->Insert(this);
DCHECK_EQ(0, sd.local_mask & KEYLOCK_ACQUIRED);
shard->db_slice().Acquire(mode, lock_args);
sd.local_mask |= KEYLOCK_ACQUIRED;
@ -1057,8 +1072,6 @@ bool Transaction::CancelShardCb(EngineShard* shard) {
// runs in engine-shard thread.
ArgSlice Transaction::GetShardArgs(ShardId sid) const {
DCHECK(!args_.empty());
// We can read unique_shard_cnt_ only because ShardArgsInShard is called after IsArmedInShard
// barrier.
if (unique_shard_cnt_ == 1) {
@ -1289,10 +1302,18 @@ void Transaction::LogAutoJournalOnShard(EngineShard* shard) {
if (multi_ && multi_->role == SQUASHER)
return;
// Ignore non-write commands or ones with disabled autojournal.
if ((cid_->opt_mask() & CO::WRITE) == 0 || ((cid_->opt_mask() & CO::NO_AUTOJOURNAL) > 0 &&
!renabled_auto_journal_.load(memory_order_relaxed)))
bool journal_by_cmd_mask = true;
if ((cid_->opt_mask() & CO::NO_KEY_JOURNAL) > 0) {
journal_by_cmd_mask = true; // Enforce journaling for commands that dont change the db.
} else if ((cid_->opt_mask() & CO::WRITE) == 0) {
journal_by_cmd_mask = false; // Non-write command are not journaled.
} else if ((cid_->opt_mask() & CO::NO_AUTOJOURNAL) > 0 &&
!renabled_auto_journal_.load(memory_order_relaxed)) {
journal_by_cmd_mask = false; // Command disabled auto journal.
}
if (!journal_by_cmd_mask) {
return;
}
auto journal = shard->journal();
if (journal == nullptr)