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

Disambiguate different types of contention. #12494

Merged
11 commits merged into from
Jan 20, 2022
2 changes: 1 addition & 1 deletion _includes/v21.2/performance/statement-contention.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ Find the transactions and statements within the transactions that are experienci
> SELECT * FROM movr.crdb_internal.cluster_contended_tables;
~~~

After identifying the transactions or statements that are experiencing contention, follow the steps in [Understanding and avoiding transaction contention](performance-best-practices-overview.html#understanding-and-avoiding-transaction-contention).
After you identify the transactions or statements that are causing contention, follow the steps in the next section [to avoid contention](performance-best-practices-overview.html#avoid-transaction-contention).
2 changes: 1 addition & 1 deletion v21.2/advanced-client-side-transaction-retries.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ If you are an application developer who needs to implement an application-level

## Overview

To improve the performance of transactions that fail due to [contention](performance-best-practices-overview.html#understanding-and-avoiding-transaction-contention), CockroachDB includes a set of statements (listed below) that let you retry those transactions. Retrying transactions using these statements has the following benefits:
To improve the performance of transactions that fail due to [contention](performance-best-practices-overview.html#transaction-contention), CockroachDB includes a set of statements (listed below) that let you retry those transactions. Retrying transactions using these statements has the following benefits:

1. When you use savepoints, you "hold your place in line" between attempts. Without savepoints, you're starting from scratch every time.
2. Transactions increase their priority each time they're retried, increasing the likelihood they will succeed. This has a lesser effect than #1.
Expand Down
2 changes: 1 addition & 1 deletion v21.2/architecture/admission-control.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Admission control should be used when overall cluster health is good but some no

When admission control is enabled, request and response operations get sorted into work queues where the operations are organized by priority and transaction start time.

Higher priority operations are processed first. The criteria for determining higher and lower priority operations is different at each processing layer, and is determined by the CPU and storage I/O of the operation. Write operations in the [KV storage layer](storage-layer.html) in particular are often the cause of performance bottlenecks, and enabling admission control prevents [the Pebble storage engine](../cockroach-start.html#storage-engine) from experiencing high read amplification. Critical cluster operations like node heartbeats are processed as high priority, as are transactions that hold locks in order to avoid [contention](../performance-recipes.html#contention) by releasing locks.
Higher priority operations are processed first. The criteria for determining higher and lower priority operations is different at each processing layer, and is determined by the CPU and storage I/O of the operation. Write operations in the [KV storage layer](storage-layer.html) in particular are often the cause of performance bottlenecks, and enabling admission control prevents [the Pebble storage engine](../cockroach-start.html#storage-engine) from experiencing high read amplification. Critical cluster operations like node heartbeats are processed as high priority, as are transactions that hold locks in order to avoid [contention](../performance-recipes.html#transaction-contention) by releasing locks.

The transaction start time is used within the priority queue and gives preference to operations with earlier transaction start times. For example, within the high priority queue operations with an earlier transaction start time are processed first.

Expand Down
4 changes: 2 additions & 2 deletions v21.2/architecture/transaction-layer.md
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ The transaction coordinator is able to do this while maintaining correctness gua
For an example showing how the Parallel Commits feature works in more detail, see [Parallel Commits - step by step](#parallel-commits-step-by-step).

{{site.data.alerts.callout_info}}
The latency until intents are resolved is unchanged by the introduction of Parallel Commits: two rounds of consensus are still required to resolve intents. This means that [contended workloads](../performance-best-practices-overview.html#understanding-and-avoiding-transaction-contention) are expected to profit less from this feature.
The latency until intents are resolved is unchanged by the introduction of Parallel Commits: two rounds of consensus are still required to resolve intents. This means that [contended workloads](../performance-best-practices-overview.html#transaction-contention) are expected to profit less from this feature.
{{site.data.alerts.end}}

#### Parallel Commits - step by step
Expand Down Expand Up @@ -396,7 +396,7 @@ Additionally, when other transactions encounter a transaction in `STAGING` state
The non-blocking transaction protocol and replication scheme differ from standard read-write transactions as follows:

- Non-blocking transactions use a replication scheme over the [ranges](overview.html#terms) they operate on that allows all followers in these ranges to serve consistent (non-stale) reads.
- Non-blocking transactions are minimally disruptive to reads over the data they modify, even in the presence of read/write [contention](../performance-best-practices-overview.html#understanding-and-avoiding-transaction-contention).
- Non-blocking transactions are minimally disruptive to reads over the data they modify, even in the presence of read/write [contention](../performance-best-practices-overview.html#transaction-contention).

These properties of non-blocking transactions combine to provide predictable read latency for a configurable subset of data in [global deployments](../multiregion-overview.html). This is useful since there exists a sizable class of data which is heavily skewed towards read traffic.

Expand Down
2 changes: 1 addition & 1 deletion v21.2/build-a-spring-app-with-cockroachdb-jdbc.md
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ On verifying that the transaction is active (using `TransactionSynchronizationMa

#### Transaction retries

Transactions may require retries if they experience deadlock or [transaction contention](performance-best-practices-overview.html#understanding-and-avoiding-transaction-contention) that cannot be resolved without allowing [serialization](demo-serializable.html) anomalies. To handle transactions that are aborted due to transient serialization errors, we highly recommend writing [client-side transaction retry logic](transactions.html#client-side-intervention) into applications written on CockroachDB.
Transactions may require retries if they experience deadlock or [transaction contention](performance-best-practices-overview.html#transaction-contention) that cannot be resolved without allowing [serialization](demo-serializable.html) anomalies. To handle transactions that are aborted due to transient serialization errors, we highly recommend writing [client-side transaction retry logic](transactions.html#client-side-intervention) into applications written on CockroachDB.

In this application, transaction retry logic is written into the methods of the `RetryableTransactionAspect` class. This class is declared an aspect with the `@Aspect` annotation. The `@Order` annotation on this aspect class is passed `Ordered.LOWEST_PRECEDENCE-2`, a level of precedence above the primary transaction advisor. This indicates that the transaction retry advisor must run outside the context of a transaction. Here are the contents of [`RetryableTransactionAspect.java`](https://github.com/cockroachlabs/roach-data/blob/master/roach-data-jdbc/src/main/java/io/roach/data/jdbc/RetryableTransactionAspect.java):

Expand Down
2 changes: 1 addition & 1 deletion v21.2/build-a-spring-app-with-cockroachdb-jpa.md
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ For more details about advice ordering, see [Advice Ordering](https://docs.sprin

#### Transaction retries

Transactions may require retries if they experience deadlock or [transaction contention](performance-best-practices-overview.html#understanding-and-avoiding-transaction-contention) that cannot be resolved without allowing [serialization](demo-serializable.html) anomalies. To handle transactions that are aborted due to transient serialization errors, we highly recommend writing [client-side transaction retry logic](transactions.html#client-side-intervention) into applications written on CockroachDB.
Transactions may require retries if they experience deadlock or [transaction contention](performance-best-practices-overview.html#transaction-contention) that cannot be resolved without allowing [serialization](demo-serializable.html) anomalies. To handle transactions that are aborted due to transient serialization errors, we highly recommend writing [client-side transaction retry logic](transactions.html#client-side-intervention) into applications written on CockroachDB.

In this application, transaction retry logic is written into the methods of the `RetryableTransactionAspect` class, declared an aspect with the `@Aspect` annotation. Here are the contents of [`RetryableTransactionAspect.java`](https://github.com/cockroachlabs/roach-data/blob/master/roach-data-jpa/src/main/java/io/roach/data/jpa/RetryableTransactionAspect.java):

Expand Down
2 changes: 1 addition & 1 deletion v21.2/build-a-spring-app-with-cockroachdb-mybatis.md
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ Instances of the `BatchResults` class, defined in `src/main/java/com/example/coc

MyBatis-Spring supports Spring's [declarative, aspect-oriented transaction management syntax](https://docs.spring.io/spring/docs/current/spring-framework-reference/data-access.html#transaction-declarative), including the [`@Transactional`](https://docs.spring.io/spring/docs/current/spring-framework-reference/data-access.html#transaction-declarative-annotations) annotation and [AspectJ's AOP annotations](https://docs.spring.io/spring/docs/current/spring-framework-reference/data-access.html#transaction-declarative-aspectj).

Transactions may require retries if they experience deadlock or [transaction contention](performance-best-practices-overview.html#understanding-and-avoiding-transaction-contention) that cannot be resolved without allowing [serialization](demo-serializable.html) anomalies. To handle transactions that are aborted due to transient serialization errors, we highly recommend writing [client-side transaction retry logic](transactions.html#client-side-intervention) into applications written on CockroachDB. In this application, transaction retry logic is written into the methods of the `RetryableTransactionAspect` class, defined in `src/main/java/com/example/cockroachdemo/RetryableTransactionAspect.java`:
Transactions may require retries if they experience deadlock or [transaction contention](performance-best-practices-overview.html#transaction-contention) that cannot be resolved without allowing [serialization](demo-serializable.html) anomalies. To handle transactions that are aborted due to transient serialization errors, we highly recommend writing [client-side transaction retry logic](transactions.html#client-side-intervention) into applications written on CockroachDB. In this application, transaction retry logic is written into the methods of the `RetryableTransactionAspect` class, defined in `src/main/java/com/example/cockroachdemo/RetryableTransactionAspect.java`:

{% include_cached copy-clipboard.html %}
~~~ java
Expand Down
8 changes: 4 additions & 4 deletions v21.2/crdb-internal.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ Table | Description
`active_range_feeds` | Contains information about [range feeds](architecture/distribution-layer.html) on nodes in your cluster.
`backward_dependencies` | Contains information about backward dependencies.
`builtin_functions` | Contains information about supported [functions](functions-and-operators.html).
`cluster_contended_indexes` | Contains information about [contended](performance-best-practices-overview.html#understanding-and-avoiding-transaction-contention) indexes in your cluster.
`cluster_contended_keys` | Contains information about [contended](performance-best-practices-overview.html#understanding-and-avoiding-transaction-contention) keys in your cluster.
`cluster_contended_tables` | Contains information about [contended](performance-best-practices-overview.html#understanding-and-avoiding-transaction-contention) tables in your cluster.
`cluster_contention_events` | Contains information about [contention](performance-best-practices-overview.html#understanding-and-avoiding-transaction-contention) in your cluster.
`cluster_contended_indexes` | Contains information about [contended](performance-best-practices-overview.html#transaction-contention) indexes in your cluster.
`cluster_contended_keys` | Contains information about [contended](performance-best-practices-overview.html#transaction-contention) keys in your cluster.
`cluster_contended_tables` | Contains information about [contended](performance-best-practices-overview.html#transaction-contention) tables in your cluster.
`cluster_contention_events` | Contains information about [contention](performance-best-practices-overview.html#transaction-contention) in your cluster.
`cluster_database_privileges` | Contains information about the [database privileges](authorization.html#privileges) on your cluster.
`cluster_distsql_flows` | Contains information about the flows of the [DistSQL execution](architecture/sql-layer.html#distsql) scheduled in your cluster.
`cluster_inflight_traces` | Contains information about in-flight [tracing](show-trace.html) in your cluster.
Expand Down
2 changes: 1 addition & 1 deletion v21.2/delete-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ Reference information related to this task:
- [Disk space usage after deletes](delete.html#disk-space-usage-after-deletes)
- [`TRUNCATE`](truncate.html)
- [`DROP TABLE`](drop-table.html)
- [Understanding and Avoiding Transaction Contention](performance-best-practices-overview.html#understanding-and-avoiding-transaction-contention)
- [Transaction Contention](performance-best-practices-overview.html#transaction-contention)

Other common tasks:

Expand Down
2 changes: 1 addition & 1 deletion v21.2/developer-guide-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Managing transactions is an important part of CockroachDB application developmen

CockroachDB guarantees [`SERIALIZABLE`](https://en.wikipedia.org/wiki/Serializability) transaction [isolation](https://en.wikipedia.org/wiki/Isolation_(database_systems)) (the "I" of ACID semantics). If transactions are executed concurrently, the final state of the database will appear as if the transactions were executed serially. `SERIALIZABLE` isolation, the strictest level of isolation, provides the highest level of data consistency and protects against concurrency-based attacks and bugs.

To guarantee `SERIALIZABLE` isolation, CockroachDB locks the data targeted by an open transaction. If a separate transaction attempts to modify data that are locked by an open transaction, the newest transaction will not succeed, as committing it could result in a violation of the `SERIALIZABLE` isolation level. This scenario is called *transaction contention*, and should be avoided when possible. For a more detailed explanation of transaction contention, and tips on how to avoid it, see [Understand and Avoid Transaction Contention](performance-best-practices-overview.html#understanding-and-avoiding-transaction-contention).
To guarantee `SERIALIZABLE` isolation, CockroachDB locks the data targeted by an open transaction. If a separate transaction attempts to modify data that are locked by an open transaction, the newest transaction will not succeed, as committing it could result in a violation of the `SERIALIZABLE` isolation level. This scenario is called *transaction contention*, and should be avoided when possible. For a more detailed explanation of transaction contention, and tips on how to avoid it, see [Understand and Avoid Transaction Contention](performance-best-practices-overview.html#transaction-contention).

#### Transaction retries

Expand Down
6 changes: 3 additions & 3 deletions v21.2/error-handling-and-troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ If you aren't sure whether SQL query performance needs to be improved on your cl

## Transaction retry errors

Messages with the Postgres error code `40001` indicate that a transaction failed because it [conflicted with another concurrent or recent transaction accessing the same data](performance-best-practices-overview.html#understanding-and-avoiding-transaction-contention). The transaction needs to be retried by the client.
Messages with the Postgres error code `40001` indicate that a transaction failed because it [conflicted with another concurrent or recent transaction accessing the same data](performance-best-practices-overview.html#transaction-contention). The transaction needs to be retried by the client.

If your language's client driver or ORM implements transaction retry logic internally (e.g., if you are using Python and [SQLAlchemy with the CockroachDB dialect](build-a-python-app-with-cockroachdb-sqlalchemy.html)), then you do not need to handle this logic from your application.

Expand All @@ -33,7 +33,7 @@ If your driver or ORM does not implement this logic, then you will need to imple
{% include {{page.version.version}}/misc/client-side-intervention-example.md %}

{{site.data.alerts.callout_info}}
If a consistently high percentage of your transactions are resulting in transaction retry errors, then you may need to evaluate your schema design and data access patterns to find and remove sources of contention. For more information about contention, see [Understanding and Avoiding Transaction Contention](performance-best-practices-overview.html#understanding-and-avoiding-transaction-contention).
If a consistently high percentage of your transactions are resulting in transaction retry errors, then you may need to evaluate your schema design and data access patterns to find and remove sources of contention. For more information about contention, see [Transaction Contention](performance-best-practices-overview.html#transaction-contention).

For more information about what is causing a specific transaction retry error code, see the [Transaction Retry Error Reference](transaction-retry-error-reference.html).
{{site.data.alerts.end}}
Expand Down Expand Up @@ -77,7 +77,7 @@ Reference information related to this page:
- [Common errors](common-errors.html)
- [Transactions](transactions.html)
- [Transaction retries](transactions.html#client-side-intervention)
- [Understanding and Avoiding Transaction Contention](performance-best-practices-overview.html#understanding-and-avoiding-transaction-contention)
- [Transaction Contention](performance-best-practices-overview.html#transaction-contention)
- [SQL Layer][sql]

Other common tasks:
Expand Down
2 changes: 1 addition & 1 deletion v21.2/flyway.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ When used with most databases, [Flyway wraps the statements in a migration withi

### Transaction retries

When multiple, concurrent transactions or statements are issued to a single CockroachDB cluster, [transaction contention](performance-best-practices-overview.html#understanding-and-avoiding-transaction-contention) can cause schema migrations to fail. In the event of transaction contention, CockroachDB returns a `40001 SQLSTATE` (i.e., a serialization failure), and Flyway automatically retries the migration. For more information about client-side transaction retries in CockroachDB, see [Transaction Retries](transactions.html#transaction-retries).
When multiple, concurrent transactions or statements are issued to a single CockroachDB cluster, [transaction contention](performance-best-practices-overview.html#transaction-contention) can cause schema migrations to fail. In the event of transaction contention, CockroachDB returns a `40001 SQLSTATE` (i.e., a serialization failure), and Flyway automatically retries the migration. For more information about client-side transaction retries in CockroachDB, see [Transaction Retries](transactions.html#transaction-retries).

### Transactional schema changes

Expand Down
2 changes: 1 addition & 1 deletion v21.2/insert-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ Reference information related to this task:
- [Import performance](import.html#performance)
- [`INSERT`](insert.html)
- [`UPSERT`](upsert.html)
- [Understanding and Avoiding Transaction Contention](performance-best-practices-overview.html#understanding-and-avoiding-transaction-contention)
- [Transaction Contention](performance-best-practices-overview.html#transaction-contention)
- [Multi-row DML best practices](performance-best-practices-overview.html#dml-best-practices)
- [Insert Multiple Rows](insert.html#insert-multiple-rows-into-an-existing-table)

Expand Down
Loading