* Process an insertion for batch of inserts using the INSERT command. */
| 899 | * Process an insertion for batch of inserts using the INSERT command. |
| 900 | */ |
| 901 | static void |
| 902 | DoBatchInsertNoTransactionId(MongoCollection *collection, BatchInsertionSpec *batchSpec, |
| 903 | BatchInsertionResult *batchResult, ExprEvalState *evalState, |
| 904 | WriteMode writeMode) |
| 905 | { |
| 906 | List *insertions = batchSpec->documents; |
| 907 | bool isOrdered = batchSpec->isOrdered; |
| 908 | |
| 909 | int insertIndex = 0; |
| 910 | bool hasBatchedInsertFailed = false; |
| 911 | |
| 912 | ListCell *insertCell = NULL; |
| 913 | while (insertIndex < list_length(insertions)) |
| 914 | { |
| 915 | CHECK_FOR_INTERRUPTS(); |
| 916 | |
| 917 | if (writeMode == WriteMode_Bulk_Proc && insertIndex > 0) |
| 918 | { |
| 919 | /* For each iteration of the loop, commit prior work */ |
| 920 | bool setSnapshot = true; |
| 921 | CommitWriteProcedureAndReacquireCollectionLock(collection, |
| 922 | batchSpec->insertShardOid, |
| 923 | setSnapshot); |
| 924 | } |
| 925 | |
| 926 | if (list_length(insertions) > 1 && !hasBatchedInsertFailed) |
| 927 | { |
| 928 | /* Optimistically try to do multiple updates together, if it fails, try again one by one to figure out which one failed */ |
| 929 | int incrementCount = 0; |
| 930 | bool performedBatchInsert = DoMultiInsertWithoutTransactionId(collection, |
| 931 | insertions, |
| 932 | batchSpec-> |
| 933 | insertShardOid, |
| 934 | batchResult, |
| 935 | insertIndex, |
| 936 | &incrementCount, |
| 937 | evalState, |
| 938 | writeMode); |
| 939 | |
| 940 | Assert(!performedBatchInsert || incrementCount > 0); |
| 941 | if (!performedBatchInsert) |
| 942 | { |
| 943 | /* Has a failure, set hasFailures and retry */ |
| 944 | hasBatchedInsertFailed = true; |
| 945 | } |
| 946 | |
| 947 | insertIndex += incrementCount; |
| 948 | continue; |
| 949 | } |
| 950 | |
| 951 | insertCell = list_nth_cell(insertions, insertIndex); |
| 952 | const bson_value_t *document = lfirst(insertCell); |
| 953 | text *transactionId = NULL; |
| 954 | bool isSuccess = DoSingleInsertWithSubTxn(collection, batchSpec->insertShardOid, |
| 955 | document, |
| 956 | transactionId, batchResult, |
| 957 | insertIndex, evalState); |
| 958 | insertIndex++; |
no test coverage detected