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

Method call

src/ExtCmd.actor.cpp:1260–1314  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1258struct ListIndexesCmd {
1259 static const char* name;
1260 ACTOR static Future<Reference<ExtMsgReply>> call(Reference<ExtConnection> ec,
1261 Reference<ExtMsgQuery> msg,
1262 Reference<ExtMsgReply> reply) {
1263 if (msg->query.hasField("cursor")) {
1264 const auto cursorObj = msg->query.getObjectField("cursor");
1265 if (cursorObj.hasField("batchSize") && cursorObj.getIntField("batchSize") != 0) {
1266 TraceEvent(SevWarn, "unsupportedCmdOption")
1267 .detail("cmd", "listCollections")
1268 .detail("option", "cursor.batchSize");
1269 throw unsupported_cmd_option();
1270 }
1271 }
1272
1273 state Reference<DocTransaction> dtr = ec->getOperationTransaction();
1274 loop {
1275 try {
1276 Reference<UnboundCollectionContext> unbound = wait(ec->mm->indexesCollection(dtr, msg->ns.first));
1277
1278 auto getIndexesPlan = getIndexesForCollectionPlan(unbound, msg->ns);
1279 std::vector<bson::BSONObj> indexObjs = wait(getIndexesTransactionally(getIndexesPlan, dtr));
1280
1281 bson::BSONArrayBuilder indexList;
1282 for (auto& indexObj : indexObjs) {
1283 indexList << indexObj;
1284 }
1285
1286 // Add the _id index here
1287 // clang-format off
1288 indexList << BSON(
1289 DocLayerConstants::NAME_FIELD << "_id_" <<
1290 DocLayerConstants::NS_FIELD << (msg->ns.first + "." + msg->ns.second) <<
1291 DocLayerConstants::KEY_FIELD << BSON(DocLayerConstants::ID_FIELD << 1) <<
1292 DocLayerConstants::METADATA_VERSION_FIELD << 1 <<
1293 DocLayerConstants::STATUS_FIELD << DocLayerConstants::INDEX_STATUS_READY <<
1294 DocLayerConstants::UNIQUE_FIELD << true
1295 );
1296 // clang-format on
1297
1298 // FIXME: Not using cursors to return collection list.
1299 // clang-format off
1300 reply->addDocument(BSON(
1301 "cursor" << BSON(
1302 "id" << (long long) 0 <<
1303 "ns" << msg->ns.first + ".$cmd.listIndexes." + msg->ns.second <<
1304 "firstBatch" << indexList.arr()) <<
1305 "ok" << 1.0
1306 )
1307 );
1308 // clang-format on
1309 return reply;
1310 } catch (Error& e) {
1311 if (e.code() != error_code_actor_cancelled) {
1312 wait(dtr->onError(e));
1313 }
1314 }
1315 }
1316 }
1317};

Callers

nothing calls this directly

Calls 5

onErrorMethod · 0.80
indexesCollectionMethod · 0.80
addDocumentMethod · 0.80

Tested by

no test coverage detected