mapleFU commented on code in PR #2689:
URL: https://github.com/apache/kvrocks/pull/2689#discussion_r1878084023
##########
src/cluster/replication.cc:
##########
@@ -576,31 +578,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)));
Review Comment:
```suggestion
const char* bulk_data = reinterpret_cast<const char
*>(evbuffer_pullup(input, static_cast<ssize_t>(incr_bulk_len_ + 2)));
```
?
--
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]