feat(server): add dfly replica offset command (#780)

* feat(server): add dfly replica offset command

Signed-off-by: adi_holden <adi@dragonflydb.io>
This commit is contained in:
adiholden 2023-02-13 11:11:33 +02:00 committed by GitHub
parent e7a5d583d0
commit 9c9ae84493
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 136 additions and 77 deletions

View file

@ -0,0 +1,36 @@
// Copyright 2022, DragonflyDB authors. All rights reserved.
// See LICENSE for licensing terms.
//
#include "server/journal/streamer.h"
namespace dfly {
void JournalStreamer::Start(io::Sink* dest) {
write_fb_ = util::fibers_ext::Fiber(&JournalStreamer::WriterFb, this, dest);
journal_cb_id_ = journal_->RegisterOnChange([this](const journal::Entry& entry) {
writer_.Write(entry);
record_cnt_.fetch_add(1, std::memory_order_relaxed);
NotifyWritten();
});
}
uint64_t JournalStreamer::GetRecordCount() const {
return record_cnt_.load(std::memory_order_relaxed);
}
void JournalStreamer::Cancel() {
journal_->UnregisterOnChange(journal_cb_id_);
Finalize();
if (write_fb_.IsJoinable())
write_fb_.Join();
}
void JournalStreamer::WriterFb(io::Sink* dest) {
if (auto ec = ConsumeIntoSink(dest); ec) {
cntx_->ReportError(ec);
}
}
} // namespace dfly