Skip to content

Commit 72aa0c8

Browse files
committed
Merge branch 'main' into replace-exec-options-with-connection-variables
2 parents d7b55fc + 8c61fd6 commit 72aa0c8

File tree

3 files changed

+26
-11
lines changed

3 files changed

+26
-11
lines changed

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,10 @@ tx.QueryContext(ctx, "SELECT SingerId, Name FROM Singers WHERE SingerId = ?", 12
103103

104104
## Transactions
105105

106-
- Read-write transactions always uses the strongest isolation level and ignore the user-specified level.
106+
- Read-write transactions support isolation levels `Serializable`, `Snapshot` and `RepeatableRead`.
107107
- Read-only transactions do strong-reads by default. Read-only transactions must be ended by calling
108108
either Commit or Rollback. Calling either of these methods will end the current read-only
109-
transaction and return the session that is used to the session pool.
109+
transaction.
110110

111111
```go
112112
tx, err := db.BeginTx(ctx, &sql.TxOptions{}) // Read-write transaction.
@@ -226,6 +226,11 @@ $ gcloud beta emulators spanner start
226226
$ export SPANNER_EMULATOR_HOST=localhost:9010
227227
```
228228

229+
### Automatically Create Instance and Database on the Emulator
230+
You can also add the `autoConfigEmulator=true` option to the connection string. This will instruct the driver
231+
to connect to the Spanner emulator, and to automatically create the Spanner instance and database on the
232+
emulator. See [examples/emulator](examples/emulator) for a working example.
233+
229234
## Spanner PostgreSQL Interface
230235

231236
This driver works with both Spanner GoogleSQL and PostgreSQL dialects.

driver.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ var noopLogger = slog.New(slog.NewTextHandler(io.Discard, &slog.HandlerOptions{L
8686
// The default is false
8787
// - enableEndToEndTracing: Boolean that indicates if end-to-end tracing is enabled
8888
// The default is false
89-
// - minSessions: The minimum number of sessions in the backing session pool. The default is 100.
90-
// - maxSessions: The maximum number of sessions in the backing session pool. The default is 400.
89+
// - minSessions (DEPRECATED): The minimum number of sessions in the backing session pool. The default is 100. This option is deprecated, as the driver by default uses a single multiplexed session for all operations.
90+
// - maxSessions (DEPRECATED): The maximum number of sessions in the backing session pool. The default is 400. This option is deprecated, as the driver by default uses a single multiplexed session for all operations.
9191
// - numChannels: The number of gRPC channels to use to communicate with Cloud Spanner. The default is 4.
9292
// - optimizerVersion: Sets the default query optimizer version to use for this connection.
9393
// - optimizerStatisticsPackage: Sets the default query optimizer statistic package to use for this connection.

driver_with_mockserver_test.go

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3444,7 +3444,8 @@ func TestMaxSessions(t *testing.T) {
34443444
}
34453445

34463446
func TestClientReuse(t *testing.T) {
3447-
t.Parallel()
3447+
// MinSessions only has an effect if we are not using multiplexed sessions.
3448+
t.Setenv("GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS", "false")
34483449

34493450
ctx := context.Background()
34503451
db, server, teardown := setupTestDBConnectionWithParams(t, "minSessions=2")
@@ -3502,7 +3503,8 @@ func TestClientReuse(t *testing.T) {
35023503
}
35033504

35043505
func TestStressClientReuse(t *testing.T) {
3505-
t.Parallel()
3506+
// MinSessions only has an effect if we are not using multiplexed sessions.
3507+
t.Setenv("GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS", "false")
35063508

35073509
ctx := context.Background()
35083510
_, server, teardown := setupTestDBConnection(t)
@@ -4288,7 +4290,8 @@ func TestTag_RunTransactionWithOptions_IsNotSticky(t *testing.T) {
42884290
}
42894291

42904292
func TestMaxIdleConnectionsNonZero(t *testing.T) {
4291-
t.Parallel()
4293+
// MinSessions only has an effect if we are not using multiplexed sessions.
4294+
t.Setenv("GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS", "false")
42924295

42934296
// Set MinSessions=1, so we can use the number of BatchCreateSessions requests as an indication
42944297
// of the number of clients that was created.
@@ -4310,7 +4313,8 @@ func TestMaxIdleConnectionsNonZero(t *testing.T) {
43104313
}
43114314

43124315
func TestMaxIdleConnectionsZero(t *testing.T) {
4313-
t.Parallel()
4316+
// MinSessions only has an effect if we are not using multiplexed sessions.
4317+
t.Setenv("GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS", "false")
43144318

43154319
// Set MinSessions=1, so we can use the number of BatchCreateSessions requests as an indication
43164320
// of the number of clients that was created.
@@ -4356,9 +4360,16 @@ func openAndCloseConn(t *testing.T, db *sql.DB) {
43564360
func TestCannotReuseClosedConnector(t *testing.T) {
43574361
// Note: This test cannot be parallel, as it inspects the size of the shared
43584362
// map of connectors in the driver. There is no guarantee how many connectors
4359-
// will be open when the test is running, if there are also other tests running
4363+
// will be open when the test is running, if there are other tests running
43604364
// in parallel.
43614365

4366+
// Make sure we start with an empty list of connectors. This cleans up connectors
4367+
// that other tests might have created, but not cleaned up.
4368+
connectors := spannerDriver.connectors
4369+
for _, connector := range connectors {
4370+
_ = connector.Close()
4371+
}
4372+
43624373
db, _, teardown := setupTestDBConnection(t)
43634374
defer teardown()
43644375

@@ -4368,9 +4379,8 @@ func TestCannotReuseClosedConnector(t *testing.T) {
43684379
t.Fatalf("failed to get a connection: %v", err)
43694380
}
43704381
_ = conn.Close()
4371-
connectors := db.Driver().(*Driver).connectors
43724382
if g, w := len(connectors), 1; g != w {
4373-
t.Fatal("underlying connector has not been created")
4383+
t.Fatalf("underlying connector count mismatch\n Got: %v\nWant: %v", g, w)
43744384
}
43754385
var connector *connector
43764386
for _, v := range connectors {

0 commit comments

Comments
 (0)