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

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

Merged
merged 4 commits into from
Feb 15, 2023

Conversation

adiholden
Copy link
Collaborator

… issue #788

Signed-off-by: adi_holden adi@dragonflydb.io

  1. register to journal record function can get a boolean flag
  2. Add flag to journal record write call which indicates if we should allow switch to journal stream consumer
  3. In the flows of heartbeat and non auto journal, do not allow switch to journal stream consumer
  4. At the end of heartbeat allow switch to journal stream consumer

… issue #788

Signed-off-by: adi_holden <adi@dragonflydb.io>
Signed-off-by: adi_holden <adi@dragonflydb.io>
@@ -120,10 +120,6 @@ class Transaction {
// Cancel all blocking watches on shutdown. Set COORD_CANCELLED.
void BreakOnShutdown();

// Log a journal entry on shard with payload and shard count.
void LogJournalOnShard(EngineShard* shard, journal::Entry::Payload&& payload,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function was not implemented

@romange romange changed the title feat(server): write journal recorod with optional await based on flag… feat(server): write journal record with optional await based on flag… Feb 13, 2023
Copy link
Contributor

@dranikpg dranikpg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Lets store the field inside the entry, then we won't need all the other changes and ambiguous bool fields
  2. Please review the journal streamer, I assume the code does not quite do what we expect of it

waker_.await([this]() { return !IsStalled() || IsStopped(); });
waker_.await([this, allow_await]() { return !allow_await || !IsStalled() || IsStopped(); });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A wrapping if would more clearly show that we're not awaiting

Comment on lines 47 to 48
// Blocks the if the consumer if not keeping up.
void WakeIfWritten();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name is a bit misleading

@@ -209,7 +205,7 @@ class Transaction {
// multi_commands to true and call the FinishLogJournalOnShard function after logging the final
// entry.
void LogJournalOnShard(EngineShard* shard, journal::Entry::Payload&& payload, uint32_t shard_cnt,
bool multi_commands) const;
bool multi_commands, bool flag) const;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets not call this flag, lets either use explicitly bool wake or create an enum with flags

Comment on lines 67 to 68
using ChangeCallback =
std::variant<std::function<void(const Entry&)>, std::function<void(const Entry&, bool flag)>>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its used in one or two places, we can just make the others accept the flags

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we use flags, we can actually make them part of the entry instead of passing them around everywhere

Comment on lines 29 to 34
void BufferedStreamerBase::WakeIfWritten() {
if (IsStopped())
return;
if (buffered_) {
waker_.await([this]() { return !IsStalled() || IsStopped(); });
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We wake by using waker_.notify(), the only thing that this can do is blocking

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I will change the function name, we already notiflied the consumer, we just need to block now till consumer runs

Comment on lines 118 to 129
void JournalSlice::AddLogRecord(const Entry& entry) {
template <class... Ts> struct Overloaded : Ts... { using Ts::operator()...; };
template <class... Ts> Overloaded(Ts...) -> Overloaded<Ts...>;

void JournalSlice::AddLogRecord(const Entry& entry, bool flag_val) {
DCHECK(ring_buffer_);
iterating_cb_arr_ = true;
for (const auto& k_v : change_cb_arr_) {
k_v.second(entry);
std::visit(Overloaded{[entry](std::function<void(const Entry&)> cb) { cb(entry); },
[entry, flag_val](std::function<void(const Entry&, bool flag)> cb) {
cb(entry, flag_val);
}},
k_v.second);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And then we won't need this monster

Signed-off-by: adi_holden <adi@dragonflydb.io>
Signed-off-by: adi_holden <adi@dragonflydb.io>
@adiholden adiholden requested a review from dranikpg February 14, 2023 12:24
@adiholden
Copy link
Collaborator Author

2. Please review the journal streamer, I assume the code does not quite do what we expect of it

@dranikpg I dont understand this comment. What do we expect of the journal steamer that it does not do..

Comment on lines 13 to 15
if (entry.opcode == journal::Op::NOOP) {
return WakeIfWritten(); // No recode to write, just wake the consumer if needed.
// No recode to write, just await if data was written so consumer will read the data.
return AwaitIfWritten();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only nit is that NOOP now implicitly means 'flush', but we can think about it later

@adiholden adiholden merged commit 50f50c8 into main Feb 15, 2023
@romange romange deleted the no_switch_journal_write branch February 18, 2023 16:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants