-
Notifications
You must be signed in to change notification settings - Fork 883
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): support config set for some flags #1624
Conversation
adiholden
commented
Aug 2, 2023
•
edited
Loading
edited
- support config set for the following flags: rename_command,dir,requirepass,masterauth
- add tcp_keepalive flag and add supprot with config set
- more print details when failing on dbfilename flag validation
src/server/main_service.cc
Outdated
@@ -617,6 +617,10 @@ void Service::Init(util::AcceptServer* acceptor, std::vector<facade::Listener*> | |||
return true; | |||
}); | |||
|
|||
config_registry.Register("dir", [](const absl::CommandLineFlag& flag) { return true; }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps we could add some default function that does nothing, or an overload that does so?
src/facade/dragonfly_listener.cc
Outdated
|
||
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val)) < 0) { | ||
LOG(WARNING) << "Could not set reuse addr on socket " << SafeErrorMessage(errno); | ||
} | ||
bool success = ConfigureKeepAlive(fd, kInterval); | ||
uint32_t interval = absl::GetFlag(FLAGS_tcp_keepalive); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I'd remove the var interval
and call GetFlag()
inline of ConfigureKeepAlive()
, your call
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I need to do validation on this flag value, so register call back is needed.pushing now my changes
src/server/command_registry.cc
Outdated
string_view origin_name = AsciiStrToUpper(kv.first); | ||
string_view new_name = AsciiStrToUpper(kv.second); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are actually undefined behavior and could crash
AsciiStrToUpper()
's return type is string
, and assigning such temporaries into a string_view
is bad.
I wish we had something to catch such cases :(
Anyway, origin_name
and new_name
should be of type string
src/server/command_registry.cc
Outdated
auto apply_cb_on_all_commands = [](const std::vector<std::string>& commands, | ||
std::function<bool(string_view, string_view)> cb) { | ||
for (string command_data : commands) { | ||
pair<string_view, string_view> kv = StrSplit(command_data, '='); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here and above, this will be unexpected behavior if the new value is expected to have =
inside the name.
Maybe use absl::MaxSplits('=', 1)
instead of just '='
?
please note that |
@adiholden correct me if I'm wrong, but I think that specifically this string never changes. It's just how we get to the |
1. support config set for the following flags: rename_command,dir,requirepass,masterauth 2. more print details when failing on dbfilename flag validation Signed-off-by: adi_holden <adi@dragonflydb.io>
Signed-off-by: adi_holden <adi@dragonflydb.io>
ee525df
to
25c82f1
Compare
src/facade/dragonfly_listener.cc
Outdated
@@ -139,6 +142,18 @@ Listener::Listener(Protocol protocol, ServiceInterface* si) : service_(si), prot | |||
http_base_.reset(new HttpListener<>); | |||
http_base_->set_resource_prefix("http://static.dragonflydb.io/data-plane"); | |||
si->ConfigureHttpHandlers(http_base_.get()); | |||
|
|||
tcp_keepalive = absl::GetFlag(FLAGS_tcp_keepalive); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This cache is not thread safe, in that an access to tcp_keepalive
can occur in parallel to setting it.
However, are you sure it's something we need to cache? We read it upon receiving a new connection, it's definitely something that can be slowed down. I'd vote to reduce complexity and not cache.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I concur. connection creation is not on a hotpath.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the reason here to use static variable is not to cache the flag but to enable the validation of the flag value i.e that it is bigger than 3. As when we call config set command we first set the flag value and then call the registered callback so I did the validation in the callback and if the validation passed I set the tcp_keepalive var. I spoke with @chakaz and he suggested to do this validation with using the absl custom flags inside the AbslParseFlag. I can do this but then the question raised do we really need this validation @romange ? I believe we have this validation today because we devide tcp_keepalive value by 3 when setting the interval between subsequent keep-alive probes. But I could just make it min value 1. Does this makes sense?
Indead there is a problem here and also not only here but when we run find command we return a pointer to the map, so I can not change the command map .I will need to think on another solutions |
The string in CommadId class does not change but we have another problem here. It is that we return a pointer to the map item CommandId when we execute a command and in the current implementation I move the object, so when executing a command the pointer maybe invalid after rename |
I did not understand the problematic scenario. Where exactly we keep the stale pointer? |
Adi and I just discussed this. |
I am going to remove the support for config set rename_command in this PR as it looks to be a bigger change than what I thought and I will do it in a different PR |
Signed-off-by: adi_holden <adi@dragonflydb.io>
Signed-off-by: adi_holden <adi@dragonflydb.io>
Signed-off-by: adi_holden <adi@dragonflydb.io>
Signed-off-by: adi_holden <adi@dragonflydb.io>
@adiholden let's not support |
another thing: the renamee feature can be redesigned differently if we take into account the admin port. |
src/facade/dragonfly_listener.cc
Outdated
@@ -27,6 +26,7 @@ ABSL_FLAG(string, tls_cert_file, "", "cert file for tls connections"); | |||
ABSL_FLAG(string, tls_key_file, "", "key file for tls connections"); | |||
ABSL_FLAG(string, tls_ca_cert_file, "", "ca signed certificate to validate tls connections"); | |||
ABSL_FLAG(string, tls_ca_cert_dir, "", "ca signed certificates directory"); | |||
ABSL_FLAG(uint32_t, tcp_keepalive, 300, "the period in seconds used to send ACKs to client"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the description of this flag is not accurate.
- We start sending acks after the idle time that is bound to the value of this flag.,
- We give up on the connection if we have not got any ack response during the additional period that equals to the same value.
So it's worth to mention that it's a period of inactivity after which keep-alives are triggerred and the total time until the dead connection is closed is twice the specified value.
Signed-off-by: adi_holden <adi@dragonflydb.io>