mapleFU commented on code in PR #2689:
URL: https://github.com/apache/kvrocks/pull/2689#discussion_r1877749326
##########
src/cluster/replication.cc:
##########
@@ -576,31 +576,35 @@ ReplicationThread::CBState
ReplicationThread::incrementBatchLoopCB(bufferevent *
}
case Incr_batch_data:
// Read bulk data (batch data)
- if (incr_bulk_len_ + 2 <= evbuffer_get_length(input)) { // We got
enough data
- bulk_data = reinterpret_cast<char *>(evbuffer_pullup(input,
static_cast<ssize_t>(incr_bulk_len_ + 2)));
- std::string bulk_string = std::string(bulk_data, incr_bulk_len_);
- // master would send the ping heartbeat packet to check whether the
slave was alive or not,
- // don't write ping to db here.
- if (bulk_string != "ping") {
- auto s = storage_->ReplicaApplyWriteBatch(std::string(bulk_data,
incr_bulk_len_));
- if (!s.IsOK()) {
- LOG(ERROR) << "[replication] CRITICAL - Failed to write batch to
local, " << s.Msg() << ". batch: 0x"
- << util::StringToHex(bulk_string);
- return CBState::RESTART;
- }
+ if (incr_bulk_len_ + 2 > evbuffer_get_length(input)) { // If data not
enough
+ return CBState::AGAIN;
+ }
- s = parseWriteBatch(bulk_string);
- if (!s.IsOK()) {
- LOG(ERROR) << "[replication] CRITICAL - failed to parse write
batch 0x" << util::StringToHex(bulk_string)
- << ": " << s.Msg();
- return CBState::RESTART;
- }
- }
- evbuffer_drain(input, incr_bulk_len_ + 2);
- incr_state_ = Incr_batch_size;
- } else {
+ char* bulk_data = reinterpret_cast<char *>(evbuffer_pullup(input,
static_cast<ssize_t>(incr_bulk_len_ + 2)));
+ std::string bulk_string = std::string(bulk_data, incr_bulk_len_);
+ evbuffer_drain(input, incr_bulk_len_ + 2);
+ incr_state_ = Incr_batch_size;
+
+ if (bulk_string == "ping") {
return CBState::AGAIN;
}
+
+ rocksdb::WriteBatch batch(std::move(bulk_string));
+
+ auto s = storage_->ReplicaApplyWriteBatch(&batch);
+ if (!s.IsOK()) {
+ LOG(ERROR) << "[replication] CRITICAL - Failed to write batch to
local, " << s.Msg() << ". batch: 0x"
+ << util::StringToHex(bulk_string);
Review Comment:
used-after-move?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]