MCPcopy Create free account
hub / github.com/documentdb/documentdb / AddIndexBuilds

Function AddIndexBuilds

pg_documentdb/src/commands/current_op.c:1274–1429  ·  view source on GitHub ↗

* Port from the current_op 1.8 SQL file - tracks the index build failures from background index * build status and updates the currentOp document for it. */

Source from the content-addressed store, hash-verified

1272 * build status and updates the currentOp document for it.
1273 */
1274static void
1275AddIndexBuilds(TupleDesc descriptor, Tuplestorestate *tupleStore)
1276{
1277 /* This can be cleaned up to be better - but not in the current iteration */
1278 StringInfo queryInfo = makeStringInfo();
1279 appendStringInfo(queryInfo, " SELECT "
1280 " coll.database_name AS database_name, "
1281 " coll.collection_name AS collection_name, "
1282 " ci.index_spec AS index_spec, "
1283 " iq.index_cmd_status AS status, "
1284 " COALESCE(iq.comment::text, '') AS comment, "
1285 " coll.database_name || '.' || coll.collection_name AS ns "
1286 " FROM %s AS iq "
1287 " JOIN %s.collection_indexes AS ci ON (iq.index_id = ci.index_id) "
1288 " JOIN %s.collections AS coll ON (ci.collection_id = coll.collection_id) "
1289 " WHERE iq.cmd_type = 'C' AND ( "
1290 " iq.index_cmd_status IN (1, 3) "
1291 " )", GetIndexQueueName(), ApiCatalogSchemaName,
1292 ApiCatalogSchemaName);
1293
1294 SPIParseOpenOptions parseOptions =
1295 {
1296 .read_only = true,
1297 .cursorOptions = 0,
1298 .params = NULL
1299 };
1300 MemoryContext priorMemoryContext = CurrentMemoryContext;
1301 SPI_connect();
1302
1303 Portal currentOpPortal = SPI_cursor_parse_open("failedIndexesPortal", queryInfo->data,
1304 &parseOptions);
1305 bool hasData = true;
1306 while (hasData)
1307 {
1308 SPI_cursor_fetch(currentOpPortal, true, 1);
1309
1310 hasData = SPI_processed >= 1;
1311 if (!hasData)
1312 {
1313 break;
1314 }
1315
1316 bool isNull;
1317 AttrNumber databaseAttr = 1;
1318 Datum resultDatum = SPI_getbinval(SPI_tuptable->vals[0],
1319 SPI_tuptable->tupdesc, databaseAttr,
1320 &isNull);
1321 if (isNull)
1322 {
1323 continue;
1324 }
1325
1326 char *databaseName = TextDatumGetCString(SPI_datumTransfer(resultDatum, false,
1327 -1));
1328
1329 AttrNumber collectionAttr = 2;
1330 resultDatum = SPI_getbinval(SPI_tuptable->vals[0],
1331 SPI_tuptable->tupdesc, collectionAttr,

Callers 1

CurrentOpAggregateCoreFunction · 0.85

Calls 13

GetIndexQueueNameFunction · 0.85
DatumGetIndexSpecFunction · 0.85
IsBsonHexadecimalStringFunction · 0.85
PgbsonInitFromJsonFunction · 0.85
PgbsonInitIteratorAtPathFunction · 0.85
PgbsonWriterInitFunction · 0.85
PgbsonWriterAppendUtf8Function · 0.85
PgbsonWriterEndDocumentFunction · 0.85
PgbsonWriterAppendBoolFunction · 0.85

Tested by

no test coverage detected