MCPcopy Create free account
hub / github.com/FoundationDB/fdb-document-layer / ExtReplaceUpdate

Class ExtReplaceUpdate

src/ExtMsg.actor.cpp:1355–1393  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1353};
1354
1355struct ExtReplaceUpdate : ConcreteUpdateOp<ExtReplaceUpdate> {
1356 bson::BSONObj replaceWith;
1357
1358 explicit ExtReplaceUpdate(bson::BSONObj const& replaceWith) : replaceWith(replaceWith) {}
1359
1360 Future<Void> update(Reference<IReadWriteContext> document) override { return replacementActor(this, document); }
1361
1362 std::string describe() override { return "ReplaceWith(" + replaceWith.toString() + ")"; }
1363
1364 ACTOR static Future<Void> replacementActor(ExtReplaceUpdate* self, Reference<IReadWriteContext> document) {
1365 state Standalone<StringRef> keyEncodedId = wait(document->getKeyEncodedId());
1366 Optional<IdInfo> encodedIds = extractEncodedIds(self->replaceWith);
1367 if (encodedIds.present() && encodedIds.get().keyEncoded != keyEncodedId) {
1368 throw replace_with_id();
1369 }
1370
1371 Optional<DataValue> iddv2 =
1372 wait(document->get(DataValue(DocLayerConstants::ID_FIELD, DVTypeCode::STRING).encode_key_part()));
1373 document->clearDescendants();
1374
1375 if (iddv2.get().getBSONType() == bson::BSONType::Object) {
1376 DataValue iddv = DataValue::decode_key_part(keyEncodedId);
1377 if (iddv.getBSONType() == bson::BSONType::Object) {
1378 insertElementRecursive(iddv.wrap(DocLayerConstants::ID_FIELD).getField(DocLayerConstants::ID_FIELD),
1379 document);
1380 }
1381 } else {
1382 document->set(DataValue(DocLayerConstants::ID_FIELD, DVTypeCode::STRING).encode_key_part(),
1383 iddv2.get().encode_value());
1384 }
1385
1386 for (auto i = self->replaceWith.begin(); i.more();) {
1387 auto e = i.next();
1388 insertElementRecursive(e, document);
1389 }
1390 document->set(StringRef(), DataValue::subObject().encode_value());
1391 return Void();
1392 }
1393};
1394
1395struct ExtOperatorUpsert : ConcreteInsertOp<ExtOperatorUpsert> {
1396 bson::BSONObj selector;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected