Skip to content

Commit

Permalink
chore: update command interface for main_service commands
Browse files Browse the repository at this point in the history
Clean up command_registry interface as well.

Signed-off-by: Roman Gershman <[email protected]>
  • Loading branch information
romange committed Dec 9, 2024
1 parent f9f93b1 commit 636be97
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 189 deletions.
20 changes: 2 additions & 18 deletions src/server/command_registry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,9 @@ bool CommandId::IsMultiTransactional() const {
return CO::IsTransKind(name()) || CO::IsEvalKind(name());
}

uint64_t CommandId::Invoke(CmdArgList args, Transaction* tx, facade::SinkReplyBuilder* builder,
ConnectionContext* cntx) const {
uint64_t CommandId::Invoke(CmdArgList args, const CommandContext& cmd_cntx) const {
int64_t before = absl::GetCurrentTimeNanos();
handler_(args, tx, builder, cntx);
handler_(args, cmd_cntx);
int64_t after = absl::GetCurrentTimeNanos();

ServerState* ss = ServerState::tlocal(); // Might have migrated thread, read after invocation
Expand Down Expand Up @@ -133,21 +132,6 @@ optional<facade::ErrorReply> CommandId::Validate(CmdArgList tail_args) const {
return nullopt;
}

CommandId&& CommandId::SetHandler(Handler2 f) && {
handler_ = [f = std::move(f)](CmdArgList args, Transaction* tx, facade::SinkReplyBuilder* builder,
ConnectionContext*) { f(args, tx, builder); };

return std::move(*this);
}

CommandId&& CommandId::SetHandler(Handler3 f) && {
handler_ = [f = std::move(f)](CmdArgList args, Transaction* tx, facade::SinkReplyBuilder* builder,
ConnectionContext* cntx) {
f(std::move(args), CommandContext{tx, builder, cntx});
};
return std::move(*this);
};

CommandRegistry::CommandRegistry() {
vector<string> rename_command = GetFlag(FLAGS_rename_command);

Expand Down
20 changes: 3 additions & 17 deletions src/server/command_registry.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,23 +96,13 @@ class CommandId : public facade::CommandId {
command_stats_ = std::make_unique<CmdCallStats[]>(thread_count);
}

using Handler =
fu2::function_base<true /*owns*/, true /*copyable*/, fu2::capacity_default,
false /* non-throwing*/, false /* strong exceptions guarantees*/,
void(CmdArgList, Transaction*, facade::SinkReplyBuilder*,
ConnectionContext*) const>;
using Handler2 =
fu2::function_base<true, true, fu2::capacity_default, false, false,
void(CmdArgList, Transaction*, facade::SinkReplyBuilder*) const>;

using Handler3 = fu2::function_base<true, true, fu2::capacity_default, false, false,
void(CmdArgList, const CommandContext&) const>;
using ArgValidator = fu2::function_base<true, true, fu2::capacity_default, false, false,
std::optional<facade::ErrorReply>(CmdArgList) const>;

// Returns the invoke time in usec.
uint64_t Invoke(CmdArgList args, Transaction*, facade::SinkReplyBuilder*,
ConnectionContext* cntx) const;
uint64_t Invoke(CmdArgList args, const CommandContext& cmd_cntx) const;

// Returns error if validation failed, otherwise nullopt
std::optional<facade::ErrorReply> Validate(CmdArgList tail_args) const;
Expand All @@ -135,15 +125,11 @@ class CommandId : public facade::CommandId {

static const char* OptName(CO::CommandOpt fl);

CommandId&& SetHandler(Handler f) && {
CommandId&& SetHandler(Handler3 f) && {
handler_ = std::move(f);
return std::move(*this);
}

CommandId&& SetHandler(Handler2 f) &&;

CommandId&& SetHandler(Handler3 f) &&;

CommandId&& SetValidator(ArgValidator f) && {
validator_ = std::move(f);
return std::move(*this);
Expand All @@ -169,7 +155,7 @@ class CommandId : public facade::CommandId {
private:
bool implicit_acl_;
std::unique_ptr<CmdCallStats[]> command_stats_;
Handler handler_;
Handler3 handler_;
ArgValidator validator_;
};

Expand Down
Loading

0 comments on commit 636be97

Please sign in to comment.