Skip to content

Commit

Permalink
chore: provide basic logging to catch possible command errors
Browse files Browse the repository at this point in the history
  • Loading branch information
romange committed Jun 17, 2024
1 parent 6e0e3cb commit ac3627a
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 9 deletions.
12 changes: 12 additions & 0 deletions src/facade/conn_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,16 @@ size_t ConnectionContext::UsedMemory() const {
return dfly::HeapSize(rbuilder_) + dfly::HeapSize(authed_username) + dfly::HeapSize(acl_commands);
}

void ConnectionContext::SendError(std::string_view str, std::string_view type) {
rbuilder_->SendError(str, type);
}

void ConnectionContext::SendError(ErrorReply error) {
rbuilder_->SendError(error);
}

void ConnectionContext::SendError(OpStatus status) {
rbuilder_->SendError(status);
}

} // namespace facade
12 changes: 3 additions & 9 deletions src/facade/conn_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,11 @@ class ConnectionContext {
return res;
}

void SendError(std::string_view str, std::string_view type = std::string_view{}) {
rbuilder_->SendError(str, type);
}
virtual void SendError(std::string_view str, std::string_view type = std::string_view{});

void SendError(ErrorReply error) {
rbuilder_->SendError(error);
}
virtual void SendError(ErrorReply error);

void SendError(OpStatus status) {
rbuilder_->SendError(status);
}
virtual void SendError(OpStatus status);

void SendStored() {
rbuilder_->SendStored();
Expand Down
23 changes: 23 additions & 0 deletions src/server/conn_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,29 @@ size_t ConnectionContext::UsedMemory() const {
return facade::ConnectionContext::UsedMemory() + dfly::HeapSize(conn_state);
}

void ConnectionContext::SendError(std::string_view str, std::string_view type) {
string_view name = cid ? cid->name() : string_view{};

VLOG(1) << "Sending error " << str << " " << type << " during " << name;
facade::ConnectionContext::SendError(str, type);
}

void ConnectionContext::SendError(facade::ErrorReply error) {
string_view name = cid ? cid->name() : string_view{};

VLOG(1) << "Sending error " << error.ToSv() << " during " << name;
facade::ConnectionContext::SendError(std::move(error));
}

void ConnectionContext::SendError(facade::OpStatus status) {
if (status != facade::OpStatus::OK) {
string_view name = cid ? cid->name() : string_view{};
VLOG(1) << "Sending error " << status << " during " << name;
}

facade::ConnectionContext::SendError(status);
}

void ConnectionState::ExecInfo::Clear() {
DCHECK(!preborrowed_interpreter); // Must have been released properly
state = EXEC_INACTIVE;
Expand Down
4 changes: 4 additions & 0 deletions src/server/conn_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,10 @@ class ConnectionContext : public facade::ConnectionContext {

size_t UsedMemory() const override;

void SendError(std::string_view str, std::string_view type = std::string_view{}) override;
void SendError(facade::ErrorReply error) override;
void SendError(facade::OpStatus status) override;

// Whether this connection is a connection from a replica to its master.
// This flag is true only on replica side, where we need to setup a special ConnectionContext
// instance that helps applying commands coming from master.
Expand Down

0 comments on commit ac3627a

Please sign in to comment.