Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[state management] Update docs around transactional operations #2372

Merged
merged 5 commits into from
Apr 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion daprdocs/content/en/contributing/codespaces.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,6 @@ git reset --hard
```

## Related links
- [GitHub documentation](https://docs.github.com/en/github/developing-online-with-codespaces/about-codespaces)
<!-- IGNORE_LINKS -->
- [GitHub documentation](https://docs.github.com/github/developing-online-with-codespaces/about-codespaces)
<!-- END_IGNORE -->
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,17 @@ With the HTTP API, you can set content type via URL query parameter `metadata.co

With the gRPC API, you can set content type by adding key/value pair `"contentType" : <content type>` to the request metadata.

### Bulk operations
### Multiple operations

Dapr supports two types of bulk operations: **bulk** or **multi**. You can group several requests of the same type into a bulk (or a batch). Dapr submits requests in bulk operations as individual requests to the underlying data store. In other words, bulk operations are not transactional. On the other hand, you can group requests of different types into a multi-operation, which is then handled as an atomic transaction.
Dapr supports two types of mult-read or multi-write operations: **bulk** or **transactional**. Read the [API reference]({{< ref state_api.md >}}) to learn how use bulk and multi options.

Read the [API reference]({{< ref state_api.md >}}) to learn how use bulk and multi options.
#### Bulk read operations

You can group multiple read requests into a bulk (or batch) operation. In the bulk operation, Dapr submits the read requests as individual requests to the underlying data store, and returns them as a single result.

#### Transactional operations

You can group write, update and delete operations into a request, which are then handled as an atomic transaction. The request will succeed or fail as a transactional set of operations.

### State encryption
Dapr supports automatic client encryption of application state with support for key rotations. This is supported on all Dapr state stores. For more info, read the [How-To: Encrypt application state]({{< ref howto-encrypt-state.md >}}) topic.
Expand Down
22 changes: 15 additions & 7 deletions daprdocs/content/en/reference/api/state_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -443,9 +443,9 @@ POST http://localhost:3500/v1.0-alpha1/state/myStore/query?metadata.partitionKey

## State transactions

Persists the changes to the state store as a multi-item transaction.
Persists the changes to the state store as a [transactional operation]({{< ref "state-management-overview.md#transactional-operations" >}}).

> This operation depends on a state store component that supports multi-item transactions.
> This API depends on a state store component that supports transactions.

Refer to the [state store component spec]({{< ref "supported-state-stores.md" >}}) for a full, current list of state stores that support transactions.

Expand Down Expand Up @@ -481,20 +481,28 @@ POST http://localhost:3500/v1.0/state/myStore/transaction?metadata.contentType=a

Field | Description
---- | -----------
`operations` | A JSON array of state operation
`metadata` | (optional) The metadata for transaction that applies to all operations
`operations` | A JSON array of state `operation`
`metadata` | (optional) The `metadata` for the transaction that applies to all operations

Each state operation is comprised with the following fields:
All transactional databases implement the following required operations:

Field | Description
Operation | Description
--------- | -----------
`upsert` | Adds or updates the value
`delete` | Deletes the value

Each operation has an associated `request` that is comprised of the following fields:

Request | Description
---- | -----------
`key` | State key
`value` | State value, which can be any byte array
`etag` | (optional) State ETag
`metadata` | (optional) Additional key-value pairs to be passed to the state store
`metadata` | (optional) Additional key-value pairs to be passed to the state store that apply for this operation
`options` | (optional) State operation options; see [state operation options](#optional-behaviors)

#### Examples
The example below shows an `upsert` operation for `key1` and a `delete` operation for `key2`. This is applied to the partition named 'planet' in the state store. Both operations either succeed or fail in the transaction.

```shell
curl -X POST http://localhost:3500/v1.0/state/starwars/transaction \
Expand Down