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

Function MakeReIndexMsg

pg_documentdb/src/commands/create_indexes.c:6637–6708  ·  view source on GitHub ↗

* MakeReIndexMsg returns a bson object that encapsulates given * ReIndexResult object. */

Source from the content-addressed store, hash-verified

6635 * ReIndexResult object.
6636 */
6637static pgbson *
6638MakeReIndexMsg(ReIndexResult *result)
6639{
6640 /* Build the response of the format for successful reindex or
6641 * a faulted response with a reason of failure
6642 * {
6643 * nIndexesWas: 1,
6644 * nIndexes: 1,
6645 * indexes: [
6646 * {
6647 * "v": 2,
6648 * "key": {"_id": 1}
6649 * "name": "_id_"
6650 * }
6651 * ],
6652 * ok: 1
6653 * }
6654 * or
6655 * {
6656 * ok: 0,
6657 * errmsg: "XYZ",
6658 * code: "ABCD"
6659 * }
6660 */
6661
6662 pgbson_writer writer;
6663 PgbsonWriterInit(&writer);
6664
6665 if (result->ok)
6666 {
6667 PgbsonWriterAppendInt32(&writer, "nIndexesWas", strlen("nIndexesWas"),
6668 result->nIndexesWas);
6669 PgbsonWriterAppendInt32(&writer, "nIndexes", strlen("nIndexes"),
6670 result->nIndexes);
6671
6672 /* List of indexes rebuilt */
6673 pgbson_array_writer indexesWriter;
6674 PgbsonWriterStartArray(&writer, "indexes", strlen("indexes"), &indexesWriter);
6675
6676 ListCell *indexDetailCell = NULL;
6677 foreach(indexDetailCell, result->indexesDetails)
6678 {
6679 const IndexDetails *indexDetail = (IndexDetails *) lfirst(indexDetailCell);
6680 PgbsonArrayWriterWriteDocument(&indexesWriter, IndexSpecAsBson(
6681 &(indexDetail->indexSpec)));
6682 }
6683 PgbsonWriterEndArray(&writer, &indexesWriter);
6684 }
6685
6686 PgbsonWriterAppendInt32(&writer, "ok", strlen("ok"), result->ok);
6687
6688 if (!result->ok)
6689 {
6690 if (result->errcode == ERRCODE_T_R_DEADLOCK_DETECTED)
6691 {
6692 result->errmsg = "deadlock detected. reIndex() command "
6693 "might cause deadlock when there is a "
6694 "concurrent operation that require exclusive "

Callers 1

Calls 9

PgbsonWriterInitFunction · 0.85
PgbsonWriterAppendInt32Function · 0.85
PgbsonWriterStartArrayFunction · 0.85
IndexSpecAsBsonFunction · 0.85
PgbsonWriterEndArrayFunction · 0.85
PgbsonWriterAppendUtf8Function · 0.85
PgbsonWriterGetPgbsonFunction · 0.85
foreachFunction · 0.50

Tested by

no test coverage detected