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

Function reindex_concurrently

pg_documentdb/src/commands/create_indexes.c:1134–1232  ·  view source on GitHub ↗

* Rebuilds/reindexes all collection indexes concurrently */

Source from the content-addressed store, hash-verified

1132 * Rebuilds/reindexes all collection indexes concurrently
1133 */
1134static ReIndexResult
1135reindex_concurrently(Datum dbNameDatum, Datum collectionNameDatum)
1136{
1137 ReIndexResult result = { 0 };
1138
1139 MongoCollection *collection =
1140 GetMongoCollectionByNameDatum(dbNameDatum, collectionNameDatum,
1141 AccessShareLock);
1142 if (!collection)
1143 {
1144 ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_NAMESPACENOTFOUND),
1145 errmsg("The specified collection '%s.%s' cannot be found.",
1146 TextDatumGetCString(dbNameDatum),
1147 TextDatumGetCString(collectionNameDatum))));
1148 }
1149
1150 uint64 collectionId = collection->collectionId;
1151
1152 /*
1153 * We wait until all the active createIndexes() operations release the
1154 * AcquireAdvisoryExclusiveLockForCreateIndexes() lock, then only get the list of indexes to rebuild
1155 *
1156 * Please note that the lock will be released after first transaction commit, and further
1157 * create index operation can run parallely, but those will not be considered for reIndex
1158 */
1159 AcquireAdvisoryExclusiveLockForCreateIndexes(collectionId);
1160
1161 bool excludeIdIndex = false;
1162 bool enableNestedDistribution = false;
1163 List *indexesDetailList = CollectionIdGetIndexes(collectionId, excludeIdIndex,
1164 enableNestedDistribution);
1165 List *indexIdList = NIL;
1166 ListCell *indexDetailCell = NULL;
1167 foreach(indexDetailCell, indexesDetailList)
1168 {
1169 const IndexDetails *indexDetail = (IndexDetails *) lfirst(indexDetailCell);
1170 indexIdList = lappend_int(indexIdList, indexDetail->indexId);
1171 }
1172
1173 /* save the memory context before committing the transaction */
1174 MemoryContext procMemContext = CurrentMemoryContext;
1175
1176 /*
1177 * Because we are rebuilding the indexes concurrently we should
1178 * mark our indexes as build-in-progress until UnsetIndexesAsBuildInProgress()
1179 * is called, backend exits, or an ereport(ERROR) call is made.
1180 *
1181 * That way, other sessions querying index metadata can take our indexes
1182 * into the account for various purposes.
1183 *
1184 * If any of the index is still building then throw relevant DocumentDB error
1185 */
1186 int ignore;
1187 if (!SetIndexesAsBuildInProgress(indexIdList, &ignore))
1188 {
1189 ereport(ERROR, (errcode(
1190 ERRCODE_DOCUMENTDB_BACKGROUNDOPERATIONINPROGRESSFORNAMESPACE),
1191 errmsg(

Callers 1

command_reindexFunction · 0.85

Tested by

no test coverage detected