* Reentrant function that looks at the update spec * and parses the update list OR update sequence of documents * and builds a batch update spec. * This is done as a second pass so that in subsequent changes, * for single shard updates, we can skip the parse stage and just * send the entire spec to the worker. */
| 728 | * send the entire spec to the worker. |
| 729 | */ |
| 730 | static void |
| 731 | BuildUpdates(BatchUpdateSpec *spec) |
| 732 | { |
| 733 | if (spec->updates != NIL) |
| 734 | { |
| 735 | return; |
| 736 | } |
| 737 | |
| 738 | List *updates = NIL; |
| 739 | if (spec->updateSequence != NULL) |
| 740 | { |
| 741 | updates = BuildUpdateSpecListFromSequence(spec->updateSequence, &spec->hasUpsert, |
| 742 | &spec->variableSpec); |
| 743 | } |
| 744 | else if (spec->updateValue.value_type == BSON_TYPE_ARRAY) |
| 745 | { |
| 746 | bson_iter_t updateArrayIter; |
| 747 | BsonValueInitIterator(&spec->updateValue, &updateArrayIter); |
| 748 | updates = BuildUpdateSpecList(&updateArrayIter, &spec->hasUpsert, |
| 749 | &spec->variableSpec); |
| 750 | } |
| 751 | else |
| 752 | { |
| 753 | ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_LOCATION40414), |
| 754 | errmsg("Required field 'update.updates' is missing"))); |
| 755 | } |
| 756 | |
| 757 | int updateCount = list_length(updates); |
| 758 | if (updateCount == 0 || updateCount > MaxWriteBatchSize) |
| 759 | { |
| 760 | ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INVALIDLENGTH), |
| 761 | errmsg("Batch sizes should always fall between 1 and %d. " |
| 762 | "Got %d operations.", MaxWriteBatchSize, updateCount), |
| 763 | errdetail_log("Batch sizes should always fall between 1 and %d. " |
| 764 | "Got %d operations.", MaxWriteBatchSize, |
| 765 | updateCount))); |
| 766 | } |
| 767 | |
| 768 | spec->updates = updates; |
| 769 | ReportUpdateFeatureUsage(list_length(updates)); |
| 770 | } |
| 771 | |
| 772 | |
| 773 | /* |
no test coverage detected