| 1155 | } |
| 1156 | |
| 1157 | Status 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 | |
| 1199 | bool ReplicationThread::isRestoringError(std::string_view err) { |
| 1200 | // err doesn't contain the CRLF, so cannot use redis::Error here. |
nothing calls this directly
no test coverage detected