Skip to content

Commit 8840a1f

Browse files
committed
docs: update README and latency guide
1 parent 10328da commit 8840a1f

File tree

3 files changed

+35
-8
lines changed

3 files changed

+35
-8
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ See [Supported Connection Properties](documentation/connection_properties.md) fo
109109
supported connection properties.
110110

111111
#### Commonly Used Properties
112+
- default_isolation_level (String): Spanner supports isolation levels REPEATABLE_READ or SERIALIZABLE. SERIALIZABLE is the default. Using isolation level REPEATABLE_READ improves performance by reducing the amount of locks that are taken by transactions that execute a large number of queries in read/write transactions. REPEATABLE_READ is recommended for applications that are ported from other relational databases that use REPEATABLE_READ or lower isolation levels by default.
112113
- credentials (String): URL for the credentials file to use for the connection. If you do not specify any credentials at all, the default credentials of the environment as returned by `GoogleCredentials#getApplicationDefault()` is used. Example: `jdbc:cloudspanner:/projects/my-project/instances/my-instance/databases/my-db;credentials=/path/to/credentials.json`
113114
- autocommit (boolean): Sets the initial autocommit mode for the connection. Default is true.
114115
- readonly (boolean): Sets the initial readonly mode for the connection. Default is false.

documentation/latency-debugging-guide.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,40 @@ queries and transactions and to determine whether transactions or requests are b
55
addition, all metrics described in [Latency points in a Spanner request](https://cloud.google.com/spanner/docs/latency-points)
66
are also collected by the JDBC driver and can be used for debugging.
77

8+
## Isolation Level
9+
10+
A common reason for high latency in read/write transactions is lock contention. Spanner by default
11+
uses isolation level `SERIALIZABLE`. This causes all queries in read/write transactions to take
12+
locks for all rows that are scanned by a query. Using isolation level `REPEATABLE_READ` reduces the
13+
number of locks that are taken during a read/write transaction, and can significantly improve
14+
performance for applications that execute many and/or large queries in read/write transactions.
15+
16+
Enable isolation level `REPEATABLE_READ` by default for all transactions that are executed by the
17+
JDBC driver by setting the `default_isolation_level` connection property like this in the connection
18+
URL:
19+
20+
```java
21+
String projectId = "my-project";
22+
String instanceId = "my-instance";
23+
String databaseId = "my-database";
24+
String isolationLevel = "REPEATABLE_READ";
25+
26+
try (Connection connection =
27+
DriverManager.getConnection(
28+
String.format(
29+
"jdbc:cloudspanner:/projects/%s/instances/%s/databases/%s?default_isolation_level=%s",
30+
projectId, instanceId, databaseId, isolationLevel))) {
31+
try (Statement statement = connection.createStatement()) {
32+
try (ResultSet rs = statement.executeQuery("SELECT CURRENT_TIMESTAMP()")) {
33+
while (rs.next()) {
34+
System.out.printf(
35+
"Connected to Cloud Spanner at [%s]%n", rs.getTimestamp(1).toString());
36+
}
37+
}
38+
}
39+
}
40+
```
41+
842
## Configuration
943

1044
You can configure the OpenTelemetry instance that should be used in two ways:

samples/snippets/pom.xml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,6 @@
2323
<!-- [START spanner-jdbc_install_with_bom] -->
2424
<dependencyManagement>
2525
<dependencies>
26-
<dependency>
27-
<groupId>com.google.cloud</groupId>
28-
<artifactId>google-cloud-spanner-bom</artifactId>
29-
<version>6.91.1</version>
30-
<type>pom</type>
31-
<scope>import</scope>
32-
</dependency>
3326
<dependency>
3427
<groupId>com.google.cloud</groupId>
3528
<artifactId>libraries-bom</artifactId>
@@ -44,7 +37,6 @@
4437
<dependency>
4538
<groupId>com.google.cloud</groupId>
4639
<artifactId>google-cloud-spanner-jdbc</artifactId>
47-
<version>2.29.1</version>
4840
<exclusions>
4941
<exclusion>
5042
<groupId>com.google.api.grpc</groupId>

0 commit comments

Comments
 (0)