Skip to content

Conversation

dranikpg
Copy link
Contributor

@dranikpg dranikpg commented Aug 9, 2023

  1. Cleanly rewrite the monitor tests because it was just a mess
  2. Move monitor dispatch to InvokeCmd, so its used by all kinds of dispatches (not only those from DispatchCommand), i.e. regular multi, script & squashing
  3. Add squashing info to connection cntx, so its picked up by the monitor
  4. Fix a bug in the testing framework with argument formating (apparently gflags interprets --bool_flag false as true)

@dranikpg dranikpg requested review from romange and kostasrim and removed request for romange August 9, 2023 10:58
@romange romange changed the title fix: fix monitoring for multi transactions fix: MONITOR now works for multi transactions Aug 9, 2023
Copy link
Contributor

@kostasrim kostasrim left a comment

Choose a reason for hiding this comment

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

Nice work 👨‍🍳

conn_state.db_index = owner->conn_state.db_index;
conn_state.squashing_info = {owner};
}
delete Inject(crb); // deletes the previous reply builder.
Copy link
Contributor

Choose a reason for hiding this comment

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

I had to look to what Inject does because this statement is raw RAII :D

From my understanding, inject, swaps crb with the internal ReplyBuilder and returns it to the user.

Why don't you add a new operation InjectRelease that instead of returning the old object just releases it via assignment since it's a std::unique_ptr<SinkReplyBuilder> ? That way, we get rid off the raw delete and RAII semantics are handled by the underline unique_ptr

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually the better solution would be to pass a flag that the reply_builder is not created at all

if (cid->name() == "AUTH")
return message;

auto accum = [](auto str, const auto& cmd) {
Copy link
Contributor

Choose a reason for hiding this comment

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

accumulate is a really nice idea here. However it suffers from two issues:

  1. auto str is a deep copy each time the lambda is invoked by the accumulate algorithm. I think only in c++20 the init string message is moved, by a call to std::move. So basically now, we are copying tail_args.size() strings with each of them increasing in size at each step (since we append to the string at each step).
  2. Furthermore, another copy is done when we return str. This is not one of the cases were NRVO applies, because str is an input parameter of the lambda.

All in all, I would suggest to rewrite this with a for loop or a for-each.

Copy link
Contributor Author

@dranikpg dranikpg Aug 10, 2023

Choose a reason for hiding this comment

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

True, its code from about a year ago that I just copied over without realizing how problematic it is 😄 (didn't think about checking performance because monitor is not critical)

print(f"EVAL error: {e}")
assert False
collected = await monitor.stop()
expected = CollectedRedisMsg.all_from_src("SET a 1", "GET a", "LPUSH l V", "LPOP l")
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice!!!!

Signed-off-by: Vladislav Oleshko <[email protected]>
@dranikpg dranikpg requested a review from kostasrim August 10, 2023 12:27
kostasrim
kostasrim previously approved these changes Aug 10, 2023
@@ -123,21 +123,28 @@ struct ConnectionState {
DflyVersion repl_version = DflyVersion::VER0;
};

struct SquashingInfo {
const ConnectionContext* owner = nullptr;
Copy link
Collaborator

Choose a reason for hiding this comment

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

can you add a comment here why during squashing the owner is not the regular ConnectionContext* that you already have access to?

Copy link
Contributor Author

@dranikpg dranikpg Aug 16, 2023

Choose a reason for hiding this comment

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

Because multiple threads execute commands in parallel during squashing. Added this comment

// Pointer to the original underlying context of the base command.
// Only const access is possible for reading from multiple threads,
// each squashing thread has its own proxy context that contains this info.

Copy link
Collaborator

@romange romange left a comment

Choose a reason for hiding this comment

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

lgtm

Signed-off-by: Vladislav Oleshko <[email protected]>
@dranikpg dranikpg requested a review from romange August 16, 2023 14:59
@dranikpg dranikpg merged commit 71fa2f2 into dragonflydb:main Aug 17, 2023
@dranikpg dranikpg deleted the fix-monitoring branch August 18, 2023 19:02
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.

3 participants