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): Implement DFLY CLUSTER CONFIG command. #1223

Merged
merged 6 commits into from May 17, 2023
Merged

feat(server): Implement DFLY CLUSTER CONFIG command. #1223

merged 6 commits into from May 17, 2023

Conversation

chakaz
Copy link
Collaborator

@chakaz chakaz commented May 16, 2023

No description provided.

@chakaz chakaz requested a review from adiholden May 16, 2023 12:17
SinkReplyBuilder* rb = cntx->reply_builder();

if (args.size() != 3) {
return rb->SendError(kSyntaxErr);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Check out this error type - WrongNumArgsError

optional<JsonType> json = JsonFromString(json_str);
if (!json.has_value()) {
LOG(WARNING) << kInvalidConfigPrefix << "Can't parse JSON " << json_str;
return rb->SendError(kSyntaxErr);
Copy link
Collaborator

@adiholden adiholden May 16, 2023

Choose a reason for hiding this comment

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

better return more details in the error here
rb->SendError(kInvalidConfigPrefix, kSyntaxErrType)

return rb->SendError(kSyntaxErr);
}

optional<ClusterConfig::ClusterShards> config = BuildClusterConfigFromJson(json.value());
Copy link
Collaborator

Choose a reason for hiding this comment

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

To me it makes sense that the function BuildClusterConfigFromJson impl will be inside the ClusterConfig class
i.e change SetConfig to get json object, and all the logic to parse the json will be inside ClusterConfig

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I agree. I actually have thought about this before making the change and (originally) thought that it made sense within dflycmd.cc, but following your comment I'm convinced that it's probably better to be part of ClusterConfig' API.
So as you requested, I moved it.

@@ -0,0 +1,374 @@
// Copyright 2022, DragonflyDB authors. All rights reserved.
Copy link
Collaborator

Choose a reason for hiding this comment

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

2023 :)

class DflyFamilyTest : public BaseFamilyTest {
public:
DflyFamilyTest() {
auto* flag = absl::FindCommandLineFlag("cluster_mode");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Because you are setting the cluster mode flag here, I would call this tests DflyClusterTest , cause we might want to add to this file more test which are not under cluster mode

@@ -61,7 +64,9 @@ class ClusterConfig {
// Returns true if `new_config` is valid and internal state was changed. Returns false and changes
// nothing otherwise.
bool SetConfig(const ClusterShards& new_config);
Copy link
Collaborator

Choose a reason for hiding this comment

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

move to private?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Generally, I'd agree. I just tried to move it, but it would then require testing solely by passing json, which is more cumbersome. Also, I guess it's a nicer API to support both, although I agree that if it's not in use there's no point in keeping it.
Again, I'd love to keep it if only to make testing this class easier, OK?

Copy link
Collaborator

Choose a reason for hiding this comment

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

sure

adiholden
adiholden previously approved these changes May 17, 2023
@chakaz chakaz merged commit f80afca into main May 17, 2023
6 checks passed
@chakaz chakaz deleted the setconf branch May 17, 2023 10:02
romange pushed a commit that referenced this pull request Jun 1, 2023
* fix: Lock before accessing slots_

* Implement `DFLY CLUSTER CONFIG` command.

* Move JSON parsing logic to ClusterConfig

* clang-tidy

* Rename test fixture class
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.

None yet

2 participants