You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/cosmos-db/nosql/transactional-batch.md
+132-3Lines changed: 132 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -138,11 +138,140 @@ if (response.isSuccessStatusCode())
138
138
> [!IMPORTANT]
139
139
> If there's a failure, the failed operation will have a status code of its corresponding error. All the other operations will have a 424 status code (failed dependency). If the operation fails because it tries to create an item that already exists, a status code of 409 (conflict) is returned. The status code enables one to identify the cause of transaction failure.
In Python, Transactional Batch operations look very similar to the singular operations apis, and are tuples containing (operation_type_string, args_tuple, batch_operation_kwargs_dictionary). Below are sample items that will be used to demonstrate batch operations functionality:
150
+
151
+
```python
152
+
153
+
create_demo_item = {
154
+
"id": "68719520766",
155
+
"category": "road-bikes",
156
+
"name": "Chropen Road Bike"
157
+
}
158
+
159
+
# for demo, assume that this item already exists in the container.
160
+
# the item id will be used for read operation in the batch
161
+
read_demo_item1 = {
162
+
"id": "68719519884",
163
+
"category": "road-bikes",
164
+
"name": "Tronosuros Tire",
165
+
"productId": "68719520766"
166
+
}
167
+
168
+
# for demo, assume that this item already exists in the container.
169
+
# the item id will be used for read operation in the batch
170
+
read_demo_item2 = {
171
+
"id": "68719519886",
172
+
"category": "road-bikes",
173
+
"name": "Tronosuros Tire",
174
+
"productId": "68719520766"
175
+
}
176
+
177
+
# for demo, assume that this item already exists in the container.
178
+
# the item id will be used for read operation in the batch
179
+
read_demo_item3 = {
180
+
"id": "68719519887",
181
+
"category": "road-bikes",
182
+
"name": "Tronosuros Tire",
183
+
"productId": "68719520766"
184
+
}
185
+
186
+
# for demo, we'll upsert the item with id 68719519885
187
+
upsert_demo_item = {
188
+
"id": "68719519885",
189
+
"category": "road-bikes",
190
+
"name": "Tronosuros Tire Upserted",
191
+
"productId": "68719520768"
192
+
}
193
+
194
+
# for replace demo, we'll replace the read_demo_item2 with this item
195
+
replace_demo_item = {
196
+
"id": "68719519886",
197
+
"category": "road-bikes",
198
+
"name": "Tronosuros Tire replaced",
199
+
"productId": "68719520769"
200
+
}
201
+
202
+
# for replace with etag match demo, we'll replace the read_demo_item3 with this item
203
+
# The use of etags and if-match/if-none-match options allows users to run conditional replace operations
204
+
# based on the etag value passed. When using if-match, the request will only succeed if the item's latest etag
205
+
# matches the passed in value. For more on optimistic concurrency control, see the link below:
> **Note for using patch operation and replace_if_match_etag operation in the batch** <br>
259
+
The batch operation kwargs dictionary is limited, and only takes a total of three different key values. In the case of wanting to use conditional patching within the batch, the use of filter_predicate key is available for the patch operation, or in case of wanting to use etags with any of the operations, the use of the if_match_etag/if_none_match_etag keys is available as well.<br>
> If there's a failure, the failed operation will have a status code of its corresponding error. All the other operations will have a 424 status code (failed dependency). If the operation fails because it tries to create an item that already exists, a status code of 409 (conflict) is returned. The status code enables one to identify the cause of transaction failure.
141
270
---
142
271
143
272
## How are transactional batch operations executed
144
273
145
-
When the `ExecuteAsync` method is called, all operations in the `TransactionalBatch` object are grouped, serialized into a single payload, and sent as a single request to the Azure Cosmos DB service.
274
+
When the Transactional Batchisexecuted, all operations in the Transactional Batch are grouped, serialized into a single payload, and sent as a single request to the Azure Cosmos DB service.
146
275
147
276
The service receives the request and executes all operations within a transactional scope, and returns a response using the same serialization protocol. This response is either a success, or a failure, and supplies individual operation responses per operation.
148
277
@@ -152,8 +281,8 @@ The SDK exposes the response for you to verify the result and, optionally, extra
152
281
153
282
Currently, there are two known limits:
154
283
155
-
* The Azure Cosmos DB request size limit constrains the size of the `TransactionalBatch` payload to not exceed 2 MB, and the maximum execution time is 5 seconds.
156
-
* There's a current limit of 100 operations per `TransactionalBatch` to ensure the performance is as expected and within SLAs.
284
+
* The Azure Cosmos DB request size limit constrains the size of the Transactional Batch payload to not exceed 2MB, and the maximum execution time is5 seconds.
285
+
* There's a current limit of 100 operations per Transactional Batch to ensure the performance is as expected and within SLAs.
0 commit comments