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

Function MakeCreateIndexesMsg

pg_documentdb/src/commands/create_indexes.c:6535–6630  ·  view source on GitHub ↗

* MakeCreateIndexesMsg returns a bson object that encapsulates given * CreateIndexesResult object. */

Source from the content-addressed store, hash-verified

6533 * CreateIndexesResult object.
6534 */
6535pgbson *
6536MakeCreateIndexesMsg(CreateIndexesResult *result)
6537{
6538 /* Response for sharded collection is of the form
6539 * {
6540 * raw: {
6541 * "shardId": {
6542 * createdCollectionAutomatically: false,
6543 * numIndexesBefore: 3,
6544 * numIndexesAfter: 5,
6545 * ok: 1
6546 * }
6547 * },
6548 * ok: 1
6549 * }
6550 */
6551
6552 pgbson_writer outerWriter;
6553 PgbsonWriterInit(&outerWriter);
6554
6555 pgbson_writer rawShardResultWriter;
6556 PgbsonWriterStartDocument(&outerWriter, "raw", strlen("raw"), &rawShardResultWriter);
6557
6558 pgbson_writer writer;
6559 PgbsonWriterStartDocument(&rawShardResultWriter, "defaultShard", strlen(
6560 "defaultShard"), &writer);
6561
6562 if (result->ok)
6563 {
6564 PgbsonWriterAppendInt32(&writer, "numIndexesBefore", strlen("numIndexesBefore"),
6565 result->numIndexesBefore);
6566 PgbsonWriterAppendInt32(&writer, "numIndexesAfter", strlen("numIndexesAfter"),
6567 result->numIndexesAfter);
6568 PgbsonWriterAppendBool(&writer, "createdCollectionAutomatically",
6569 strlen("createdCollectionAutomatically"),
6570 result->createdCollectionAutomatically);
6571 }
6572
6573 if (result->note != NULL)
6574 {
6575 PgbsonWriterAppendUtf8(&writer, "note", strlen("note"), result->note);
6576 }
6577
6578 PgbsonWriterAppendInt32(&writer, "ok", strlen("ok"), result->ok);
6579
6580 if (!result->ok)
6581 {
6582 if (result->errcode == ERRCODE_T_R_DEADLOCK_DETECTED)
6583 {
6584 result->errmsg = "deadlock detected. createIndexes() command "
6585 "might cause deadlock when there is a "
6586 "concurrent operation that require exclusive "
6587 "access on the same collection";
6588 }
6589 else if (result->errcode == ERRCODE_UNDEFINED_TABLE)
6590 {
6591 result->errcode = ERRCODE_DOCUMENTDB_INDEXBUILDABORTED;
6592 result->errmsg = COLLIDX_CONCURRENTLY_DROPPED_RECREATED_ERRMSG;

Calls 11

PgbsonWriterInitFunction · 0.85
PgbsonWriterAppendInt32Function · 0.85
PgbsonWriterAppendBoolFunction · 0.85
PgbsonWriterAppendUtf8Function · 0.85
PgbsonWriterEndDocumentFunction · 0.85
PgbsonWriterStartArrayFunction · 0.85
PgbsonWriterEndArrayFunction · 0.85
PgbsonWriterGetPgbsonFunction · 0.85
foreachFunction · 0.50

Tested by

no test coverage detected