Skip to content

Commit

Permalink
chore: journal cleanup (#2749)
Browse files Browse the repository at this point in the history
Signed-off-by: Roman Gershman <[email protected]>
  • Loading branch information
romange authored Mar 19, 2024
1 parent 1ec603e commit 31fabf2
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 82 deletions.
51 changes: 4 additions & 47 deletions src/server/journal/journal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,30 +38,12 @@ void Journal::StartInThread() {
}
}

#if 0
error_code Journal::OpenInThread(bool persistent, string_view dir) {


error_code ec;

if (persistent) {
ec = journal_slice.Open(dir);
if (ec) {
return ec;
}
}

return ec;
}
#endif

error_code Journal::Close() {
CHECK(lameduck_.load(memory_order_relaxed));

VLOG(1) << "Journal::Close";

fb2::Mutex ec_mu;
error_code res;
if (!journal_slice.IsOpen()) {
return {};
}

lock_guard lk(state_mu_);
auto close_cb = [&](auto*) {
Expand All @@ -70,18 +52,11 @@ error_code Journal::Close() {
if (shard) {
shard->set_journal(nullptr);
}

/*auto ec = journal_slice.Close();
if (ec) {
lock_guard lk2(ec_mu);
res = ec;
}*/
};

shard_set->pool()->AwaitFiberOnAll(close_cb);

return res;
return {};
}

uint32_t Journal::RegisterOnChange(ChangeCallback cb) {
Expand All @@ -108,28 +83,10 @@ LSN Journal::GetLsn() const {
return journal_slice.cur_lsn();
}

bool Journal::EnterLameDuck() {
if (!journal_slice.IsOpen()) {
return false;
}

bool val = false;
bool res = lameduck_.compare_exchange_strong(val, true, memory_order_acq_rel);
return res;
}

void Journal::RecordEntry(TxId txid, Op opcode, DbIndex dbid, unsigned shard_cnt,
std::optional<SlotId> slot, Entry::Payload payload, bool await) {
journal_slice.AddLogRecord(Entry{txid, opcode, dbid, shard_cnt, slot, std::move(payload)}, await);
}

/*
void Journal::OpArgs(TxId txid, Op opcode, Span keys) {
DCHECK(journal_slice.IsOpen());
journal_slice.AddLogRecord(txid, opcode);
}
*/

} // namespace journal
} // namespace dfly
25 changes: 0 additions & 25 deletions src/server/journal/journal.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,10 @@ class Journal {

Journal();

// Returns true if journal has been active and changed its state to lameduck mode
// and false otherwise.
bool EnterLameDuck(); // still logs ongoing transactions but refuses to start new ones.

void StartInThread();

// Requires: journal is in lameduck mode.
std::error_code Close();

#if 0
// Opens journal inside a Dragonfly thread. Must be called in each thread.
std::error_code OpenInThread(bool persistent, std::string_view dir);
#endif

//******* The following functions must be called in the context of the owning shard *********//

uint32_t RegisterOnChange(ChangeCallback cb);
Expand All @@ -42,28 +32,13 @@ class Journal {
bool IsLSNInBuffer(LSN lsn) const;
std::string_view GetEntry(LSN lsn) const;

/*
void AddCmd(TxId txid, Op opcode, Span args) {
OpArgs(txid, opcode, args);
}
void Lock(TxId txid, Span keys) {
OpArgs(txid, Op::LOCK, keys);
}
void Unlock(TxId txid, Span keys) {
OpArgs(txid, Op::UNLOCK, keys);
}
*/
LSN GetLsn() const;

void RecordEntry(TxId txid, Op opcode, DbIndex dbid, unsigned shard_cnt,
std::optional<SlotId> slot, Entry::Payload payload, bool await);

private:
mutable util::fb2::Mutex state_mu_;

std::atomic_bool lameduck_{false};
};

} // namespace journal
Expand Down
6 changes: 0 additions & 6 deletions src/server/journal/journal_slice.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@ class JournalSlice {

void Init(unsigned index);

#if 0
std::error_code Open(std::string_view dir);

std::error_code Close();
#endif

// This is always the LSN of the *next* journal entry.
LSN cur_lsn() const {
return lsn_;
Expand Down
6 changes: 2 additions & 4 deletions src/server/server_family.cc
Original file line number Diff line number Diff line change
Expand Up @@ -792,10 +792,8 @@ void ServerFamily::Shutdown() {
stats_caching_task_ = 0;
}

if (journal_->EnterLameDuck()) {
auto ec = journal_->Close();
LOG_IF(ERROR, ec) << "Error closing journal " << ec;
}
auto ec = journal_->Close();
LOG_IF(ERROR, ec) << "Error closing journal " << ec;

unique_lock lk(replicaof_mu_);
if (replica_) {
Expand Down

0 comments on commit 31fabf2

Please sign in to comment.