feat(server): write journal record with optional await based on flag… (#791)

* feat(server): write journal recorod with optional await based on flag issue #788

Signed-off-by: adi_holden <adi@dragonflydb.io>
This commit is contained in:
adiholden 2023-02-15 09:34:24 +02:00 committed by GitHub
parent 8068e1a2ae
commit 50f50c8380
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 65 additions and 31 deletions

View file

@ -8,11 +8,16 @@ 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();
});
journal_cb_id_ =
journal_->RegisterOnChange([this](const journal::Entry& entry, bool allow_await) {
if (entry.opcode == journal::Op::NOOP) {
// No recode to write, just await if data was written so consumer will read the data.
return AwaitIfWritten();
}
writer_.Write(entry);
record_cnt_.fetch_add(1, std::memory_order_relaxed);
NotifyWritten(allow_await);
});
}
uint64_t JournalStreamer::GetRecordCount() const {