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/database-transactions-optimistic-concurrency.md
+10-9Lines changed: 10 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,19 +1,19 @@
1
1
---
2
2
title: Database transactions and optimistic concurrency control in Azure Cosmos DB
3
3
description: This article describes database transactions and optimistic concurrency control in Azure Cosmos DB
4
-
author: markjbrown
4
+
author: rimman
5
5
ms.service: cosmos-db
6
6
ms.topic: conceptual
7
-
ms.date: 11/14/2018
8
-
ms.author: mjbrown
7
+
ms.date: 04/08/2019
8
+
ms.author: rimman
9
9
ms.reviewer: sngun
10
10
---
11
11
12
12
# Transactions and optimistic concurrency control
13
13
14
-
Database transactions provide a safe and predictable programming model to deal with concurrent changes to the data. Traditional relational databases, like SQL Server allow you to write the business logic using stored-procedures and/or triggers, send it to the server for execution directly within the database engine. With traditional relational databases, you are required to deal with two different programming languages- the (non-transactional) application programming language such as JavaScript, Python, C#, Java, etc. and the transactional programming language (T-SQL) that is natively executed by the database.
14
+
Database transactions provide a safe and predictable programming model to deal with concurrent changes to the data. Traditional relational databases, like SQL Server, allow you to write the business logic using stored-procedures and/or triggers, send it to the server for execution directly within the database engine. With traditional relational databases, you are required to deal with two different programming languages the (non-transactional) application programming language such as JavaScript, Python, C#, Java, etc. and the transactional programming language (such as T-SQL) that is natively executed by the database.
15
15
16
-
The database engine in Azure Cosmos DB supports full ACID (Atomicity, Consistency, Isolation, Durability) compliant transactions with snapshot isolation. All the database operations within the scope of a container's logical partition are transactionally executed within the database engine that is hosted by the replica of the partition. These operations include both write (updating one or more items within the logical partition) and read operations. The following table illustrates different operations and transcation types:
16
+
The database engine in Azure Cosmos DB supports full ACID (Atomicity, Consistency, Isolation, Durability) compliant transactions with snapshot isolation. All the database operations within the scope of a container's [logical partition](partition-data.md) are transactionally executed within the database engine that is hosted by the replica of the partition. These operations include both write (updating one or more items within the logical partition) and read operations. The following table illustrates different operations and transcation types:
17
17
18
18
|**Operation**|**Operation Type**|**Single or Multi Item Transaction**|
19
19
|---------|---------|---------|
@@ -36,21 +36,21 @@ The database engine in Azure Cosmos DB supports full ACID (Atomicity, Consistenc
36
36
37
37
## Multi-item transactions
38
38
39
-
Azure Cosmos DB allows you to write stored procedures, pre/post triggers, user-defined-functions (UDFs) and merge procedures in JavaScript. Azure Cosmos DB natively supports JavaScript execution inside its database engine. You can register stored procedures, pre/post triggers, user-defined-functions (UDFs) and merge procedures on a container and later execute them transactionally within the Azure Cosmos database engine. Writing application logic in JavaScript allows natural expression of control flow, variable scoping, assignment, and integration of exception handling primitives within the database transactions directly in the JavaScript language.
39
+
Azure Cosmos DB allows you to write [stored procedures, pre/post triggers, user-defined-functions (UDFs)](stored-procedures-triggers-udfs.md) and merge procedures in JavaScript. Azure Cosmos DB natively supports JavaScript execution inside its database engine. You can register stored procedures, pre/post triggers, user-defined-functions (UDFs) and merge procedures on a container and later execute them transactionally within the Azure Cosmos database engine. Writing application logic in JavaScript allows natural expression of control flow, variable scoping, assignment, and integration of exception handling primitives within the database transactions directly in the JavaScript language.
40
40
41
41
The JavaScript-based stored procedures, triggers, UDFs, and merge procedures are wrapped within an ambient ACID transaction with snapshot isolation across all items within the logical partition. During the course of its execution, if the JavaScript program throws an exception, the entire transaction is aborted and rolled-back. The resulting programming model is simple yet powerful. JavaScript developers get a durable programming model while still using their familiar language constructs and library primitives.
42
42
43
43
The ability to execute JavaScript directly within the database engine provides performance and transactional execution of database operations against the items of a container. Furthermore, since Azure Cosmos database engine natively supports JSON and JavaScript, there is no impedance mismatch between the type systems of an application and the database.
44
44
45
45
## Optimistic concurrency control
46
46
47
-
Optimistic concurrency control allows you to prevent lost updates and deletes. Concurrent, conflicting operations are subjected to the regular pessimistic locking of the database engine hosted by the logical partition that owns the item. When two concurrent operations attempt to update the latest version of an item within a logical partition, one of them will win and the other will fail. However, if one or two operations attempting to concurrently update the same item had previously read an older value of the item, the database doesn’t know if the previously read value by either or both the conflicting operations was indeed the latest value of the item. Fortunately, this situation can be detected with the Optimistic Concurrency Control (OCC) before letting the two operations enter the transaction boundary inside the database engine. OCC protects your data from accidentally overwriting changes that were made by others. It also prevents others from accidentally overwriting your own changes.
47
+
Optimistic concurrency control allows you to prevent lost updates and deletes. Concurrent, conflicting operations are subjected to the regular pessimistic locking of the database engine hosted by the logical partition that owns the item. When two concurrent operations attempt to update the latest version of an item within a logical partition, one of them will win and the other will fail. However, if one or two operations attempting to concurrently update the same item had previously read an older value of the item, the database doesn’t know if the previously read value by either or both the conflicting operations was indeed the latest value of the item. Fortunately, this situation can be detected with the **Optimistic Concurrency Control (OCC)** before letting the two operations enter the transaction boundary inside the database engine. OCC protects your data from accidentally overwriting changes that were made by others. It also prevents others from accidentally overwriting your own changes.
48
48
49
49
The concurrent updates of an item are subjected to the OCC by Azure Cosmos DB’s communication protocol layer. Azure Cosmos database ensures that the client-side version of the item that you are updating (or deleting) is the same as the version of the item in the Azure Cosmos container. This guarantees that your writes are protected from being overwritten accidentally by the writes of others and vice versa. In a multi-user environment, the optimistic concurrency control protects you from accidentally deleting or updating wrong version of an item. As such, items are protected against the infamous “lost update” or “lost delete” problems.
50
50
51
-
Every item stored in an Azure Cosmos container has a system defined `_etag` property. The value of the `_etag` is automatically generated and updated by the server every time the item is updated. `_etag` can be used with the client supplied if-match request header to allow the server to decide whether an item can be conditionally updated. The value of the if-match header matches the value of the `_etag` at the server, the item is then updated. If the value of the if-match request header is no longer current, the server rejects the operation with an "HTTP 412 Precondition failure" response message. The client then can refetch the item to acquire the current version of the item on the server or override the version of item in the server with its own `_etag` value for the item. In addition, `_etag` can be used with the if-none-match header to determine whether a refetch of a resource is needed.
51
+
Every item stored in an Azure Cosmos container has a system defined `_etag` property. The value of the `_etag` is automatically generated and updated by the server every time the item is updated. `_etag` can be used with the client supplied `if-match` request header to allow the server to decide whether an item can be conditionally updated. The value of the `if-match` header matches the value of the `_etag` at the server, the item is then updated. If the value of the `if-match` request header is no longer current, the server rejects the operation with an "HTTP 412 Precondition failure" response message. The client then can re-fetch the item to acquire the current version of the item on the server or override the version of item in the server with its own `_etag` value for the item. In addition, `_etag` can be used with the `if-none-match` header to determine whether a refetch of a resource is needed.
52
52
53
-
The item’s _etag value changes every time the item is updated. For replace item operations, if-match must be explicitly expressed as a part of the request options. For an example, see the sample code in [GitHub](https://github.com/Azure/azure-documentdb-dotnet/blob/master/samples/code-samples/DocumentManagement/Program.cs#L398-L446). `_etag` values are implicitly checked for all written items touched by a stored procedure. If any conflict is detected, the stored procedure will roll back the transaction and throws an exception. With this method, either all or no writes within the stored procedure are applied atomically. This is a signal to the application to reapply updates and retry the original client request.
53
+
The item’s `_etag` value changes every time the item is updated. For replace item operations, `if-match` must be explicitly expressed as a part of the request options. For an example, see the sample code in [GitHub](https://github.com/Azure/azure-documentdb-dotnet/blob/master/samples/code-samples/DocumentManagement/Program.cs#L398-L446). `_etag` values are implicitly checked for all written items touched by the stored procedure. If any conflict is detected, the stored procedure will roll back the transaction and throw an exception. With this method, either all or no writes within the stored procedure are applied atomically. This is a signal to the application to reapply updates and retry the original client request.
54
54
55
55
## Next steps
56
56
@@ -59,3 +59,4 @@ Learn more about database transactions and optimistic concurrency control in the
59
59
-[Working with Azure Cosmos databases, containers and items](databases-containers-items.md)
60
60
-[Consistency levels](consistency-levels.md)
61
61
-[Conflict types and resolution policies](conflict-resolution-policies.md)
62
+
-[Stored procedures, triggers, and user-defined functions](stored-procedures-triggers-udfs.md)
Copy file name to clipboardExpand all lines: articles/cosmos-db/how-to-manage-database-account.md
+24-19Lines changed: 24 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,16 +1,16 @@
1
1
---
2
2
title: Learn how to manage database accounts in Azure Cosmos DB
3
3
description: Learn how to manage database accounts in Azure Cosmos DB
4
-
author: christopheranderson
4
+
author: rimman
5
5
ms.service: cosmos-db
6
6
ms.topic: sample
7
-
ms.date: 10/17/2018
8
-
ms.author: chrande
7
+
ms.date: 04/08/2019
8
+
ms.author: rimman
9
9
---
10
10
11
11
# Manage an Azure Cosmos account
12
12
13
-
This article describes how to manage your Azure Cosmos DB account. You learn how to set up multi-homing, add or remove a region, configure multiple write regions, and set up failover priorities.
13
+
This article describes how to manage your Azure Cosmos account. You will learn how to set up multi-homing, add or remove a region, configure multiple write regions, and set up failover priorities.
1. Go to your Azure Cosmos DB account, and open the **Replicate data globally** menu.
97
+
1. Go to your Azure Cosmos account, and open the **Replicate data globally** menu.
98
98
99
-
2. To add regions, select the hexagons on the map with the **+** label that correspond to your desired region. To add a region, select the **+ Add region** option and choose a region from the drop-down menu.
99
+
2. To add regions, select the hexagons on the map with the **+** label that correspond to your desired region(s). Alternatively, to add a region, select the **+ Add region** option and choose a region from the drop-down menu.
100
100
101
101
3. To remove regions, clear one or more regions from the map by selecting the blue hexagons with check marks. Or select the "wastebasket" (🗑) icon next to the region on the right side.
102
102
103
103
4. To save your changes, select **OK**.
104
104
105
105

106
106
107
-
In single-region write mode, you can't remove the write region. You must fail over to a different region before you can delete that current write region.
107
+
In a single-region write mode, you cannot remove the write region. You must fail over to a different region before you can delete the current write region.
108
108
109
-
In multi-region write mode, you can add or remove any region if you have at least one region.
109
+
In a multi-region write mode, you can add or remove any region, if you have at least one region.
The following JSON code is an example of an Azure Resource Manager template. You can use it to deploy an Azure Cosmos DB account with a consistency policy of bounded staleness. The maximum staleness interval is set at 5 seconds. The maximum number of stale requests that's tolerated is set at 100. To learn about the Resource Manager template format and syntax, see [Resource Manager](../azure-resource-manager/resource-group-authoring-templates.md).
140
+
The following JSON code is an example of an [Azure Resource Manager](https://docs.microsoft.com/azure/azure-resource-manager/resource-group-overview) template. You can use it to deploy an Azure Cosmos account with [bounded staleness consistency level](consistency-levels.md). The maximum staleness interval is set to 5 seconds. The maximum number of stale requests that is tolerated is set to 100. To learn about the Resource Manager template format and syntax, see [Resource Manager](../azure-resource-manager/resource-group-authoring-templates.md).
141
141
142
142
```json
143
143
{
@@ -192,11 +192,11 @@ The following JSON code is an example of an Azure Resource Manager template. You
192
192
```
193
193
194
194
195
-
## <aid="manual-failover"></a>Enable manual failover for your Azure Cosmos DB account
195
+
## <aid="manual-failover"></a>Enable manual failover for your Azure Cosmos account
0 commit comments