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

Refactor replication code #1507

Merged
merged 8 commits into from
Jul 17, 2023
Merged

Refactor replication code #1507

merged 8 commits into from
Jul 17, 2023

Conversation

royjacobson
Copy link
Contributor

No functional changes.

Commit #1: Split I/O logic away
Commit #2: Split shard replication into a new class.

@royjacobson royjacobson requested review from chakaz and adiholden July 2, 2023 14:34
src/server/main_service.h Outdated Show resolved Hide resolved
src/server/protocol_client.h Show resolved Hide resolved
src/server/protocol_client.h Show resolved Hide resolved
src/server/protocol_client.h Outdated Show resolved Hide resolved
src/server/replica.h Outdated Show resolved Hide resolved
src/server/replica.h Outdated Show resolved Hide resolved
src/server/replica.h Outdated Show resolved Hide resolved
src/server/replica.h Show resolved Hide resolved
src/server/replica.h Outdated Show resolved Hide resolved
src/server/protocol_client.cc Show resolved Hide resolved
src/server/protocol_client.h Show resolved Hide resolved
Comment on lines +164 to +169
/* These may help but require additional field testing to learn.
int yes = 1;
CHECK_EQ(0, setsockopt(sock_->native_handle(), IPPROTO_TCP, TCP_NODELAY, &yes, sizeof(yes)));
CHECK_EQ(0, setsockopt(sock_->native_handle(), SOL_SOCKET, SO_KEEPALIVE, &yes, sizeof(yes)));

int intv = 15;
CHECK_EQ(0, setsockopt(sock_->native_handle(), IPPROTO_TCP, TCP_KEEPIDLE, &intv, sizeof(intv)));

intv /= 3;
CHECK_EQ(0, setsockopt(sock_->native_handle(), IPPROTO_TCP, TCP_KEEPINTVL, &intv, sizeof(intv)));

intv = 3;
CHECK_EQ(0, setsockopt(sock_->native_handle(), IPPROTO_TCP, TCP_KEEPCNT, &intv, sizeof(intv)));
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd put this in an issue / discussion rather than here..

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just moved it around :) but honestly I don't think I mind it as much

src/server/replica.cc Outdated Show resolved Hide resolved
@royjacobson royjacobson requested a review from chakaz July 9, 2023 13:18

ABSL_FLAG(std::string, masterauth, "", "password for authentication with master");

#define RETURN_ON_BAD_RESPONSE(x) \
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd move this to a header instead of duplicating it.
I know, it's a macro and they are evil, but duplicating macros is even more evil :)

return server_context_;
}

void ResetParser(bool server_mode);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's much clearer to define an enum (instead of a bool) for such arguments. Especially for the call sites. It's also more extensible.
Also see https://abseil.io/tips/94

BTW I realize that all this function does is pass the bool to the c'tor of RedisParser. I think we should fix that c'tor as well (obviously beyond the scope of this PR).

// from the sock_. The output will reside in resp_args_.
// For error reporting purposes, the parsed command would be in last_resp_ if copy_msg is true.
// If io_buf is not given, a temporary buffer will be used.
io::Result<size_t> ReadRespReply(base::IoBuf* buffer = nullptr, bool copy_msg = true);
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto re/ copy_msg (see below)


result = parser_->Parse(buffer->InputBuffer(), &consumed, &resp_args_);
if (copy_msg)
last_resp_ += std::string_view((char*)buffer->InputBuffer().data(), consumed);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we use static_cast instead of c-style cast here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Apparently you need reinterpret_cast in this case, lol. It's fine since I cast into char* and we don't reallyy care about encodings here, but it's nicer to be as scary about this as possible I guess.

src/server/replica.cc Show resolved Hide resolved
Comment on lines 528 to 529
ec = response.error();
break;
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason not to return early here, i.e. return rc;?


void DflyShardReplica::StableSyncDflyAcksFb(Context* cntx) {
constexpr size_t kAckRecordMaxInterval = 1024;
Copy link
Contributor

Choose a reason for hiding this comment

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

Move this to be a global (probably anonymous namespace) var?

@royjacobson
Copy link
Contributor Author

This needs more work: I'm doing some things I'm not allowed to do with buffers in the redis replication flow.

* Fix the redis replication code.
@royjacobson royjacobson merged commit 6d2fcba into main Jul 17, 2023
@romange romange deleted the refactor_replica branch July 31, 2023 16:09
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