MCPcopy Create free account
hub / github.com/apache/kvrocks / parseWriteBatch

Method parseWriteBatch

src/cluster/replication.cc:1157–1197  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1155}
1156
1157Status ReplicationThread::parseWriteBatch(const rocksdb::WriteBatch &write_batch) {
1158 WriteBatchHandler write_batch_handler;
1159
1160 auto db_status = write_batch.Iterate(&write_batch_handler);
1161 if (!db_status.ok()) return {Status::NotOK, "failed to iterate over write batch: " + db_status.ToString()};
1162
1163 switch (write_batch_handler.Type()) {
1164 case kBatchTypePublish:
1165 srv_->PublishMessage(write_batch_handler.Key(), write_batch_handler.Value());
1166 break;
1167 case kBatchTypePropagate:
1168 if (write_batch_handler.Key() == engine::kPropagateScriptCommand) {
1169 std::vector<std::string> tokens = util::TokenizeRedisProtocol(write_batch_handler.Value());
1170 if (!tokens.empty()) {
1171 auto s = srv_->ExecPropagatedCommand(tokens);
1172 if (!s.IsOK()) {
1173 return s.Prefixed("failed to execute propagate command");
1174 }
1175 }
1176 } else if (write_batch_handler.Key() == kNamespaceDBKey) {
1177 auto s = srv_->GetNamespace()->LoadAndRewrite();
1178 if (!s.IsOK()) {
1179 return s.Prefixed("failed to load namespaces");
1180 }
1181 }
1182 break;
1183 case kBatchTypeStream: {
1184 auto key = write_batch_handler.Key();
1185 InternalKey ikey(key, storage_->IsSlotIdEncoded());
1186 Slice entry_id = ikey.GetSubKey();
1187 redis::StreamEntryID id;
1188 GetFixed64(&entry_id, &id.ms);
1189 GetFixed64(&entry_id, &id.seq);
1190 srv_->OnEntryAddedToStream(ikey.GetNamespace().ToString(), ikey.GetKey().ToString(), id);
1191 break;
1192 }
1193 case kBatchTypeNone:
1194 break;
1195 }
1196 return Status::OK();
1197}
1198
1199bool ReplicationThread::isRestoringError(std::string_view err) {
1200 // err doesn't contain the CRLF, so cannot use redis::Error here.

Callers

nothing calls this directly

Calls 15

TokenizeRedisProtocolFunction · 0.85
GetFixed64Function · 0.85
PublishMessageMethod · 0.80
ExecPropagatedCommandMethod · 0.80
LoadAndRewriteMethod · 0.80
IsSlotIdEncodedMethod · 0.80
GetSubKeyMethod · 0.80
OnEntryAddedToStreamMethod · 0.80
GetKeyMethod · 0.80
ToStringMethod · 0.45
TypeMethod · 0.45
KeyMethod · 0.45

Tested by

no test coverage detected