Skip to content
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(replication): do not log to journal on callback fail #4392

Merged
merged 1 commit into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix replication: do not log to journal on callback fail
Signed-off-by: adi_holden <adi@dragonflydb.io>
  • Loading branch information
adiholden committed Jan 1, 2025
commit 786dabd749e245a75e64a349de7a15aa28cba663
10 changes: 7 additions & 3 deletions src/server/transaction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ void Transaction::RunCallback(EngineShard* shard) {

// Log to journal only once the command finished running
if ((coordinator_state_ & COORD_CONCLUDING) || (multi_ && multi_->concluding)) {
LogAutoJournalOnShard(shard);
LogAutoJournalOnShard(shard, result);
MaybeInvokeTrackingCb();
}
}
Expand Down Expand Up @@ -1346,7 +1346,7 @@ OpStatus Transaction::RunSquashedMultiCb(RunnableType cb) {
auto result = cb(this, shard);
db_slice.OnCbFinish();

LogAutoJournalOnShard(shard);
LogAutoJournalOnShard(shard, result);
MaybeInvokeTrackingCb();

DCHECK_EQ(result.flags, 0); // if it's sophisticated, we shouldn't squash it
Expand Down Expand Up @@ -1438,7 +1438,7 @@ optional<string_view> Transaction::GetWakeKey(ShardId sid) const {
return ArgS(full_args_, sd.wake_key_pos);
}

void Transaction::LogAutoJournalOnShard(EngineShard* shard) {
void Transaction::LogAutoJournalOnShard(EngineShard* shard, RunnableResult result) {
// TODO: For now, we ignore non shard coordination.
if (shard == nullptr)
return;
Expand All @@ -1455,6 +1455,10 @@ void Transaction::LogAutoJournalOnShard(EngineShard* shard) {
if (journal == nullptr)
return;

if (result.status != OpStatus::OK) {
return; // Do not log to journal if command execution failed.
}

// If autojournaling was disabled and not re-enabled the callback is writing to journal.
if ((cid_->opt_mask() & CO::NO_AUTOJOURNAL) && !re_enabled_auto_journal_) {
return;
Expand Down
2 changes: 1 addition & 1 deletion src/server/transaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ class Transaction {

// Log command in shard's journal, if this is a write command with auto-journaling enabled.
// Should be called immediately after the last hop.
void LogAutoJournalOnShard(EngineShard* shard);
void LogAutoJournalOnShard(EngineShard* shard, RunnableResult shard_result);

// Whether the callback can be run directly on this thread without dispatching on the shard queue
bool CanRunInlined() const;
Expand Down
Loading