redis command splitter refactor#1273
Conversation
dnoe
left a comment
There was a problem hiding this comment.
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)}; |
There was a problem hiding this comment.
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)}; |
There was a problem hiding this comment.
Here too, can you just do:
std::unique_ptr<MGETRequest> request_ptr{new MGETRequest(callbacks)}
mattklein123
left a comment
There was a problem hiding this comment.
Looks good, some small comments.
| return std::move(request_ptr); | ||
| } | ||
|
|
||
| AllParamsToOneServerCommandHandler::SplitRequestImpl::~SplitRequestImpl() { ASSERT(!handle_); } |
There was a problem hiding this comment.
This ASSERT should remain. I would add back the destructor and the assert.
| pending_requests_.reserve(num_responses); | ||
| } | ||
|
|
||
| MGETCommandHandler::SplitRequestImpl::~SplitRequestImpl() { |
There was a problem hiding this comment.
Same. Retain destructor and all ASSERTS (if there are others that I am missing).
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
Why is this commented out?
| struct SplitRequestImpl : public SplitRequest, public ConnPool::PoolCallbacks { | ||
| SplitRequestImpl(SplitCallbacks& callbacks) : callbacks_(callbacks) {} | ||
| ~SplitRequestImpl(); | ||
| void onFailure(); |
There was a problem hiding this comment.
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 { |
| uint32_t num_pending_responses_; | ||
| }; | ||
|
|
||
| template <class RequestClass> |
| static SplitRequestPtr create(ConnPool::Instance& conn_pool, const RespValue& incoming_request, | ||
| SplitCallbacks& callbacks); | ||
|
|
||
| void onChildResponse(RespValuePtr&& value, uint32_t index); |
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
Why remove this debug print?
|
|
||
| MGETRequest::~MGETRequest() { | ||
| #ifndef NDEBUG | ||
| for (const PendingRequest& request : pending_requests_) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
I kind of doubt it, but I would be curious also. :)
There was a problem hiding this comment.
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"
mattklein123
left a comment
There was a problem hiding this comment.
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.
dnoe
left a comment
There was a problem hiding this comment.
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.
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>
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>
**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>
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.