Skip to content

redis command splitter refactor#1273

Merged
danielhochman merged 7 commits intomasterfrom
redis-splitter-refactor
Jul 18, 2017
Merged

redis command splitter refactor#1273
danielhochman merged 7 commits intomasterfrom
redis-splitter-refactor

Conversation

@danielhochman
Copy link
Copy Markdown
Contributor

This is a refactor to move logic from the handler into the request. This will make it possible to create an abstract base class for fragmented commands (MGET + MSET, DEL, EXISTS, TOUCH, etc) to share some of the splitting logic.

Copy link
Copy Markdown
Contributor

@dnoe dnoe left a comment

Choose a reason for hiding this comment

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

Minor nit about unique_ptr initialization.

const RespValue& incoming_request,
SplitCallbacks& callbacks) {
std::unique_ptr<SimpleRequest> request_ptr =
std::unique_ptr<SimpleRequest>{new SimpleRequest(callbacks)};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why not std::unique_ptr<SimpleRequest> request_ptr{new SimpleRequest(callbacks)}; ?

SplitRequestPtr MGETRequest::create(ConnPool::Instance& conn_pool,
const RespValue& incoming_request, SplitCallbacks& callbacks) {
std::unique_ptr<MGETRequest> request_ptr =
std::unique_ptr<MGETRequest>{new MGETRequest(callbacks)};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Here too, can you just do:

std::unique_ptr<MGETRequest> request_ptr{new MGETRequest(callbacks)}

Copy link
Copy Markdown
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

Looks good, some small comments.

return std::move(request_ptr);
}

AllParamsToOneServerCommandHandler::SplitRequestImpl::~SplitRequestImpl() { ASSERT(!handle_); }
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This ASSERT should remain. I would add back the destructor and the assert.

pending_requests_.reserve(num_responses);
}

MGETCommandHandler::SplitRequestImpl::~SplitRequestImpl() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same. Retain destructor and all ASSERTS (if there are others that I am missing).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed both cases

ENVOY_LOG(debug, "redis: response: '{}'", pending_response_->toString());
ASSERT(num_pending_responses_ > 0);
if (--num_pending_responses_ == 0) {
// ENVOY_LOG(debug, "redis: response: '{}'", pending_response_->toString());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why is this commented out?

struct SplitRequestImpl : public SplitRequest, public ConnPool::PoolCallbacks {
SplitRequestImpl(SplitCallbacks& callbacks) : callbacks_(callbacks) {}
~SplitRequestImpl();
void onFailure();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

All overrides should have "override" postfix, del newline between definitions, and add // Redis::ConnPool::PoolCallbacks between them. Same in other places.

class MGETCommandHandler : public CommandHandler,
CommandHandlerBase,
Logger::Loggable<Logger::Id::redis> {
class MGETRequest : public SplitRequest {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Add class comment

uint32_t num_pending_responses_;
};

template <class RequestClass>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Add class comment

static SplitRequestPtr create(ConnPool::Instance& conn_pool, const RespValue& incoming_request,
SplitCallbacks& callbacks);

void onChildResponse(RespValuePtr&& value, uint32_t index);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think these 2 methods can be private?

PendingRequest& pending_request = request_ptr->pending_requests_.back();

single_mget.asArray()[1].asString() = request.asArray()[i].asString();
ENVOY_LOG(debug, "redis: parallel get: '{}'", single_mget.toString());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why remove this debug print?


MGETRequest::~MGETRequest() {
#ifndef NDEBUG
for (const PendingRequest& request : pending_requests_) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'd be curious if the compiler optimizer is smart enough to remove the entire loop when ASSERT is compiled out rendering this #ifdef unnecessary.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I kind of doubt it, but I would be curious also. :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Prepare to be impressed. I compiled this with Clang++ -O2 -S to see the assembly (using cassert, but it should be equivalent to our macro):

void do_nothing_to_vector(std::vector<std::string>& foo) {
  for (const std::string& s : foo) {
    assert(s.size() > 1);
  }
}

If you add -DNDEBUG to the Clang command line the assembly it generates is just "retq"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

cool

Copy link
Copy Markdown
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

LGTM. I don't care either way about the NDEBUG removal. (I guess my preference would be to not depend on a compiler optimization in this case, but I don't care that much). @dnoe can decide whether he cares or not.

Copy link
Copy Markdown
Contributor

@dnoe dnoe left a comment

Choose a reason for hiding this comment

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

I think leaving the ifdef here is fine. It's a slightly ugly leak of the assert implementation, but it makes it obvious to someone reading the code that the loop is gone in opt builds.

@danielhochman danielhochman merged commit d56c6d2 into master Jul 18, 2017
@danielhochman danielhochman deleted the redis-splitter-refactor branch July 18, 2017 18:32
jpsim pushed a commit that referenced this pull request Nov 28, 2022
Description: Standardizes source and test paths across languages.
Risk Level: Moderate
Testing: Local and CI

Signed-off-by: Mike Schore <mike.schore@gmail.com>
Signed-off-by: JP Simard <jp@jpsim.com>
jpsim pushed a commit that referenced this pull request Nov 29, 2022
Description: Standardizes source and test paths across languages.
Risk Level: Moderate
Testing: Local and CI

Signed-off-by: Mike Schore <mike.schore@gmail.com>
Signed-off-by: JP Simard <jp@jpsim.com>
mathetake added a commit that referenced this pull request Mar 3, 2026
**Description**

This is a follow up on #1248, and enables the skipped test case by using
the old commit hash. We will pin it later to the next version which is
v0.4.0.

Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
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.

3 participants