} is resolved.
- */
- SessionReference getMultiplexedSessionInstance() {
- try {
- return currentMultiplexedSessionReference.get().get();
- } catch (InterruptedException e) {
- throw SpannerExceptionFactory.propagateInterrupt(e);
- } catch (ExecutionException e) {
- throw asSpannerException(e.getCause());
- }
+ PooledSessionFutureWrapper getMultiplexedSessionWithFallback() throws SpannerException {
+ return new PooledSessionFutureWrapper(getSession());
}
/**
@@ -3271,14 +2703,12 @@ private PooledSessionFuture checkoutSession(
return res;
}
- private void incrementNumSessionsInUse(boolean isMultiplexed) {
+ private void incrementNumSessionsInUse() {
synchronized (lock) {
- if (!isMultiplexed) {
- if (maxSessionsInUse < ++numSessionsInUse) {
- maxSessionsInUse = numSessionsInUse;
- }
- numSessionsAcquired++;
+ if (maxSessionsInUse < ++numSessionsInUse) {
+ maxSessionsInUse = numSessionsInUse;
}
+ numSessionsAcquired++;
}
}
@@ -3496,7 +2926,7 @@ static boolean isUnbalanced(
private void handleCreateSessionsFailure(SpannerException e, int count) {
synchronized (lock) {
for (int i = 0; i < count; i++) {
- if (waiters.size() > 0) {
+ if (!waiters.isEmpty()) {
waiters.poll().put(e);
} else {
break;
@@ -3638,20 +3068,6 @@ private boolean canCreateSession() {
}
}
- private void maybeCreateMultiplexedSession(SessionConsumer sessionConsumer) {
- synchronized (lock) {
- if (!multiplexedSessionBeingCreated) {
- logger.log(Level.FINE, String.format("Creating multiplexed sessions"));
- try {
- multiplexedSessionBeingCreated = true;
- sessionClient.asyncCreateMultiplexedSession(sessionConsumer);
- } catch (Throwable ignore) {
- // such an exception will never be thrown. the exception will be passed onto the consumer.
- }
- }
- }
- }
-
private void createSessions(final int sessionCount, boolean distributeOverChannels) {
logger.log(Level.FINE, String.format("Creating %d sessions", sessionCount));
synchronized (lock) {
@@ -3674,99 +3090,6 @@ private void createSessions(final int sessionCount, boolean distributeOverChanne
}
}
- /**
- * Callback interface which is invoked when a multiplexed session is being replaced by the
- * background maintenance thread. When a multiplexed session creation fails during background
- * thread, it would simply log the exception and retry the session creation in the next background
- * thread invocation.
- *
- * This consumer is not used when the multiplexed session is getting initialized for the first
- * time during application startup. We instead use {@link
- * MultiplexedSessionInitializationConsumer} for the first time when multiplexed session is
- * getting created.
- */
- class MultiplexedSessionMaintainerConsumer implements SessionConsumer {
- @Override
- public void onSessionReady(SessionImpl sessionImpl) {
- final SessionReference sessionReference = sessionImpl.getSessionReference();
- final SettableFuture settableFuture = SettableFuture.create();
- settableFuture.set(sessionReference);
-
- synchronized (lock) {
- SessionReference oldSession = null;
- if (currentMultiplexedSessionReference.get().isDone()) {
- oldSession = getMultiplexedSessionInstance();
- }
- SettableApiFuture settableApiFuture = SettableApiFuture.create();
- settableApiFuture.set(sessionReference);
- currentMultiplexedSessionReference.set(settableApiFuture);
- if (oldSession != null) {
- logger.log(
- Level.INFO,
- String.format(
- "Removed Multiplexed Session => %s created at => %s",
- oldSession.getName(), oldSession.getCreateTime()));
- if (multiplexedSessionRemovedListener != null) {
- multiplexedSessionRemovedListener.apply(oldSession);
- }
- }
- multiplexedSessionBeingCreated = false;
- }
- }
-
- /**
- * Method which logs the exception so that session creation can be re-attempted in the next
- * background thread invocation.
- */
- @Override
- public void onSessionCreateFailure(Throwable t, int createFailureForSessionCount) {
- synchronized (lock) {
- multiplexedSessionBeingCreated = false;
- }
- logger.log(
- Level.WARNING,
- String.format(
- "Failed to create multiplexed session. "
- + "Pending replacing stale multiplexed session",
- t));
- }
- }
-
- /**
- * Callback interface which is invoked when a multiplexed session is getting initialised for the
- * first time when a session is getting created.
- */
- class MultiplexedSessionInitializationConsumer implements SessionConsumer {
- @Override
- public void onSessionReady(SessionImpl sessionImpl) {
- final SessionReference sessionReference = sessionImpl.getSessionReference();
- synchronized (lock) {
- SettableApiFuture settableApiFuture =
- currentMultiplexedSessionReference.get();
- settableApiFuture.set(sessionReference);
- multiplexedSessionBeingCreated = false;
- waitOnMultiplexedSessionsLatch.countDown();
- }
- }
-
- /**
- * When a multiplexed session fails during initialization we would like all pending threads to
- * receive the exception and throw the error. This is done because at the time of start up there
- * is no other multiplexed session which could have been assigned to the pending requests.
- */
- @Override
- public void onSessionCreateFailure(Throwable t, int createFailureForSessionCount) {
- synchronized (lock) {
- multiplexedSessionBeingCreated = false;
- if (isDatabaseOrInstanceNotFound(asSpannerException(t))) {
- setResourceNotFoundException((ResourceNotFoundException) t);
- poolMaintainer.close();
- }
- currentMultiplexedSessionReference.get().setException(asSpannerException(t));
- }
- }
- }
-
/**
* {@link SessionConsumer} that receives the created sessions from a {@link SessionClient} and
* releases these into the pool. The session pool only needs one instance of this, as all sessions
diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SessionPoolOptions.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SessionPoolOptions.java
index 2a065c8b2ce..ba2eedbccb8 100644
--- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SessionPoolOptions.java
+++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SessionPoolOptions.java
@@ -569,6 +569,8 @@ private Builder(SessionPoolOptions options) {
this.acquireSessionTimeout = options.acquireSessionTimeout;
this.randomizePositionQPSThreshold = options.randomizePositionQPSThreshold;
this.inactiveTransactionRemovalOptions = options.inactiveTransactionRemovalOptions;
+ this.useMultiplexedSession = options.useMultiplexedSession;
+ this.multiplexedSessionMaintenanceDuration = options.multiplexedSessionMaintenanceDuration;
this.poolMaintainerClock = options.poolMaintainerClock;
}
diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/TransactionRunnerImpl.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/TransactionRunnerImpl.java
index 692a60e97b5..7219389e775 100644
--- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/TransactionRunnerImpl.java
+++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/TransactionRunnerImpl.java
@@ -306,12 +306,23 @@ private void createTxnAsync(final SettableApiFuture res) {
void commit() {
try {
- commitResponse = commitAsync().get();
- } catch (InterruptedException e) {
+ // Normally, Gax will take care of any timeouts, but we add a timeout for getting the value
+ // from the future here as well to make sure the call always finishes, even if the future
+ // never resolves.
+ commitResponse =
+ commitAsync()
+ .get(
+ rpc.getCommitRetrySettings().getTotalTimeout().getSeconds() + 5,
+ TimeUnit.SECONDS);
+ } catch (InterruptedException | TimeoutException e) {
if (commitFuture != null) {
commitFuture.cancel(true);
}
- throw SpannerExceptionFactory.propagateInterrupt(e);
+ if (e instanceof InterruptedException) {
+ throw SpannerExceptionFactory.propagateInterrupt((InterruptedException) e);
+ } else {
+ throw SpannerExceptionFactory.propagateTimeout((TimeoutException) e);
+ }
} catch (ExecutionException e) {
throw SpannerExceptionFactory.newSpannerException(e.getCause() == null ? e : e.getCause());
}
@@ -422,6 +433,14 @@ public void run() {
commitFuture.addListener(
() -> {
try (IScope ignore = tracer.withSpan(opSpan)) {
+ if (!commitFuture.isDone()) {
+ // This should not be possible, considering that we are in a listener for the
+ // future, but we add a result here as well as a safety precaution.
+ res.setException(
+ SpannerExceptionFactory.newSpannerException(
+ ErrorCode.INTERNAL, "commitFuture is not done"));
+ return;
+ }
com.google.spanner.v1.CommitResponse proto = commitFuture.get();
if (!proto.hasCommitTimestamp()) {
throw newSpannerException(
@@ -430,20 +449,28 @@ public void run() {
span.addAnnotation("Commit Done");
opSpan.end();
res.set(new CommitResponse(proto));
- } catch (Throwable e) {
- if (e instanceof ExecutionException) {
- e =
- SpannerExceptionFactory.newSpannerException(
- e.getCause() == null ? e : e.getCause());
- } else if (e instanceof InterruptedException) {
- e = SpannerExceptionFactory.propagateInterrupt((InterruptedException) e);
- } else {
- e = SpannerExceptionFactory.newSpannerException(e);
+ } catch (Throwable throwable) {
+ SpannerException resultException;
+ try {
+ if (throwable instanceof ExecutionException) {
+ resultException =
+ SpannerExceptionFactory.asSpannerException(
+ throwable.getCause() == null ? throwable : throwable.getCause());
+ } else if (throwable instanceof InterruptedException) {
+ resultException =
+ SpannerExceptionFactory.propagateInterrupt(
+ (InterruptedException) throwable);
+ } else {
+ resultException = SpannerExceptionFactory.asSpannerException(throwable);
+ }
+ span.addAnnotation("Commit Failed", resultException);
+ opSpan.setStatus(resultException);
+ opSpan.end();
+ res.setException(onError(resultException, false));
+ } catch (Throwable unexpectedError) {
+ // This is a safety precaution to make sure that a result is always returned.
+ res.setException(unexpectedError);
}
- span.addAnnotation("Commit Failed", e);
- opSpan.setStatus(e);
- opSpan.end();
- res.setException(onError((SpannerException) e, false));
}
},
MoreExecutors.directExecutor());
@@ -451,9 +478,6 @@ public void run() {
res.setException(SpannerExceptionFactory.propagateInterrupt(e));
} catch (TimeoutException e) {
res.setException(SpannerExceptionFactory.propagateTimeout(e));
- } catch (ExecutionException e) {
- res.setException(
- SpannerExceptionFactory.newSpannerException(e.getCause() == null ? e : e.getCause()));
} catch (Throwable e) {
res.setException(
SpannerExceptionFactory.newSpannerException(e.getCause() == null ? e : e.getCause()));
diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/database/v1/DatabaseAdminClient.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/database/v1/DatabaseAdminClient.java
index e518198549b..dd00f6750c7 100644
--- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/database/v1/DatabaseAdminClient.java
+++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/database/v1/DatabaseAdminClient.java
@@ -43,24 +43,31 @@
import com.google.protobuf.Timestamp;
import com.google.spanner.admin.database.v1.Backup;
import com.google.spanner.admin.database.v1.BackupName;
+import com.google.spanner.admin.database.v1.BackupSchedule;
+import com.google.spanner.admin.database.v1.BackupScheduleName;
import com.google.spanner.admin.database.v1.CopyBackupMetadata;
import com.google.spanner.admin.database.v1.CopyBackupRequest;
import com.google.spanner.admin.database.v1.CreateBackupMetadata;
import com.google.spanner.admin.database.v1.CreateBackupRequest;
+import com.google.spanner.admin.database.v1.CreateBackupScheduleRequest;
import com.google.spanner.admin.database.v1.CreateDatabaseMetadata;
import com.google.spanner.admin.database.v1.CreateDatabaseRequest;
import com.google.spanner.admin.database.v1.Database;
import com.google.spanner.admin.database.v1.DatabaseName;
import com.google.spanner.admin.database.v1.DatabaseRole;
import com.google.spanner.admin.database.v1.DeleteBackupRequest;
+import com.google.spanner.admin.database.v1.DeleteBackupScheduleRequest;
import com.google.spanner.admin.database.v1.DropDatabaseRequest;
import com.google.spanner.admin.database.v1.GetBackupRequest;
+import com.google.spanner.admin.database.v1.GetBackupScheduleRequest;
import com.google.spanner.admin.database.v1.GetDatabaseDdlRequest;
import com.google.spanner.admin.database.v1.GetDatabaseDdlResponse;
import com.google.spanner.admin.database.v1.GetDatabaseRequest;
import com.google.spanner.admin.database.v1.InstanceName;
import com.google.spanner.admin.database.v1.ListBackupOperationsRequest;
import com.google.spanner.admin.database.v1.ListBackupOperationsResponse;
+import com.google.spanner.admin.database.v1.ListBackupSchedulesRequest;
+import com.google.spanner.admin.database.v1.ListBackupSchedulesResponse;
import com.google.spanner.admin.database.v1.ListBackupsRequest;
import com.google.spanner.admin.database.v1.ListBackupsResponse;
import com.google.spanner.admin.database.v1.ListDatabaseOperationsRequest;
@@ -72,6 +79,7 @@
import com.google.spanner.admin.database.v1.RestoreDatabaseMetadata;
import com.google.spanner.admin.database.v1.RestoreDatabaseRequest;
import com.google.spanner.admin.database.v1.UpdateBackupRequest;
+import com.google.spanner.admin.database.v1.UpdateBackupScheduleRequest;
import com.google.spanner.admin.database.v1.UpdateDatabaseDdlMetadata;
import com.google.spanner.admin.database.v1.UpdateDatabaseDdlRequest;
import com.google.spanner.admin.database.v1.UpdateDatabaseMetadata;
@@ -515,6 +523,101 @@
*
*
*
+ *
+ * CreateBackupSchedule
+ * Creates a new backup schedule.
+ *
+ * Request object method variants only take one parameter, a request object, which must be constructed before the call.
+ *
+ * "Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.
+ *
+ * createBackupSchedule(DatabaseName parent, BackupSchedule backupSchedule, String backupScheduleId)
+ *
createBackupSchedule(String parent, BackupSchedule backupSchedule, String backupScheduleId)
+ *
+ * Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
+ *
+ *
+ *
+ *
+ * GetBackupSchedule
+ * Gets backup schedule for the input schedule name.
+ *
+ * Request object method variants only take one parameter, a request object, which must be constructed before the call.
+ *
+ * "Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.
+ *
+ * Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
+ *
+ *
+ *
+ *
+ * UpdateBackupSchedule
+ * Updates a backup schedule.
+ *
+ * Request object method variants only take one parameter, a request object, which must be constructed before the call.
+ *
+ * "Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.
+ *
+ * Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
+ *
+ *
+ *
+ *
+ * DeleteBackupSchedule
+ * Deletes a backup schedule.
+ *
+ * Request object method variants only take one parameter, a request object, which must be constructed before the call.
+ *
+ * "Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.
+ *
+ * Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
+ *
+ *
+ *
+ *
+ * ListBackupSchedules
+ * Lists all the backup schedules for the database.
+ *
+ * Request object method variants only take one parameter, a request object, which must be constructed before the call.
+ *
+ * "Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.
+ *
+ * Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
+ *
+ *
+ *
*
*
* See the individual methods for example code.
@@ -4215,62 +4318,707 @@ public final ListDatabaseRolesPagedResponse listDatabaseRoles(ListDatabaseRolesR
return stub.listDatabaseRolesCallable();
}
- @Override
- public final void close() {
- stub.close();
+ // AUTO-GENERATED DOCUMENTATION AND METHOD.
+ /**
+ * Creates a new backup schedule.
+ *
+ *
Sample code:
+ *
+ *
{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * try (DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create()) {
+ * DatabaseName parent = DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]");
+ * BackupSchedule backupSchedule = BackupSchedule.newBuilder().build();
+ * String backupScheduleId = "backupScheduleId1704974708";
+ * BackupSchedule response =
+ * databaseAdminClient.createBackupSchedule(parent, backupSchedule, backupScheduleId);
+ * }
+ * }
+ *
+ * @param parent Required. The name of the database that this backup schedule applies to.
+ * @param backupSchedule Required. The backup schedule to create.
+ * @param backupScheduleId Required. The Id to use for the backup schedule. The
+ * `backup_schedule_id` appended to `parent` forms the full backup schedule name of the form
+ * `projects/<project>/instances/<instance>/databases/<database>/backupSchedules/<backup_schedule_id>`.
+ * @throws com.google.api.gax.rpc.ApiException if the remote call fails
+ */
+ public final BackupSchedule createBackupSchedule(
+ DatabaseName parent, BackupSchedule backupSchedule, String backupScheduleId) {
+ CreateBackupScheduleRequest request =
+ CreateBackupScheduleRequest.newBuilder()
+ .setParent(parent == null ? null : parent.toString())
+ .setBackupSchedule(backupSchedule)
+ .setBackupScheduleId(backupScheduleId)
+ .build();
+ return createBackupSchedule(request);
}
- @Override
- public void shutdown() {
- stub.shutdown();
+ // AUTO-GENERATED DOCUMENTATION AND METHOD.
+ /**
+ * Creates a new backup schedule.
+ *
+ * Sample code:
+ *
+ *
{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * try (DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create()) {
+ * String parent = DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]").toString();
+ * BackupSchedule backupSchedule = BackupSchedule.newBuilder().build();
+ * String backupScheduleId = "backupScheduleId1704974708";
+ * BackupSchedule response =
+ * databaseAdminClient.createBackupSchedule(parent, backupSchedule, backupScheduleId);
+ * }
+ * }
+ *
+ * @param parent Required. The name of the database that this backup schedule applies to.
+ * @param backupSchedule Required. The backup schedule to create.
+ * @param backupScheduleId Required. The Id to use for the backup schedule. The
+ * `backup_schedule_id` appended to `parent` forms the full backup schedule name of the form
+ * `projects/<project>/instances/<instance>/databases/<database>/backupSchedules/<backup_schedule_id>`.
+ * @throws com.google.api.gax.rpc.ApiException if the remote call fails
+ */
+ public final BackupSchedule createBackupSchedule(
+ String parent, BackupSchedule backupSchedule, String backupScheduleId) {
+ CreateBackupScheduleRequest request =
+ CreateBackupScheduleRequest.newBuilder()
+ .setParent(parent)
+ .setBackupSchedule(backupSchedule)
+ .setBackupScheduleId(backupScheduleId)
+ .build();
+ return createBackupSchedule(request);
}
- @Override
- public boolean isShutdown() {
- return stub.isShutdown();
+ // AUTO-GENERATED DOCUMENTATION AND METHOD.
+ /**
+ * Creates a new backup schedule.
+ *
+ * Sample code:
+ *
+ *
{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * try (DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create()) {
+ * CreateBackupScheduleRequest request =
+ * CreateBackupScheduleRequest.newBuilder()
+ * .setParent(DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]").toString())
+ * .setBackupScheduleId("backupScheduleId1704974708")
+ * .setBackupSchedule(BackupSchedule.newBuilder().build())
+ * .build();
+ * BackupSchedule response = databaseAdminClient.createBackupSchedule(request);
+ * }
+ * }
+ *
+ * @param request The request object containing all of the parameters for the API call.
+ * @throws com.google.api.gax.rpc.ApiException if the remote call fails
+ */
+ public final BackupSchedule createBackupSchedule(CreateBackupScheduleRequest request) {
+ return createBackupScheduleCallable().call(request);
}
- @Override
- public boolean isTerminated() {
- return stub.isTerminated();
+ // AUTO-GENERATED DOCUMENTATION AND METHOD.
+ /**
+ * Creates a new backup schedule.
+ *
+ * Sample code:
+ *
+ *
{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * try (DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create()) {
+ * CreateBackupScheduleRequest request =
+ * CreateBackupScheduleRequest.newBuilder()
+ * .setParent(DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]").toString())
+ * .setBackupScheduleId("backupScheduleId1704974708")
+ * .setBackupSchedule(BackupSchedule.newBuilder().build())
+ * .build();
+ * ApiFuture future =
+ * databaseAdminClient.createBackupScheduleCallable().futureCall(request);
+ * // Do something.
+ * BackupSchedule response = future.get();
+ * }
+ * }
+ */
+ public final UnaryCallable
+ createBackupScheduleCallable() {
+ return stub.createBackupScheduleCallable();
}
- @Override
- public void shutdownNow() {
- stub.shutdownNow();
+ // AUTO-GENERATED DOCUMENTATION AND METHOD.
+ /**
+ * Gets backup schedule for the input schedule name.
+ *
+ * Sample code:
+ *
+ *
{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * try (DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create()) {
+ * BackupScheduleName name =
+ * BackupScheduleName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SCHEDULE]");
+ * BackupSchedule response = databaseAdminClient.getBackupSchedule(name);
+ * }
+ * }
+ *
+ * @param name Required. The name of the schedule to retrieve. Values are of the form
+ * `projects/<project>/instances/<instance>/databases/<database>/backupSchedules/<backup_schedule_id>`.
+ * @throws com.google.api.gax.rpc.ApiException if the remote call fails
+ */
+ public final BackupSchedule getBackupSchedule(BackupScheduleName name) {
+ GetBackupScheduleRequest request =
+ GetBackupScheduleRequest.newBuilder()
+ .setName(name == null ? null : name.toString())
+ .build();
+ return getBackupSchedule(request);
}
- @Override
- public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException {
- return stub.awaitTermination(duration, unit);
+ // AUTO-GENERATED DOCUMENTATION AND METHOD.
+ /**
+ * Gets backup schedule for the input schedule name.
+ *
+ * Sample code:
+ *
+ *
{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * try (DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create()) {
+ * String name =
+ * BackupScheduleName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SCHEDULE]").toString();
+ * BackupSchedule response = databaseAdminClient.getBackupSchedule(name);
+ * }
+ * }
+ *
+ * @param name Required. The name of the schedule to retrieve. Values are of the form
+ * `projects/<project>/instances/<instance>/databases/<database>/backupSchedules/<backup_schedule_id>`.
+ * @throws com.google.api.gax.rpc.ApiException if the remote call fails
+ */
+ public final BackupSchedule getBackupSchedule(String name) {
+ GetBackupScheduleRequest request = GetBackupScheduleRequest.newBuilder().setName(name).build();
+ return getBackupSchedule(request);
}
- public static class ListDatabasesPagedResponse
- extends AbstractPagedListResponse<
- ListDatabasesRequest,
- ListDatabasesResponse,
- Database,
- ListDatabasesPage,
- ListDatabasesFixedSizeCollection> {
-
- public static ApiFuture createAsync(
- PageContext context,
- ApiFuture futureResponse) {
- ApiFuture futurePage =
- ListDatabasesPage.createEmptyPage().createPageAsync(context, futureResponse);
- return ApiFutures.transform(
- futurePage,
- input -> new ListDatabasesPagedResponse(input),
- MoreExecutors.directExecutor());
- }
+ // AUTO-GENERATED DOCUMENTATION AND METHOD.
+ /**
+ * Gets backup schedule for the input schedule name.
+ *
+ * Sample code:
+ *
+ *
{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * try (DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create()) {
+ * GetBackupScheduleRequest request =
+ * GetBackupScheduleRequest.newBuilder()
+ * .setName(
+ * BackupScheduleName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SCHEDULE]")
+ * .toString())
+ * .build();
+ * BackupSchedule response = databaseAdminClient.getBackupSchedule(request);
+ * }
+ * }
+ *
+ * @param request The request object containing all of the parameters for the API call.
+ * @throws com.google.api.gax.rpc.ApiException if the remote call fails
+ */
+ public final BackupSchedule getBackupSchedule(GetBackupScheduleRequest request) {
+ return getBackupScheduleCallable().call(request);
+ }
- private ListDatabasesPagedResponse(ListDatabasesPage page) {
- super(page, ListDatabasesFixedSizeCollection.createEmptyCollection());
- }
+ // AUTO-GENERATED DOCUMENTATION AND METHOD.
+ /**
+ * Gets backup schedule for the input schedule name.
+ *
+ * Sample code:
+ *
+ *
{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * try (DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create()) {
+ * GetBackupScheduleRequest request =
+ * GetBackupScheduleRequest.newBuilder()
+ * .setName(
+ * BackupScheduleName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SCHEDULE]")
+ * .toString())
+ * .build();
+ * ApiFuture future =
+ * databaseAdminClient.getBackupScheduleCallable().futureCall(request);
+ * // Do something.
+ * BackupSchedule response = future.get();
+ * }
+ * }
+ */
+ public final UnaryCallable getBackupScheduleCallable() {
+ return stub.getBackupScheduleCallable();
}
- public static class ListDatabasesPage
- extends AbstractPage<
+ // AUTO-GENERATED DOCUMENTATION AND METHOD.
+ /**
+ * Updates a backup schedule.
+ *
+ * Sample code:
+ *
+ *
{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * try (DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create()) {
+ * BackupSchedule backupSchedule = BackupSchedule.newBuilder().build();
+ * FieldMask updateMask = FieldMask.newBuilder().build();
+ * BackupSchedule response =
+ * databaseAdminClient.updateBackupSchedule(backupSchedule, updateMask);
+ * }
+ * }
+ *
+ * @param backupSchedule Required. The backup schedule to update. `backup_schedule.name`, and the
+ * fields to be updated as specified by `update_mask` are required. Other fields are ignored.
+ * @param updateMask Required. A mask specifying which fields in the BackupSchedule resource
+ * should be updated. This mask is relative to the BackupSchedule resource, not to the request
+ * message. The field mask must always be specified; this prevents any future fields from
+ * being erased accidentally.
+ * @throws com.google.api.gax.rpc.ApiException if the remote call fails
+ */
+ public final BackupSchedule updateBackupSchedule(
+ BackupSchedule backupSchedule, FieldMask updateMask) {
+ UpdateBackupScheduleRequest request =
+ UpdateBackupScheduleRequest.newBuilder()
+ .setBackupSchedule(backupSchedule)
+ .setUpdateMask(updateMask)
+ .build();
+ return updateBackupSchedule(request);
+ }
+
+ // AUTO-GENERATED DOCUMENTATION AND METHOD.
+ /**
+ * Updates a backup schedule.
+ *
+ * Sample code:
+ *
+ *
{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * try (DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create()) {
+ * UpdateBackupScheduleRequest request =
+ * UpdateBackupScheduleRequest.newBuilder()
+ * .setBackupSchedule(BackupSchedule.newBuilder().build())
+ * .setUpdateMask(FieldMask.newBuilder().build())
+ * .build();
+ * BackupSchedule response = databaseAdminClient.updateBackupSchedule(request);
+ * }
+ * }
+ *
+ * @param request The request object containing all of the parameters for the API call.
+ * @throws com.google.api.gax.rpc.ApiException if the remote call fails
+ */
+ public final BackupSchedule updateBackupSchedule(UpdateBackupScheduleRequest request) {
+ return updateBackupScheduleCallable().call(request);
+ }
+
+ // AUTO-GENERATED DOCUMENTATION AND METHOD.
+ /**
+ * Updates a backup schedule.
+ *
+ * Sample code:
+ *
+ *
{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * try (DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create()) {
+ * UpdateBackupScheduleRequest request =
+ * UpdateBackupScheduleRequest.newBuilder()
+ * .setBackupSchedule(BackupSchedule.newBuilder().build())
+ * .setUpdateMask(FieldMask.newBuilder().build())
+ * .build();
+ * ApiFuture future =
+ * databaseAdminClient.updateBackupScheduleCallable().futureCall(request);
+ * // Do something.
+ * BackupSchedule response = future.get();
+ * }
+ * }
+ */
+ public final UnaryCallable
+ updateBackupScheduleCallable() {
+ return stub.updateBackupScheduleCallable();
+ }
+
+ // AUTO-GENERATED DOCUMENTATION AND METHOD.
+ /**
+ * Deletes a backup schedule.
+ *
+ * Sample code:
+ *
+ *
{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * try (DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create()) {
+ * BackupScheduleName name =
+ * BackupScheduleName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SCHEDULE]");
+ * databaseAdminClient.deleteBackupSchedule(name);
+ * }
+ * }
+ *
+ * @param name Required. The name of the schedule to delete. Values are of the form
+ * `projects/<project>/instances/<instance>/databases/<database>/backupSchedules/<backup_schedule_id>`.
+ * @throws com.google.api.gax.rpc.ApiException if the remote call fails
+ */
+ public final void deleteBackupSchedule(BackupScheduleName name) {
+ DeleteBackupScheduleRequest request =
+ DeleteBackupScheduleRequest.newBuilder()
+ .setName(name == null ? null : name.toString())
+ .build();
+ deleteBackupSchedule(request);
+ }
+
+ // AUTO-GENERATED DOCUMENTATION AND METHOD.
+ /**
+ * Deletes a backup schedule.
+ *
+ * Sample code:
+ *
+ *
{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * try (DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create()) {
+ * String name =
+ * BackupScheduleName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SCHEDULE]").toString();
+ * databaseAdminClient.deleteBackupSchedule(name);
+ * }
+ * }
+ *
+ * @param name Required. The name of the schedule to delete. Values are of the form
+ * `projects/<project>/instances/<instance>/databases/<database>/backupSchedules/<backup_schedule_id>`.
+ * @throws com.google.api.gax.rpc.ApiException if the remote call fails
+ */
+ public final void deleteBackupSchedule(String name) {
+ DeleteBackupScheduleRequest request =
+ DeleteBackupScheduleRequest.newBuilder().setName(name).build();
+ deleteBackupSchedule(request);
+ }
+
+ // AUTO-GENERATED DOCUMENTATION AND METHOD.
+ /**
+ * Deletes a backup schedule.
+ *
+ * Sample code:
+ *
+ *
{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * try (DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create()) {
+ * DeleteBackupScheduleRequest request =
+ * DeleteBackupScheduleRequest.newBuilder()
+ * .setName(
+ * BackupScheduleName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SCHEDULE]")
+ * .toString())
+ * .build();
+ * databaseAdminClient.deleteBackupSchedule(request);
+ * }
+ * }
+ *
+ * @param request The request object containing all of the parameters for the API call.
+ * @throws com.google.api.gax.rpc.ApiException if the remote call fails
+ */
+ public final void deleteBackupSchedule(DeleteBackupScheduleRequest request) {
+ deleteBackupScheduleCallable().call(request);
+ }
+
+ // AUTO-GENERATED DOCUMENTATION AND METHOD.
+ /**
+ * Deletes a backup schedule.
+ *
+ * Sample code:
+ *
+ *
{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * try (DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create()) {
+ * DeleteBackupScheduleRequest request =
+ * DeleteBackupScheduleRequest.newBuilder()
+ * .setName(
+ * BackupScheduleName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SCHEDULE]")
+ * .toString())
+ * .build();
+ * ApiFuture future =
+ * databaseAdminClient.deleteBackupScheduleCallable().futureCall(request);
+ * // Do something.
+ * future.get();
+ * }
+ * }
+ */
+ public final UnaryCallable deleteBackupScheduleCallable() {
+ return stub.deleteBackupScheduleCallable();
+ }
+
+ // AUTO-GENERATED DOCUMENTATION AND METHOD.
+ /**
+ * Lists all the backup schedules for the database.
+ *
+ * Sample code:
+ *
+ *
{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * try (DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create()) {
+ * DatabaseName parent = DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]");
+ * for (BackupSchedule element : databaseAdminClient.listBackupSchedules(parent).iterateAll()) {
+ * // doThingsWith(element);
+ * }
+ * }
+ * }
+ *
+ * @param parent Required. Database is the parent resource whose backup schedules should be
+ * listed. Values are of the form
+ * projects/<project>/instances/<instance>/databases/<database>
+ * @throws com.google.api.gax.rpc.ApiException if the remote call fails
+ */
+ public final ListBackupSchedulesPagedResponse listBackupSchedules(DatabaseName parent) {
+ ListBackupSchedulesRequest request =
+ ListBackupSchedulesRequest.newBuilder()
+ .setParent(parent == null ? null : parent.toString())
+ .build();
+ return listBackupSchedules(request);
+ }
+
+ // AUTO-GENERATED DOCUMENTATION AND METHOD.
+ /**
+ * Lists all the backup schedules for the database.
+ *
+ * Sample code:
+ *
+ *
{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * try (DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create()) {
+ * String parent = DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]").toString();
+ * for (BackupSchedule element : databaseAdminClient.listBackupSchedules(parent).iterateAll()) {
+ * // doThingsWith(element);
+ * }
+ * }
+ * }
+ *
+ * @param parent Required. Database is the parent resource whose backup schedules should be
+ * listed. Values are of the form
+ * projects/<project>/instances/<instance>/databases/<database>
+ * @throws com.google.api.gax.rpc.ApiException if the remote call fails
+ */
+ public final ListBackupSchedulesPagedResponse listBackupSchedules(String parent) {
+ ListBackupSchedulesRequest request =
+ ListBackupSchedulesRequest.newBuilder().setParent(parent).build();
+ return listBackupSchedules(request);
+ }
+
+ // AUTO-GENERATED DOCUMENTATION AND METHOD.
+ /**
+ * Lists all the backup schedules for the database.
+ *
+ * Sample code:
+ *
+ *
{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * try (DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create()) {
+ * ListBackupSchedulesRequest request =
+ * ListBackupSchedulesRequest.newBuilder()
+ * .setParent(DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]").toString())
+ * .setPageSize(883849137)
+ * .setPageToken("pageToken873572522")
+ * .build();
+ * for (BackupSchedule element : databaseAdminClient.listBackupSchedules(request).iterateAll()) {
+ * // doThingsWith(element);
+ * }
+ * }
+ * }
+ *
+ * @param request The request object containing all of the parameters for the API call.
+ * @throws com.google.api.gax.rpc.ApiException if the remote call fails
+ */
+ public final ListBackupSchedulesPagedResponse listBackupSchedules(
+ ListBackupSchedulesRequest request) {
+ return listBackupSchedulesPagedCallable().call(request);
+ }
+
+ // AUTO-GENERATED DOCUMENTATION AND METHOD.
+ /**
+ * Lists all the backup schedules for the database.
+ *
+ * Sample code:
+ *
+ *
{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * try (DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create()) {
+ * ListBackupSchedulesRequest request =
+ * ListBackupSchedulesRequest.newBuilder()
+ * .setParent(DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]").toString())
+ * .setPageSize(883849137)
+ * .setPageToken("pageToken873572522")
+ * .build();
+ * ApiFuture future =
+ * databaseAdminClient.listBackupSchedulesPagedCallable().futureCall(request);
+ * // Do something.
+ * for (BackupSchedule element : future.get().iterateAll()) {
+ * // doThingsWith(element);
+ * }
+ * }
+ * }
+ */
+ public final UnaryCallable
+ listBackupSchedulesPagedCallable() {
+ return stub.listBackupSchedulesPagedCallable();
+ }
+
+ // AUTO-GENERATED DOCUMENTATION AND METHOD.
+ /**
+ * Lists all the backup schedules for the database.
+ *
+ * Sample code:
+ *
+ *
{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * try (DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create()) {
+ * ListBackupSchedulesRequest request =
+ * ListBackupSchedulesRequest.newBuilder()
+ * .setParent(DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]").toString())
+ * .setPageSize(883849137)
+ * .setPageToken("pageToken873572522")
+ * .build();
+ * while (true) {
+ * ListBackupSchedulesResponse response =
+ * databaseAdminClient.listBackupSchedulesCallable().call(request);
+ * for (BackupSchedule element : response.getBackupSchedulesList()) {
+ * // doThingsWith(element);
+ * }
+ * String nextPageToken = response.getNextPageToken();
+ * if (!Strings.isNullOrEmpty(nextPageToken)) {
+ * request = request.toBuilder().setPageToken(nextPageToken).build();
+ * } else {
+ * break;
+ * }
+ * }
+ * }
+ * }
+ */
+ public final UnaryCallable
+ listBackupSchedulesCallable() {
+ return stub.listBackupSchedulesCallable();
+ }
+
+ @Override
+ public final void close() {
+ stub.close();
+ }
+
+ @Override
+ public void shutdown() {
+ stub.shutdown();
+ }
+
+ @Override
+ public boolean isShutdown() {
+ return stub.isShutdown();
+ }
+
+ @Override
+ public boolean isTerminated() {
+ return stub.isTerminated();
+ }
+
+ @Override
+ public void shutdownNow() {
+ stub.shutdownNow();
+ }
+
+ @Override
+ public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException {
+ return stub.awaitTermination(duration, unit);
+ }
+
+ public static class ListDatabasesPagedResponse
+ extends AbstractPagedListResponse<
+ ListDatabasesRequest,
+ ListDatabasesResponse,
+ Database,
+ ListDatabasesPage,
+ ListDatabasesFixedSizeCollection> {
+
+ public static ApiFuture createAsync(
+ PageContext context,
+ ApiFuture futureResponse) {
+ ApiFuture futurePage =
+ ListDatabasesPage.createEmptyPage().createPageAsync(context, futureResponse);
+ return ApiFutures.transform(
+ futurePage,
+ input -> new ListDatabasesPagedResponse(input),
+ MoreExecutors.directExecutor());
+ }
+
+ private ListDatabasesPagedResponse(ListDatabasesPage page) {
+ super(page, ListDatabasesFixedSizeCollection.createEmptyCollection());
+ }
+ }
+
+ public static class ListDatabasesPage
+ extends AbstractPage<
ListDatabasesRequest, ListDatabasesResponse, Database, ListDatabasesPage> {
private ListDatabasesPage(
@@ -4637,4 +5385,88 @@ protected ListDatabaseRolesFixedSizeCollection createCollection(
return new ListDatabaseRolesFixedSizeCollection(pages, collectionSize);
}
}
+
+ public static class ListBackupSchedulesPagedResponse
+ extends AbstractPagedListResponse<
+ ListBackupSchedulesRequest,
+ ListBackupSchedulesResponse,
+ BackupSchedule,
+ ListBackupSchedulesPage,
+ ListBackupSchedulesFixedSizeCollection> {
+
+ public static ApiFuture createAsync(
+ PageContext
+ context,
+ ApiFuture futureResponse) {
+ ApiFuture futurePage =
+ ListBackupSchedulesPage.createEmptyPage().createPageAsync(context, futureResponse);
+ return ApiFutures.transform(
+ futurePage,
+ input -> new ListBackupSchedulesPagedResponse(input),
+ MoreExecutors.directExecutor());
+ }
+
+ private ListBackupSchedulesPagedResponse(ListBackupSchedulesPage page) {
+ super(page, ListBackupSchedulesFixedSizeCollection.createEmptyCollection());
+ }
+ }
+
+ public static class ListBackupSchedulesPage
+ extends AbstractPage<
+ ListBackupSchedulesRequest,
+ ListBackupSchedulesResponse,
+ BackupSchedule,
+ ListBackupSchedulesPage> {
+
+ private ListBackupSchedulesPage(
+ PageContext
+ context,
+ ListBackupSchedulesResponse response) {
+ super(context, response);
+ }
+
+ private static ListBackupSchedulesPage createEmptyPage() {
+ return new ListBackupSchedulesPage(null, null);
+ }
+
+ @Override
+ protected ListBackupSchedulesPage createPage(
+ PageContext
+ context,
+ ListBackupSchedulesResponse response) {
+ return new ListBackupSchedulesPage(context, response);
+ }
+
+ @Override
+ public ApiFuture createPageAsync(
+ PageContext
+ context,
+ ApiFuture futureResponse) {
+ return super.createPageAsync(context, futureResponse);
+ }
+ }
+
+ public static class ListBackupSchedulesFixedSizeCollection
+ extends AbstractFixedSizeCollection<
+ ListBackupSchedulesRequest,
+ ListBackupSchedulesResponse,
+ BackupSchedule,
+ ListBackupSchedulesPage,
+ ListBackupSchedulesFixedSizeCollection> {
+
+ private ListBackupSchedulesFixedSizeCollection(
+ List pages, int collectionSize) {
+ super(pages, collectionSize);
+ }
+
+ private static ListBackupSchedulesFixedSizeCollection createEmptyCollection() {
+ return new ListBackupSchedulesFixedSizeCollection(null, 0);
+ }
+
+ @Override
+ protected ListBackupSchedulesFixedSizeCollection createCollection(
+ List pages, int collectionSize) {
+ return new ListBackupSchedulesFixedSizeCollection(pages, collectionSize);
+ }
+ }
}
diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/database/v1/DatabaseAdminSettings.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/database/v1/DatabaseAdminSettings.java
index 50d6900e1ce..513f91e7100 100644
--- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/database/v1/DatabaseAdminSettings.java
+++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/database/v1/DatabaseAdminSettings.java
@@ -17,6 +17,7 @@
package com.google.cloud.spanner.admin.database.v1;
import static com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient.ListBackupOperationsPagedResponse;
+import static com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient.ListBackupSchedulesPagedResponse;
import static com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient.ListBackupsPagedResponse;
import static com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient.ListDatabaseOperationsPagedResponse;
import static com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient.ListDatabaseRolesPagedResponse;
@@ -44,21 +45,27 @@
import com.google.longrunning.Operation;
import com.google.protobuf.Empty;
import com.google.spanner.admin.database.v1.Backup;
+import com.google.spanner.admin.database.v1.BackupSchedule;
import com.google.spanner.admin.database.v1.CopyBackupMetadata;
import com.google.spanner.admin.database.v1.CopyBackupRequest;
import com.google.spanner.admin.database.v1.CreateBackupMetadata;
import com.google.spanner.admin.database.v1.CreateBackupRequest;
+import com.google.spanner.admin.database.v1.CreateBackupScheduleRequest;
import com.google.spanner.admin.database.v1.CreateDatabaseMetadata;
import com.google.spanner.admin.database.v1.CreateDatabaseRequest;
import com.google.spanner.admin.database.v1.Database;
import com.google.spanner.admin.database.v1.DeleteBackupRequest;
+import com.google.spanner.admin.database.v1.DeleteBackupScheduleRequest;
import com.google.spanner.admin.database.v1.DropDatabaseRequest;
import com.google.spanner.admin.database.v1.GetBackupRequest;
+import com.google.spanner.admin.database.v1.GetBackupScheduleRequest;
import com.google.spanner.admin.database.v1.GetDatabaseDdlRequest;
import com.google.spanner.admin.database.v1.GetDatabaseDdlResponse;
import com.google.spanner.admin.database.v1.GetDatabaseRequest;
import com.google.spanner.admin.database.v1.ListBackupOperationsRequest;
import com.google.spanner.admin.database.v1.ListBackupOperationsResponse;
+import com.google.spanner.admin.database.v1.ListBackupSchedulesRequest;
+import com.google.spanner.admin.database.v1.ListBackupSchedulesResponse;
import com.google.spanner.admin.database.v1.ListBackupsRequest;
import com.google.spanner.admin.database.v1.ListBackupsResponse;
import com.google.spanner.admin.database.v1.ListDatabaseOperationsRequest;
@@ -70,6 +77,7 @@
import com.google.spanner.admin.database.v1.RestoreDatabaseMetadata;
import com.google.spanner.admin.database.v1.RestoreDatabaseRequest;
import com.google.spanner.admin.database.v1.UpdateBackupRequest;
+import com.google.spanner.admin.database.v1.UpdateBackupScheduleRequest;
import com.google.spanner.admin.database.v1.UpdateDatabaseDdlMetadata;
import com.google.spanner.admin.database.v1.UpdateDatabaseDdlRequest;
import com.google.spanner.admin.database.v1.UpdateDatabaseMetadata;
@@ -266,6 +274,35 @@ public UnaryCallSettings restoreDatabaseSetti
return ((DatabaseAdminStubSettings) getStubSettings()).listDatabaseRolesSettings();
}
+ /** Returns the object with the settings used for calls to createBackupSchedule. */
+ public UnaryCallSettings
+ createBackupScheduleSettings() {
+ return ((DatabaseAdminStubSettings) getStubSettings()).createBackupScheduleSettings();
+ }
+
+ /** Returns the object with the settings used for calls to getBackupSchedule. */
+ public UnaryCallSettings getBackupScheduleSettings() {
+ return ((DatabaseAdminStubSettings) getStubSettings()).getBackupScheduleSettings();
+ }
+
+ /** Returns the object with the settings used for calls to updateBackupSchedule. */
+ public UnaryCallSettings
+ updateBackupScheduleSettings() {
+ return ((DatabaseAdminStubSettings) getStubSettings()).updateBackupScheduleSettings();
+ }
+
+ /** Returns the object with the settings used for calls to deleteBackupSchedule. */
+ public UnaryCallSettings deleteBackupScheduleSettings() {
+ return ((DatabaseAdminStubSettings) getStubSettings()).deleteBackupScheduleSettings();
+ }
+
+ /** Returns the object with the settings used for calls to listBackupSchedules. */
+ public PagedCallSettings<
+ ListBackupSchedulesRequest, ListBackupSchedulesResponse, ListBackupSchedulesPagedResponse>
+ listBackupSchedulesSettings() {
+ return ((DatabaseAdminStubSettings) getStubSettings()).listBackupSchedulesSettings();
+ }
+
public static final DatabaseAdminSettings create(DatabaseAdminStubSettings stub)
throws IOException {
return new DatabaseAdminSettings.Builder(stub.toBuilder()).build();
@@ -531,6 +568,39 @@ public UnaryCallSettings.Builder restoreDatab
return getStubSettingsBuilder().listDatabaseRolesSettings();
}
+ /** Returns the builder for the settings used for calls to createBackupSchedule. */
+ public UnaryCallSettings.Builder
+ createBackupScheduleSettings() {
+ return getStubSettingsBuilder().createBackupScheduleSettings();
+ }
+
+ /** Returns the builder for the settings used for calls to getBackupSchedule. */
+ public UnaryCallSettings.Builder
+ getBackupScheduleSettings() {
+ return getStubSettingsBuilder().getBackupScheduleSettings();
+ }
+
+ /** Returns the builder for the settings used for calls to updateBackupSchedule. */
+ public UnaryCallSettings.Builder
+ updateBackupScheduleSettings() {
+ return getStubSettingsBuilder().updateBackupScheduleSettings();
+ }
+
+ /** Returns the builder for the settings used for calls to deleteBackupSchedule. */
+ public UnaryCallSettings.Builder
+ deleteBackupScheduleSettings() {
+ return getStubSettingsBuilder().deleteBackupScheduleSettings();
+ }
+
+ /** Returns the builder for the settings used for calls to listBackupSchedules. */
+ public PagedCallSettings.Builder<
+ ListBackupSchedulesRequest,
+ ListBackupSchedulesResponse,
+ ListBackupSchedulesPagedResponse>
+ listBackupSchedulesSettings() {
+ return getStubSettingsBuilder().listBackupSchedulesSettings();
+ }
+
@Override
public DatabaseAdminSettings build() throws IOException {
return new DatabaseAdminSettings(this);
diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/database/v1/gapic_metadata.json b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/database/v1/gapic_metadata.json
index 01fcbd4de1a..7d6c894d7b6 100644
--- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/database/v1/gapic_metadata.json
+++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/database/v1/gapic_metadata.json
@@ -16,18 +16,27 @@
"CreateBackup": {
"methods": ["createBackupAsync", "createBackupAsync", "createBackupAsync", "createBackupOperationCallable", "createBackupCallable"]
},
+ "CreateBackupSchedule": {
+ "methods": ["createBackupSchedule", "createBackupSchedule", "createBackupSchedule", "createBackupScheduleCallable"]
+ },
"CreateDatabase": {
"methods": ["createDatabaseAsync", "createDatabaseAsync", "createDatabaseAsync", "createDatabaseOperationCallable", "createDatabaseCallable"]
},
"DeleteBackup": {
"methods": ["deleteBackup", "deleteBackup", "deleteBackup", "deleteBackupCallable"]
},
+ "DeleteBackupSchedule": {
+ "methods": ["deleteBackupSchedule", "deleteBackupSchedule", "deleteBackupSchedule", "deleteBackupScheduleCallable"]
+ },
"DropDatabase": {
"methods": ["dropDatabase", "dropDatabase", "dropDatabase", "dropDatabaseCallable"]
},
"GetBackup": {
"methods": ["getBackup", "getBackup", "getBackup", "getBackupCallable"]
},
+ "GetBackupSchedule": {
+ "methods": ["getBackupSchedule", "getBackupSchedule", "getBackupSchedule", "getBackupScheduleCallable"]
+ },
"GetDatabase": {
"methods": ["getDatabase", "getDatabase", "getDatabase", "getDatabaseCallable"]
},
@@ -40,6 +49,9 @@
"ListBackupOperations": {
"methods": ["listBackupOperations", "listBackupOperations", "listBackupOperations", "listBackupOperationsPagedCallable", "listBackupOperationsCallable"]
},
+ "ListBackupSchedules": {
+ "methods": ["listBackupSchedules", "listBackupSchedules", "listBackupSchedules", "listBackupSchedulesPagedCallable", "listBackupSchedulesCallable"]
+ },
"ListBackups": {
"methods": ["listBackups", "listBackups", "listBackups", "listBackupsPagedCallable", "listBackupsCallable"]
},
@@ -64,6 +76,9 @@
"UpdateBackup": {
"methods": ["updateBackup", "updateBackup", "updateBackupCallable"]
},
+ "UpdateBackupSchedule": {
+ "methods": ["updateBackupSchedule", "updateBackupSchedule", "updateBackupScheduleCallable"]
+ },
"UpdateDatabase": {
"methods": ["updateDatabaseAsync", "updateDatabaseAsync", "updateDatabaseOperationCallable", "updateDatabaseCallable"]
},
diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/database/v1/stub/DatabaseAdminStub.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/database/v1/stub/DatabaseAdminStub.java
index 37fb433c3eb..2f53f6cf5b4 100644
--- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/database/v1/stub/DatabaseAdminStub.java
+++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/database/v1/stub/DatabaseAdminStub.java
@@ -17,6 +17,7 @@
package com.google.cloud.spanner.admin.database.v1.stub;
import static com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient.ListBackupOperationsPagedResponse;
+import static com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient.ListBackupSchedulesPagedResponse;
import static com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient.ListBackupsPagedResponse;
import static com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient.ListDatabaseOperationsPagedResponse;
import static com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient.ListDatabaseRolesPagedResponse;
@@ -34,21 +35,27 @@
import com.google.longrunning.stub.OperationsStub;
import com.google.protobuf.Empty;
import com.google.spanner.admin.database.v1.Backup;
+import com.google.spanner.admin.database.v1.BackupSchedule;
import com.google.spanner.admin.database.v1.CopyBackupMetadata;
import com.google.spanner.admin.database.v1.CopyBackupRequest;
import com.google.spanner.admin.database.v1.CreateBackupMetadata;
import com.google.spanner.admin.database.v1.CreateBackupRequest;
+import com.google.spanner.admin.database.v1.CreateBackupScheduleRequest;
import com.google.spanner.admin.database.v1.CreateDatabaseMetadata;
import com.google.spanner.admin.database.v1.CreateDatabaseRequest;
import com.google.spanner.admin.database.v1.Database;
import com.google.spanner.admin.database.v1.DeleteBackupRequest;
+import com.google.spanner.admin.database.v1.DeleteBackupScheduleRequest;
import com.google.spanner.admin.database.v1.DropDatabaseRequest;
import com.google.spanner.admin.database.v1.GetBackupRequest;
+import com.google.spanner.admin.database.v1.GetBackupScheduleRequest;
import com.google.spanner.admin.database.v1.GetDatabaseDdlRequest;
import com.google.spanner.admin.database.v1.GetDatabaseDdlResponse;
import com.google.spanner.admin.database.v1.GetDatabaseRequest;
import com.google.spanner.admin.database.v1.ListBackupOperationsRequest;
import com.google.spanner.admin.database.v1.ListBackupOperationsResponse;
+import com.google.spanner.admin.database.v1.ListBackupSchedulesRequest;
+import com.google.spanner.admin.database.v1.ListBackupSchedulesResponse;
import com.google.spanner.admin.database.v1.ListBackupsRequest;
import com.google.spanner.admin.database.v1.ListBackupsResponse;
import com.google.spanner.admin.database.v1.ListDatabaseOperationsRequest;
@@ -60,6 +67,7 @@
import com.google.spanner.admin.database.v1.RestoreDatabaseMetadata;
import com.google.spanner.admin.database.v1.RestoreDatabaseRequest;
import com.google.spanner.admin.database.v1.UpdateBackupRequest;
+import com.google.spanner.admin.database.v1.UpdateBackupScheduleRequest;
import com.google.spanner.admin.database.v1.UpdateDatabaseDdlMetadata;
import com.google.spanner.admin.database.v1.UpdateDatabaseDdlRequest;
import com.google.spanner.admin.database.v1.UpdateDatabaseMetadata;
@@ -223,6 +231,32 @@ public UnaryCallable restoreDatabaseCallable(
throw new UnsupportedOperationException("Not implemented: listDatabaseRolesCallable()");
}
+ public UnaryCallable createBackupScheduleCallable() {
+ throw new UnsupportedOperationException("Not implemented: createBackupScheduleCallable()");
+ }
+
+ public UnaryCallable getBackupScheduleCallable() {
+ throw new UnsupportedOperationException("Not implemented: getBackupScheduleCallable()");
+ }
+
+ public UnaryCallable updateBackupScheduleCallable() {
+ throw new UnsupportedOperationException("Not implemented: updateBackupScheduleCallable()");
+ }
+
+ public UnaryCallable deleteBackupScheduleCallable() {
+ throw new UnsupportedOperationException("Not implemented: deleteBackupScheduleCallable()");
+ }
+
+ public UnaryCallable
+ listBackupSchedulesPagedCallable() {
+ throw new UnsupportedOperationException("Not implemented: listBackupSchedulesPagedCallable()");
+ }
+
+ public UnaryCallable
+ listBackupSchedulesCallable() {
+ throw new UnsupportedOperationException("Not implemented: listBackupSchedulesCallable()");
+ }
+
@Override
public abstract void close();
}
diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/database/v1/stub/DatabaseAdminStubSettings.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/database/v1/stub/DatabaseAdminStubSettings.java
index 4808f1553e9..2865fcd8d08 100644
--- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/database/v1/stub/DatabaseAdminStubSettings.java
+++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/database/v1/stub/DatabaseAdminStubSettings.java
@@ -17,6 +17,7 @@
package com.google.cloud.spanner.admin.database.v1.stub;
import static com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient.ListBackupOperationsPagedResponse;
+import static com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient.ListBackupSchedulesPagedResponse;
import static com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient.ListBackupsPagedResponse;
import static com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient.ListDatabaseOperationsPagedResponse;
import static com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient.ListDatabaseRolesPagedResponse;
@@ -25,6 +26,7 @@
import com.google.api.core.ApiFunction;
import com.google.api.core.ApiFuture;
import com.google.api.core.BetaApi;
+import com.google.api.core.ObsoleteApi;
import com.google.api.gax.core.GaxProperties;
import com.google.api.gax.core.GoogleCredentialsProvider;
import com.google.api.gax.core.InstantiatingExecutorProvider;
@@ -63,22 +65,28 @@
import com.google.longrunning.Operation;
import com.google.protobuf.Empty;
import com.google.spanner.admin.database.v1.Backup;
+import com.google.spanner.admin.database.v1.BackupSchedule;
import com.google.spanner.admin.database.v1.CopyBackupMetadata;
import com.google.spanner.admin.database.v1.CopyBackupRequest;
import com.google.spanner.admin.database.v1.CreateBackupMetadata;
import com.google.spanner.admin.database.v1.CreateBackupRequest;
+import com.google.spanner.admin.database.v1.CreateBackupScheduleRequest;
import com.google.spanner.admin.database.v1.CreateDatabaseMetadata;
import com.google.spanner.admin.database.v1.CreateDatabaseRequest;
import com.google.spanner.admin.database.v1.Database;
import com.google.spanner.admin.database.v1.DatabaseRole;
import com.google.spanner.admin.database.v1.DeleteBackupRequest;
+import com.google.spanner.admin.database.v1.DeleteBackupScheduleRequest;
import com.google.spanner.admin.database.v1.DropDatabaseRequest;
import com.google.spanner.admin.database.v1.GetBackupRequest;
+import com.google.spanner.admin.database.v1.GetBackupScheduleRequest;
import com.google.spanner.admin.database.v1.GetDatabaseDdlRequest;
import com.google.spanner.admin.database.v1.GetDatabaseDdlResponse;
import com.google.spanner.admin.database.v1.GetDatabaseRequest;
import com.google.spanner.admin.database.v1.ListBackupOperationsRequest;
import com.google.spanner.admin.database.v1.ListBackupOperationsResponse;
+import com.google.spanner.admin.database.v1.ListBackupSchedulesRequest;
+import com.google.spanner.admin.database.v1.ListBackupSchedulesResponse;
import com.google.spanner.admin.database.v1.ListBackupsRequest;
import com.google.spanner.admin.database.v1.ListBackupsResponse;
import com.google.spanner.admin.database.v1.ListDatabaseOperationsRequest;
@@ -90,6 +98,7 @@
import com.google.spanner.admin.database.v1.RestoreDatabaseMetadata;
import com.google.spanner.admin.database.v1.RestoreDatabaseRequest;
import com.google.spanner.admin.database.v1.UpdateBackupRequest;
+import com.google.spanner.admin.database.v1.UpdateBackupScheduleRequest;
import com.google.spanner.admin.database.v1.UpdateDatabaseDdlMetadata;
import com.google.spanner.admin.database.v1.UpdateDatabaseDdlRequest;
import com.google.spanner.admin.database.v1.UpdateDatabaseMetadata;
@@ -192,6 +201,16 @@ public class DatabaseAdminStubSettings extends StubSettings
listDatabaseRolesSettings;
+ private final UnaryCallSettings
+ createBackupScheduleSettings;
+ private final UnaryCallSettings
+ getBackupScheduleSettings;
+ private final UnaryCallSettings
+ updateBackupScheduleSettings;
+ private final UnaryCallSettings deleteBackupScheduleSettings;
+ private final PagedCallSettings<
+ ListBackupSchedulesRequest, ListBackupSchedulesResponse, ListBackupSchedulesPagedResponse>
+ listBackupSchedulesSettings;
private static final PagedListDescriptor
LIST_DATABASES_PAGE_STR_DESC =
@@ -387,6 +406,46 @@ public Iterable extractResources(ListDatabaseRolesResponse payload
}
};
+ private static final PagedListDescriptor<
+ ListBackupSchedulesRequest, ListBackupSchedulesResponse, BackupSchedule>
+ LIST_BACKUP_SCHEDULES_PAGE_STR_DESC =
+ new PagedListDescriptor<
+ ListBackupSchedulesRequest, ListBackupSchedulesResponse, BackupSchedule>() {
+ @Override
+ public String emptyToken() {
+ return "";
+ }
+
+ @Override
+ public ListBackupSchedulesRequest injectToken(
+ ListBackupSchedulesRequest payload, String token) {
+ return ListBackupSchedulesRequest.newBuilder(payload).setPageToken(token).build();
+ }
+
+ @Override
+ public ListBackupSchedulesRequest injectPageSize(
+ ListBackupSchedulesRequest payload, int pageSize) {
+ return ListBackupSchedulesRequest.newBuilder(payload).setPageSize(pageSize).build();
+ }
+
+ @Override
+ public Integer extractPageSize(ListBackupSchedulesRequest payload) {
+ return payload.getPageSize();
+ }
+
+ @Override
+ public String extractNextToken(ListBackupSchedulesResponse payload) {
+ return payload.getNextPageToken();
+ }
+
+ @Override
+ public Iterable extractResources(ListBackupSchedulesResponse payload) {
+ return payload.getBackupSchedulesList() == null
+ ? ImmutableList.of()
+ : payload.getBackupSchedulesList();
+ }
+ };
+
private static final PagedListResponseFactory<
ListDatabasesRequest, ListDatabasesResponse, ListDatabasesPagedResponse>
LIST_DATABASES_PAGE_STR_FACT =
@@ -489,6 +548,27 @@ public ApiFuture getFuturePagedResponse(
}
};
+ private static final PagedListResponseFactory<
+ ListBackupSchedulesRequest, ListBackupSchedulesResponse, ListBackupSchedulesPagedResponse>
+ LIST_BACKUP_SCHEDULES_PAGE_STR_FACT =
+ new PagedListResponseFactory<
+ ListBackupSchedulesRequest,
+ ListBackupSchedulesResponse,
+ ListBackupSchedulesPagedResponse>() {
+ @Override
+ public ApiFuture getFuturePagedResponse(
+ UnaryCallable callable,
+ ListBackupSchedulesRequest request,
+ ApiCallContext context,
+ ApiFuture futureResponse) {
+ PageContext
+ pageContext =
+ PageContext.create(
+ callable, LIST_BACKUP_SCHEDULES_PAGE_STR_DESC, request, context);
+ return ListBackupSchedulesPagedResponse.createAsync(pageContext, futureResponse);
+ }
+ };
+
/** Returns the object with the settings used for calls to listDatabases. */
public PagedCallSettings
listDatabasesSettings() {
@@ -638,6 +718,35 @@ public UnaryCallSettings restoreDatabaseSetti
return listDatabaseRolesSettings;
}
+ /** Returns the object with the settings used for calls to createBackupSchedule. */
+ public UnaryCallSettings
+ createBackupScheduleSettings() {
+ return createBackupScheduleSettings;
+ }
+
+ /** Returns the object with the settings used for calls to getBackupSchedule. */
+ public UnaryCallSettings getBackupScheduleSettings() {
+ return getBackupScheduleSettings;
+ }
+
+ /** Returns the object with the settings used for calls to updateBackupSchedule. */
+ public UnaryCallSettings
+ updateBackupScheduleSettings() {
+ return updateBackupScheduleSettings;
+ }
+
+ /** Returns the object with the settings used for calls to deleteBackupSchedule. */
+ public UnaryCallSettings deleteBackupScheduleSettings() {
+ return deleteBackupScheduleSettings;
+ }
+
+ /** Returns the object with the settings used for calls to listBackupSchedules. */
+ public PagedCallSettings<
+ ListBackupSchedulesRequest, ListBackupSchedulesResponse, ListBackupSchedulesPagedResponse>
+ listBackupSchedulesSettings() {
+ return listBackupSchedulesSettings;
+ }
+
public DatabaseAdminStub createStub() throws IOException {
if (getTransportChannelProvider()
.getTransportName()
@@ -666,6 +775,7 @@ public static InstantiatingExecutorProvider.Builder defaultExecutorProviderBuild
}
/** Returns the default service endpoint. */
+ @ObsoleteApi("Use getEndpoint() instead")
public static String getDefaultEndpoint() {
return "spanner.googleapis.com:443";
}
@@ -775,6 +885,11 @@ protected DatabaseAdminStubSettings(Builder settingsBuilder) throws IOException
listDatabaseOperationsSettings = settingsBuilder.listDatabaseOperationsSettings().build();
listBackupOperationsSettings = settingsBuilder.listBackupOperationsSettings().build();
listDatabaseRolesSettings = settingsBuilder.listDatabaseRolesSettings().build();
+ createBackupScheduleSettings = settingsBuilder.createBackupScheduleSettings().build();
+ getBackupScheduleSettings = settingsBuilder.getBackupScheduleSettings().build();
+ updateBackupScheduleSettings = settingsBuilder.updateBackupScheduleSettings().build();
+ deleteBackupScheduleSettings = settingsBuilder.deleteBackupScheduleSettings().build();
+ listBackupSchedulesSettings = settingsBuilder.listBackupSchedulesSettings().build();
}
/** Builder for DatabaseAdminStubSettings. */
@@ -836,6 +951,19 @@ public static class Builder extends StubSettings.Builder
listDatabaseRolesSettings;
+ private final UnaryCallSettings.Builder
+ createBackupScheduleSettings;
+ private final UnaryCallSettings.Builder
+ getBackupScheduleSettings;
+ private final UnaryCallSettings.Builder
+ updateBackupScheduleSettings;
+ private final UnaryCallSettings.Builder
+ deleteBackupScheduleSettings;
+ private final PagedCallSettings.Builder<
+ ListBackupSchedulesRequest,
+ ListBackupSchedulesResponse,
+ ListBackupSchedulesPagedResponse>
+ listBackupSchedulesSettings;
private static final ImmutableMap>
RETRYABLE_CODE_DEFINITIONS;
@@ -940,6 +1068,12 @@ protected Builder(ClientContext clientContext) {
listBackupOperationsSettings =
PagedCallSettings.newBuilder(LIST_BACKUP_OPERATIONS_PAGE_STR_FACT);
listDatabaseRolesSettings = PagedCallSettings.newBuilder(LIST_DATABASE_ROLES_PAGE_STR_FACT);
+ createBackupScheduleSettings = UnaryCallSettings.newUnaryCallSettingsBuilder();
+ getBackupScheduleSettings = UnaryCallSettings.newUnaryCallSettingsBuilder();
+ updateBackupScheduleSettings = UnaryCallSettings.newUnaryCallSettingsBuilder();
+ deleteBackupScheduleSettings = UnaryCallSettings.newUnaryCallSettingsBuilder();
+ listBackupSchedulesSettings =
+ PagedCallSettings.newBuilder(LIST_BACKUP_SCHEDULES_PAGE_STR_FACT);
unaryMethodSettingsBuilders =
ImmutableList.>of(
@@ -962,7 +1096,12 @@ protected Builder(ClientContext clientContext) {
restoreDatabaseSettings,
listDatabaseOperationsSettings,
listBackupOperationsSettings,
- listDatabaseRolesSettings);
+ listDatabaseRolesSettings,
+ createBackupScheduleSettings,
+ getBackupScheduleSettings,
+ updateBackupScheduleSettings,
+ deleteBackupScheduleSettings,
+ listBackupSchedulesSettings);
initDefaults(this);
}
@@ -995,6 +1134,11 @@ protected Builder(DatabaseAdminStubSettings settings) {
listDatabaseOperationsSettings = settings.listDatabaseOperationsSettings.toBuilder();
listBackupOperationsSettings = settings.listBackupOperationsSettings.toBuilder();
listDatabaseRolesSettings = settings.listDatabaseRolesSettings.toBuilder();
+ createBackupScheduleSettings = settings.createBackupScheduleSettings.toBuilder();
+ getBackupScheduleSettings = settings.getBackupScheduleSettings.toBuilder();
+ updateBackupScheduleSettings = settings.updateBackupScheduleSettings.toBuilder();
+ deleteBackupScheduleSettings = settings.deleteBackupScheduleSettings.toBuilder();
+ listBackupSchedulesSettings = settings.listBackupSchedulesSettings.toBuilder();
unaryMethodSettingsBuilders =
ImmutableList.>of(
@@ -1017,7 +1161,12 @@ protected Builder(DatabaseAdminStubSettings settings) {
restoreDatabaseSettings,
listDatabaseOperationsSettings,
listBackupOperationsSettings,
- listDatabaseRolesSettings);
+ listDatabaseRolesSettings,
+ createBackupScheduleSettings,
+ getBackupScheduleSettings,
+ updateBackupScheduleSettings,
+ deleteBackupScheduleSettings,
+ listBackupSchedulesSettings);
}
private static Builder createDefault() {
@@ -1145,6 +1294,31 @@ private static Builder initDefaults(Builder builder) {
.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_0_codes"))
.setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_0_params"));
+ builder
+ .createBackupScheduleSettings()
+ .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_0_codes"))
+ .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_0_params"));
+
+ builder
+ .getBackupScheduleSettings()
+ .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_0_codes"))
+ .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_0_params"));
+
+ builder
+ .updateBackupScheduleSettings()
+ .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_0_codes"))
+ .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_0_params"));
+
+ builder
+ .deleteBackupScheduleSettings()
+ .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_0_codes"))
+ .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_0_params"));
+
+ builder
+ .listBackupSchedulesSettings()
+ .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_0_codes"))
+ .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_0_params"));
+
builder
.createDatabaseOperationSettings()
.setInitialCallSettings(
@@ -1460,6 +1634,39 @@ public UnaryCallSettings.Builder restoreDatab
return listDatabaseRolesSettings;
}
+ /** Returns the builder for the settings used for calls to createBackupSchedule. */
+ public UnaryCallSettings.Builder
+ createBackupScheduleSettings() {
+ return createBackupScheduleSettings;
+ }
+
+ /** Returns the builder for the settings used for calls to getBackupSchedule. */
+ public UnaryCallSettings.Builder
+ getBackupScheduleSettings() {
+ return getBackupScheduleSettings;
+ }
+
+ /** Returns the builder for the settings used for calls to updateBackupSchedule. */
+ public UnaryCallSettings.Builder
+ updateBackupScheduleSettings() {
+ return updateBackupScheduleSettings;
+ }
+
+ /** Returns the builder for the settings used for calls to deleteBackupSchedule. */
+ public UnaryCallSettings.Builder
+ deleteBackupScheduleSettings() {
+ return deleteBackupScheduleSettings;
+ }
+
+ /** Returns the builder for the settings used for calls to listBackupSchedules. */
+ public PagedCallSettings.Builder<
+ ListBackupSchedulesRequest,
+ ListBackupSchedulesResponse,
+ ListBackupSchedulesPagedResponse>
+ listBackupSchedulesSettings() {
+ return listBackupSchedulesSettings;
+ }
+
@Override
public DatabaseAdminStubSettings build() throws IOException {
return new DatabaseAdminStubSettings(this);
diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/database/v1/stub/GrpcDatabaseAdminStub.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/database/v1/stub/GrpcDatabaseAdminStub.java
index 875ff8443fc..8207ebcbce5 100644
--- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/database/v1/stub/GrpcDatabaseAdminStub.java
+++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/database/v1/stub/GrpcDatabaseAdminStub.java
@@ -17,6 +17,7 @@
package com.google.cloud.spanner.admin.database.v1.stub;
import static com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient.ListBackupOperationsPagedResponse;
+import static com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient.ListBackupSchedulesPagedResponse;
import static com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient.ListBackupsPagedResponse;
import static com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient.ListDatabaseOperationsPagedResponse;
import static com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient.ListDatabaseRolesPagedResponse;
@@ -39,21 +40,27 @@
import com.google.longrunning.stub.GrpcOperationsStub;
import com.google.protobuf.Empty;
import com.google.spanner.admin.database.v1.Backup;
+import com.google.spanner.admin.database.v1.BackupSchedule;
import com.google.spanner.admin.database.v1.CopyBackupMetadata;
import com.google.spanner.admin.database.v1.CopyBackupRequest;
import com.google.spanner.admin.database.v1.CreateBackupMetadata;
import com.google.spanner.admin.database.v1.CreateBackupRequest;
+import com.google.spanner.admin.database.v1.CreateBackupScheduleRequest;
import com.google.spanner.admin.database.v1.CreateDatabaseMetadata;
import com.google.spanner.admin.database.v1.CreateDatabaseRequest;
import com.google.spanner.admin.database.v1.Database;
import com.google.spanner.admin.database.v1.DeleteBackupRequest;
+import com.google.spanner.admin.database.v1.DeleteBackupScheduleRequest;
import com.google.spanner.admin.database.v1.DropDatabaseRequest;
import com.google.spanner.admin.database.v1.GetBackupRequest;
+import com.google.spanner.admin.database.v1.GetBackupScheduleRequest;
import com.google.spanner.admin.database.v1.GetDatabaseDdlRequest;
import com.google.spanner.admin.database.v1.GetDatabaseDdlResponse;
import com.google.spanner.admin.database.v1.GetDatabaseRequest;
import com.google.spanner.admin.database.v1.ListBackupOperationsRequest;
import com.google.spanner.admin.database.v1.ListBackupOperationsResponse;
+import com.google.spanner.admin.database.v1.ListBackupSchedulesRequest;
+import com.google.spanner.admin.database.v1.ListBackupSchedulesResponse;
import com.google.spanner.admin.database.v1.ListBackupsRequest;
import com.google.spanner.admin.database.v1.ListBackupsResponse;
import com.google.spanner.admin.database.v1.ListDatabaseOperationsRequest;
@@ -65,6 +72,7 @@
import com.google.spanner.admin.database.v1.RestoreDatabaseMetadata;
import com.google.spanner.admin.database.v1.RestoreDatabaseRequest;
import com.google.spanner.admin.database.v1.UpdateBackupRequest;
+import com.google.spanner.admin.database.v1.UpdateBackupScheduleRequest;
import com.google.spanner.admin.database.v1.UpdateDatabaseDdlMetadata;
import com.google.spanner.admin.database.v1.UpdateDatabaseDdlRequest;
import com.google.spanner.admin.database.v1.UpdateDatabaseMetadata;
@@ -277,6 +285,61 @@ public class GrpcDatabaseAdminStub extends DatabaseAdminStub {
ProtoUtils.marshaller(ListDatabaseRolesResponse.getDefaultInstance()))
.build();
+ private static final MethodDescriptor
+ createBackupScheduleMethodDescriptor =
+ MethodDescriptor.newBuilder()
+ .setType(MethodDescriptor.MethodType.UNARY)
+ .setFullMethodName(
+ "google.spanner.admin.database.v1.DatabaseAdmin/CreateBackupSchedule")
+ .setRequestMarshaller(
+ ProtoUtils.marshaller(CreateBackupScheduleRequest.getDefaultInstance()))
+ .setResponseMarshaller(ProtoUtils.marshaller(BackupSchedule.getDefaultInstance()))
+ .build();
+
+ private static final MethodDescriptor
+ getBackupScheduleMethodDescriptor =
+ MethodDescriptor.newBuilder()
+ .setType(MethodDescriptor.MethodType.UNARY)
+ .setFullMethodName("google.spanner.admin.database.v1.DatabaseAdmin/GetBackupSchedule")
+ .setRequestMarshaller(
+ ProtoUtils.marshaller(GetBackupScheduleRequest.getDefaultInstance()))
+ .setResponseMarshaller(ProtoUtils.marshaller(BackupSchedule.getDefaultInstance()))
+ .build();
+
+ private static final MethodDescriptor
+ updateBackupScheduleMethodDescriptor =
+ MethodDescriptor.newBuilder()
+ .setType(MethodDescriptor.MethodType.UNARY)
+ .setFullMethodName(
+ "google.spanner.admin.database.v1.DatabaseAdmin/UpdateBackupSchedule")
+ .setRequestMarshaller(
+ ProtoUtils.marshaller(UpdateBackupScheduleRequest.getDefaultInstance()))
+ .setResponseMarshaller(ProtoUtils.marshaller(BackupSchedule.getDefaultInstance()))
+ .build();
+
+ private static final MethodDescriptor
+ deleteBackupScheduleMethodDescriptor =
+ MethodDescriptor.newBuilder()
+ .setType(MethodDescriptor.MethodType.UNARY)
+ .setFullMethodName(
+ "google.spanner.admin.database.v1.DatabaseAdmin/DeleteBackupSchedule")
+ .setRequestMarshaller(
+ ProtoUtils.marshaller(DeleteBackupScheduleRequest.getDefaultInstance()))
+ .setResponseMarshaller(ProtoUtils.marshaller(Empty.getDefaultInstance()))
+ .build();
+
+ private static final MethodDescriptor
+ listBackupSchedulesMethodDescriptor =
+ MethodDescriptor.newBuilder()
+ .setType(MethodDescriptor.MethodType.UNARY)
+ .setFullMethodName(
+ "google.spanner.admin.database.v1.DatabaseAdmin/ListBackupSchedules")
+ .setRequestMarshaller(
+ ProtoUtils.marshaller(ListBackupSchedulesRequest.getDefaultInstance()))
+ .setResponseMarshaller(
+ ProtoUtils.marshaller(ListBackupSchedulesResponse.getDefaultInstance()))
+ .build();
+
private final UnaryCallable listDatabasesCallable;
private final UnaryCallable
listDatabasesPagedCallable;
@@ -323,6 +386,16 @@ public class GrpcDatabaseAdminStub extends DatabaseAdminStub {
listDatabaseRolesCallable;
private final UnaryCallable
listDatabaseRolesPagedCallable;
+ private final UnaryCallable
+ createBackupScheduleCallable;
+ private final UnaryCallable getBackupScheduleCallable;
+ private final UnaryCallable
+ updateBackupScheduleCallable;
+ private final UnaryCallable deleteBackupScheduleCallable;
+ private final UnaryCallable
+ listBackupSchedulesCallable;
+ private final UnaryCallable
+ listBackupSchedulesPagedCallable;
private final BackgroundResource backgroundResources;
private final GrpcOperationsStub operationsStub;
@@ -572,6 +645,61 @@ protected GrpcDatabaseAdminStub(
return builder.build();
})
.build();
+ GrpcCallSettings
+ createBackupScheduleTransportSettings =
+ GrpcCallSettings.newBuilder()
+ .setMethodDescriptor(createBackupScheduleMethodDescriptor)
+ .setParamsExtractor(
+ request -> {
+ RequestParamsBuilder builder = RequestParamsBuilder.create();
+ builder.add("parent", String.valueOf(request.getParent()));
+ return builder.build();
+ })
+ .build();
+ GrpcCallSettings getBackupScheduleTransportSettings =
+ GrpcCallSettings.newBuilder()
+ .setMethodDescriptor(getBackupScheduleMethodDescriptor)
+ .setParamsExtractor(
+ request -> {
+ RequestParamsBuilder builder = RequestParamsBuilder.create();
+ builder.add("name", String.valueOf(request.getName()));
+ return builder.build();
+ })
+ .build();
+ GrpcCallSettings
+ updateBackupScheduleTransportSettings =
+ GrpcCallSettings.newBuilder()
+ .setMethodDescriptor(updateBackupScheduleMethodDescriptor)
+ .setParamsExtractor(
+ request -> {
+ RequestParamsBuilder builder = RequestParamsBuilder.create();
+ builder.add(
+ "backup_schedule.name",
+ String.valueOf(request.getBackupSchedule().getName()));
+ return builder.build();
+ })
+ .build();
+ GrpcCallSettings deleteBackupScheduleTransportSettings =
+ GrpcCallSettings.newBuilder()
+ .setMethodDescriptor(deleteBackupScheduleMethodDescriptor)
+ .setParamsExtractor(
+ request -> {
+ RequestParamsBuilder builder = RequestParamsBuilder.create();
+ builder.add("name", String.valueOf(request.getName()));
+ return builder.build();
+ })
+ .build();
+ GrpcCallSettings
+ listBackupSchedulesTransportSettings =
+ GrpcCallSettings.newBuilder()
+ .setMethodDescriptor(listBackupSchedulesMethodDescriptor)
+ .setParamsExtractor(
+ request -> {
+ RequestParamsBuilder builder = RequestParamsBuilder.create();
+ builder.add("parent", String.valueOf(request.getParent()));
+ return builder.build();
+ })
+ .build();
this.listDatabasesCallable =
callableFactory.createUnaryCallable(
@@ -700,6 +828,36 @@ protected GrpcDatabaseAdminStub(
listDatabaseRolesTransportSettings,
settings.listDatabaseRolesSettings(),
clientContext);
+ this.createBackupScheduleCallable =
+ callableFactory.createUnaryCallable(
+ createBackupScheduleTransportSettings,
+ settings.createBackupScheduleSettings(),
+ clientContext);
+ this.getBackupScheduleCallable =
+ callableFactory.createUnaryCallable(
+ getBackupScheduleTransportSettings,
+ settings.getBackupScheduleSettings(),
+ clientContext);
+ this.updateBackupScheduleCallable =
+ callableFactory.createUnaryCallable(
+ updateBackupScheduleTransportSettings,
+ settings.updateBackupScheduleSettings(),
+ clientContext);
+ this.deleteBackupScheduleCallable =
+ callableFactory.createUnaryCallable(
+ deleteBackupScheduleTransportSettings,
+ settings.deleteBackupScheduleSettings(),
+ clientContext);
+ this.listBackupSchedulesCallable =
+ callableFactory.createUnaryCallable(
+ listBackupSchedulesTransportSettings,
+ settings.listBackupSchedulesSettings(),
+ clientContext);
+ this.listBackupSchedulesPagedCallable =
+ callableFactory.createPagedCallable(
+ listBackupSchedulesTransportSettings,
+ settings.listBackupSchedulesSettings(),
+ clientContext);
this.backgroundResources =
new BackgroundResourceAggregation(clientContext.getBackgroundResources());
@@ -878,6 +1036,38 @@ public UnaryCallable restoreDatabaseCallable(
return listDatabaseRolesPagedCallable;
}
+ @Override
+ public UnaryCallable createBackupScheduleCallable() {
+ return createBackupScheduleCallable;
+ }
+
+ @Override
+ public UnaryCallable getBackupScheduleCallable() {
+ return getBackupScheduleCallable;
+ }
+
+ @Override
+ public UnaryCallable updateBackupScheduleCallable() {
+ return updateBackupScheduleCallable;
+ }
+
+ @Override
+ public UnaryCallable deleteBackupScheduleCallable() {
+ return deleteBackupScheduleCallable;
+ }
+
+ @Override
+ public UnaryCallable
+ listBackupSchedulesCallable() {
+ return listBackupSchedulesCallable;
+ }
+
+ @Override
+ public UnaryCallable
+ listBackupSchedulesPagedCallable() {
+ return listBackupSchedulesPagedCallable;
+ }
+
@Override
public final void close() {
try {
diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/database/v1/stub/HttpJsonDatabaseAdminStub.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/database/v1/stub/HttpJsonDatabaseAdminStub.java
index 1eaa5055133..fbe9f02b1f8 100644
--- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/database/v1/stub/HttpJsonDatabaseAdminStub.java
+++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/database/v1/stub/HttpJsonDatabaseAdminStub.java
@@ -17,6 +17,7 @@
package com.google.cloud.spanner.admin.database.v1.stub;
import static com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient.ListBackupOperationsPagedResponse;
+import static com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient.ListBackupSchedulesPagedResponse;
import static com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient.ListBackupsPagedResponse;
import static com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient.ListDatabaseOperationsPagedResponse;
import static com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient.ListDatabaseRolesPagedResponse;
@@ -48,21 +49,27 @@
import com.google.protobuf.Empty;
import com.google.protobuf.TypeRegistry;
import com.google.spanner.admin.database.v1.Backup;
+import com.google.spanner.admin.database.v1.BackupSchedule;
import com.google.spanner.admin.database.v1.CopyBackupMetadata;
import com.google.spanner.admin.database.v1.CopyBackupRequest;
import com.google.spanner.admin.database.v1.CreateBackupMetadata;
import com.google.spanner.admin.database.v1.CreateBackupRequest;
+import com.google.spanner.admin.database.v1.CreateBackupScheduleRequest;
import com.google.spanner.admin.database.v1.CreateDatabaseMetadata;
import com.google.spanner.admin.database.v1.CreateDatabaseRequest;
import com.google.spanner.admin.database.v1.Database;
import com.google.spanner.admin.database.v1.DeleteBackupRequest;
+import com.google.spanner.admin.database.v1.DeleteBackupScheduleRequest;
import com.google.spanner.admin.database.v1.DropDatabaseRequest;
import com.google.spanner.admin.database.v1.GetBackupRequest;
+import com.google.spanner.admin.database.v1.GetBackupScheduleRequest;
import com.google.spanner.admin.database.v1.GetDatabaseDdlRequest;
import com.google.spanner.admin.database.v1.GetDatabaseDdlResponse;
import com.google.spanner.admin.database.v1.GetDatabaseRequest;
import com.google.spanner.admin.database.v1.ListBackupOperationsRequest;
import com.google.spanner.admin.database.v1.ListBackupOperationsResponse;
+import com.google.spanner.admin.database.v1.ListBackupSchedulesRequest;
+import com.google.spanner.admin.database.v1.ListBackupSchedulesResponse;
import com.google.spanner.admin.database.v1.ListBackupsRequest;
import com.google.spanner.admin.database.v1.ListBackupsResponse;
import com.google.spanner.admin.database.v1.ListDatabaseOperationsRequest;
@@ -74,6 +81,7 @@
import com.google.spanner.admin.database.v1.RestoreDatabaseMetadata;
import com.google.spanner.admin.database.v1.RestoreDatabaseRequest;
import com.google.spanner.admin.database.v1.UpdateBackupRequest;
+import com.google.spanner.admin.database.v1.UpdateBackupScheduleRequest;
import com.google.spanner.admin.database.v1.UpdateDatabaseDdlMetadata;
import com.google.spanner.admin.database.v1.UpdateDatabaseDdlRequest;
import com.google.spanner.admin.database.v1.UpdateDatabaseMetadata;
@@ -385,7 +393,8 @@ public class HttpJsonDatabaseAdminStub extends DatabaseAdminStub {
return fields;
})
.setAdditionalPaths(
- "/v1/{resource=projects/*/instances/*/backups/*}:setIamPolicy")
+ "/v1/{resource=projects/*/instances/*/backups/*}:setIamPolicy",
+ "/v1/{resource=projects/*/instances/*/databases/*/backupSchedules/*}:setIamPolicy")
.setQueryParamsExtractor(
request -> {
Map> fields = new HashMap<>();
@@ -424,7 +433,8 @@ public class HttpJsonDatabaseAdminStub extends DatabaseAdminStub {
return fields;
})
.setAdditionalPaths(
- "/v1/{resource=projects/*/instances/*/backups/*}:getIamPolicy")
+ "/v1/{resource=projects/*/instances/*/backups/*}:getIamPolicy",
+ "/v1/{resource=projects/*/instances/*/databases/*/backupSchedules/*}:getIamPolicy")
.setQueryParamsExtractor(
request -> {
Map> fields = new HashMap<>();
@@ -465,6 +475,7 @@ public class HttpJsonDatabaseAdminStub extends DatabaseAdminStub {
})
.setAdditionalPaths(
"/v1/{resource=projects/*/instances/*/backups/*}:testIamPermissions",
+ "/v1/{resource=projects/*/instances/*/databases/*/backupSchedules/*}:testIamPermissions",
"/v1/{resource=projects/*/instances/*/databases/*/databaseRoles/*}:testIamPermissions")
.setQueryParamsExtractor(
request -> {
@@ -868,6 +879,194 @@ public class HttpJsonDatabaseAdminStub extends DatabaseAdminStub {
.build())
.build();
+ private static final ApiMethodDescriptor
+ createBackupScheduleMethodDescriptor =
+ ApiMethodDescriptor.newBuilder()
+ .setFullMethodName(
+ "google.spanner.admin.database.v1.DatabaseAdmin/CreateBackupSchedule")
+ .setHttpMethod("POST")
+ .setType(ApiMethodDescriptor.MethodType.UNARY)
+ .setRequestFormatter(
+ ProtoMessageRequestFormatter.newBuilder()
+ .setPath(
+ "/v1/{parent=projects/*/instances/*/databases/*}/backupSchedules",
+ request -> {
+ Map fields = new HashMap<>();
+ ProtoRestSerializer serializer =
+ ProtoRestSerializer.create();
+ serializer.putPathParam(fields, "parent", request.getParent());
+ return fields;
+ })
+ .setQueryParamsExtractor(
+ request -> {
+ Map> fields = new HashMap<>();
+ ProtoRestSerializer serializer =
+ ProtoRestSerializer.create();
+ serializer.putQueryParam(
+ fields, "backupScheduleId", request.getBackupScheduleId());
+ serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int");
+ return fields;
+ })
+ .setRequestBodyExtractor(
+ request ->
+ ProtoRestSerializer.create()
+ .toBody("backupSchedule", request.getBackupSchedule(), true))
+ .build())
+ .setResponseParser(
+ ProtoMessageResponseParser.newBuilder()
+ .setDefaultInstance(BackupSchedule.getDefaultInstance())
+ .setDefaultTypeRegistry(typeRegistry)
+ .build())
+ .build();
+
+ private static final ApiMethodDescriptor
+ getBackupScheduleMethodDescriptor =
+ ApiMethodDescriptor.newBuilder()
+ .setFullMethodName("google.spanner.admin.database.v1.DatabaseAdmin/GetBackupSchedule")
+ .setHttpMethod("GET")
+ .setType(ApiMethodDescriptor.MethodType.UNARY)
+ .setRequestFormatter(
+ ProtoMessageRequestFormatter.newBuilder()
+ .setPath(
+ "/v1/{name=projects/*/instances/*/databases/*/backupSchedules/*}",
+ request -> {
+ Map fields = new HashMap<>();
+ ProtoRestSerializer serializer =
+ ProtoRestSerializer.create();
+ serializer.putPathParam(fields, "name", request.getName());
+ return fields;
+ })
+ .setQueryParamsExtractor(
+ request -> {
+ Map> fields = new HashMap<>();
+ ProtoRestSerializer serializer =
+ ProtoRestSerializer.create();
+ serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int");
+ return fields;
+ })
+ .setRequestBodyExtractor(request -> null)
+ .build())
+ .setResponseParser(
+ ProtoMessageResponseParser.newBuilder()
+ .setDefaultInstance(BackupSchedule.getDefaultInstance())
+ .setDefaultTypeRegistry(typeRegistry)
+ .build())
+ .build();
+
+ private static final ApiMethodDescriptor
+ updateBackupScheduleMethodDescriptor =
+ ApiMethodDescriptor.newBuilder()
+ .setFullMethodName(
+ "google.spanner.admin.database.v1.DatabaseAdmin/UpdateBackupSchedule")
+ .setHttpMethod("PATCH")
+ .setType(ApiMethodDescriptor.MethodType.UNARY)
+ .setRequestFormatter(
+ ProtoMessageRequestFormatter.newBuilder()
+ .setPath(
+ "/v1/{backupSchedule.name=projects/*/instances/*/databases/*/backupSchedules/*}",
+ request -> {
+ Map fields = new HashMap<>();
+ ProtoRestSerializer serializer =
+ ProtoRestSerializer.create();
+ serializer.putPathParam(
+ fields,
+ "backupSchedule.name",
+ request.getBackupSchedule().getName());
+ return fields;
+ })
+ .setQueryParamsExtractor(
+ request -> {
+ Map> fields = new HashMap<>();
+ ProtoRestSerializer serializer =
+ ProtoRestSerializer.create();
+ serializer.putQueryParam(fields, "updateMask", request.getUpdateMask());
+ serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int");
+ return fields;
+ })
+ .setRequestBodyExtractor(
+ request ->
+ ProtoRestSerializer.create()
+ .toBody("backupSchedule", request.getBackupSchedule(), true))
+ .build())
+ .setResponseParser(
+ ProtoMessageResponseParser.newBuilder()
+ .setDefaultInstance(BackupSchedule.getDefaultInstance())
+ .setDefaultTypeRegistry(typeRegistry)
+ .build())
+ .build();
+
+ private static final ApiMethodDescriptor
+ deleteBackupScheduleMethodDescriptor =
+ ApiMethodDescriptor.newBuilder()
+ .setFullMethodName(
+ "google.spanner.admin.database.v1.DatabaseAdmin/DeleteBackupSchedule")
+ .setHttpMethod("DELETE")
+ .setType(ApiMethodDescriptor.MethodType.UNARY)
+ .setRequestFormatter(
+ ProtoMessageRequestFormatter.newBuilder()
+ .setPath(
+ "/v1/{name=projects/*/instances/*/databases/*/backupSchedules/*}",
+ request -> {
+ Map fields = new HashMap<>();
+ ProtoRestSerializer serializer =
+ ProtoRestSerializer.create();
+ serializer.putPathParam(fields, "name", request.getName());
+ return fields;
+ })
+ .setQueryParamsExtractor(
+ request -> {
+ Map> fields = new HashMap<>();
+ ProtoRestSerializer serializer =
+ ProtoRestSerializer.create();
+ serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int");
+ return fields;
+ })
+ .setRequestBodyExtractor(request -> null)
+ .build())
+ .setResponseParser(
+ ProtoMessageResponseParser.newBuilder()
+ .setDefaultInstance(Empty.getDefaultInstance())
+ .setDefaultTypeRegistry(typeRegistry)
+ .build())
+ .build();
+
+ private static final ApiMethodDescriptor
+ listBackupSchedulesMethodDescriptor =
+ ApiMethodDescriptor.newBuilder()
+ .setFullMethodName(
+ "google.spanner.admin.database.v1.DatabaseAdmin/ListBackupSchedules")
+ .setHttpMethod("GET")
+ .setType(ApiMethodDescriptor.MethodType.UNARY)
+ .setRequestFormatter(
+ ProtoMessageRequestFormatter.newBuilder()
+ .setPath(
+ "/v1/{parent=projects/*/instances/*/databases/*}/backupSchedules",
+ request -> {
+ Map fields = new HashMap<>();
+ ProtoRestSerializer serializer =
+ ProtoRestSerializer.create();
+ serializer.putPathParam(fields, "parent", request.getParent());
+ return fields;
+ })
+ .setQueryParamsExtractor(
+ request -> {
+ Map> fields = new HashMap<>();
+ ProtoRestSerializer serializer =
+ ProtoRestSerializer.create();
+ serializer.putQueryParam(fields, "pageSize", request.getPageSize());
+ serializer.putQueryParam(fields, "pageToken", request.getPageToken());
+ serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int");
+ return fields;
+ })
+ .setRequestBodyExtractor(request -> null)
+ .build())
+ .setResponseParser(
+ ProtoMessageResponseParser.newBuilder()
+ .setDefaultInstance(ListBackupSchedulesResponse.getDefaultInstance())
+ .setDefaultTypeRegistry(typeRegistry)
+ .build())
+ .build();
+
private final UnaryCallable listDatabasesCallable;
private final UnaryCallable
listDatabasesPagedCallable;
@@ -914,6 +1113,16 @@ public class HttpJsonDatabaseAdminStub extends DatabaseAdminStub {
listDatabaseRolesCallable;
private final UnaryCallable
listDatabaseRolesPagedCallable;
+ private final UnaryCallable
+ createBackupScheduleCallable;
+ private final UnaryCallable getBackupScheduleCallable;
+ private final UnaryCallable
+ updateBackupScheduleCallable;
+ private final UnaryCallable deleteBackupScheduleCallable;
+ private final UnaryCallable
+ listBackupSchedulesCallable;
+ private final UnaryCallable
+ listBackupSchedulesPagedCallable;
private final BackgroundResource backgroundResources;
private final HttpJsonOperationsStub httpJsonOperationsStub;
@@ -1265,6 +1474,68 @@ protected HttpJsonDatabaseAdminStub(
return builder.build();
})
.build();
+ HttpJsonCallSettings
+ createBackupScheduleTransportSettings =
+ HttpJsonCallSettings.newBuilder()
+ .setMethodDescriptor(createBackupScheduleMethodDescriptor)
+ .setTypeRegistry(typeRegistry)
+ .setParamsExtractor(
+ request -> {
+ RequestParamsBuilder builder = RequestParamsBuilder.create();
+ builder.add("parent", String.valueOf(request.getParent()));
+ return builder.build();
+ })
+ .build();
+ HttpJsonCallSettings
+ getBackupScheduleTransportSettings =
+ HttpJsonCallSettings.newBuilder()
+ .setMethodDescriptor(getBackupScheduleMethodDescriptor)
+ .setTypeRegistry(typeRegistry)
+ .setParamsExtractor(
+ request -> {
+ RequestParamsBuilder builder = RequestParamsBuilder.create();
+ builder.add("name", String.valueOf(request.getName()));
+ return builder.build();
+ })
+ .build();
+ HttpJsonCallSettings
+ updateBackupScheduleTransportSettings =
+ HttpJsonCallSettings.newBuilder()
+ .setMethodDescriptor(updateBackupScheduleMethodDescriptor)
+ .setTypeRegistry(typeRegistry)
+ .setParamsExtractor(
+ request -> {
+ RequestParamsBuilder builder = RequestParamsBuilder.create();
+ builder.add(
+ "backup_schedule.name",
+ String.valueOf(request.getBackupSchedule().getName()));
+ return builder.build();
+ })
+ .build();
+ HttpJsonCallSettings deleteBackupScheduleTransportSettings =
+ HttpJsonCallSettings.newBuilder()
+ .setMethodDescriptor(deleteBackupScheduleMethodDescriptor)
+ .setTypeRegistry(typeRegistry)
+ .setParamsExtractor(
+ request -> {
+ RequestParamsBuilder builder = RequestParamsBuilder.create();
+ builder.add("name", String.valueOf(request.getName()));
+ return builder.build();
+ })
+ .build();
+ HttpJsonCallSettings
+ listBackupSchedulesTransportSettings =
+ HttpJsonCallSettings
+ .newBuilder()
+ .setMethodDescriptor(listBackupSchedulesMethodDescriptor)
+ .setTypeRegistry(typeRegistry)
+ .setParamsExtractor(
+ request -> {
+ RequestParamsBuilder builder = RequestParamsBuilder.create();
+ builder.add("parent", String.valueOf(request.getParent()));
+ return builder.build();
+ })
+ .build();
this.listDatabasesCallable =
callableFactory.createUnaryCallable(
@@ -1393,6 +1664,36 @@ protected HttpJsonDatabaseAdminStub(
listDatabaseRolesTransportSettings,
settings.listDatabaseRolesSettings(),
clientContext);
+ this.createBackupScheduleCallable =
+ callableFactory.createUnaryCallable(
+ createBackupScheduleTransportSettings,
+ settings.createBackupScheduleSettings(),
+ clientContext);
+ this.getBackupScheduleCallable =
+ callableFactory.createUnaryCallable(
+ getBackupScheduleTransportSettings,
+ settings.getBackupScheduleSettings(),
+ clientContext);
+ this.updateBackupScheduleCallable =
+ callableFactory.createUnaryCallable(
+ updateBackupScheduleTransportSettings,
+ settings.updateBackupScheduleSettings(),
+ clientContext);
+ this.deleteBackupScheduleCallable =
+ callableFactory.createUnaryCallable(
+ deleteBackupScheduleTransportSettings,
+ settings.deleteBackupScheduleSettings(),
+ clientContext);
+ this.listBackupSchedulesCallable =
+ callableFactory.createUnaryCallable(
+ listBackupSchedulesTransportSettings,
+ settings.listBackupSchedulesSettings(),
+ clientContext);
+ this.listBackupSchedulesPagedCallable =
+ callableFactory.createPagedCallable(
+ listBackupSchedulesTransportSettings,
+ settings.listBackupSchedulesSettings(),
+ clientContext);
this.backgroundResources =
new BackgroundResourceAggregation(clientContext.getBackgroundResources());
@@ -1421,6 +1722,11 @@ public static List getMethodDescriptors() {
methodDescriptors.add(listDatabaseOperationsMethodDescriptor);
methodDescriptors.add(listBackupOperationsMethodDescriptor);
methodDescriptors.add(listDatabaseRolesMethodDescriptor);
+ methodDescriptors.add(createBackupScheduleMethodDescriptor);
+ methodDescriptors.add(getBackupScheduleMethodDescriptor);
+ methodDescriptors.add(updateBackupScheduleMethodDescriptor);
+ methodDescriptors.add(deleteBackupScheduleMethodDescriptor);
+ methodDescriptors.add(listBackupSchedulesMethodDescriptor);
return methodDescriptors;
}
@@ -1597,6 +1903,38 @@ public UnaryCallable restoreDatabaseCallable(
return listDatabaseRolesPagedCallable;
}
+ @Override
+ public UnaryCallable createBackupScheduleCallable() {
+ return createBackupScheduleCallable;
+ }
+
+ @Override
+ public UnaryCallable getBackupScheduleCallable() {
+ return getBackupScheduleCallable;
+ }
+
+ @Override
+ public UnaryCallable updateBackupScheduleCallable() {
+ return updateBackupScheduleCallable;
+ }
+
+ @Override
+ public UnaryCallable deleteBackupScheduleCallable() {
+ return deleteBackupScheduleCallable;
+ }
+
+ @Override
+ public UnaryCallable
+ listBackupSchedulesCallable() {
+ return listBackupSchedulesCallable;
+ }
+
+ @Override
+ public UnaryCallable
+ listBackupSchedulesPagedCallable() {
+ return listBackupSchedulesPagedCallable;
+ }
+
@Override
public final void close() {
try {
diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/instance/v1/stub/InstanceAdminStubSettings.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/instance/v1/stub/InstanceAdminStubSettings.java
index 9a00b312c61..a74094a3149 100644
--- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/instance/v1/stub/InstanceAdminStubSettings.java
+++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/instance/v1/stub/InstanceAdminStubSettings.java
@@ -25,6 +25,7 @@
import com.google.api.core.ApiFunction;
import com.google.api.core.ApiFuture;
import com.google.api.core.BetaApi;
+import com.google.api.core.ObsoleteApi;
import com.google.api.gax.core.GaxProperties;
import com.google.api.gax.core.GoogleCredentialsProvider;
import com.google.api.gax.core.InstantiatingExecutorProvider;
@@ -738,6 +739,7 @@ public static InstantiatingExecutorProvider.Builder defaultExecutorProviderBuild
}
/** Returns the default service endpoint. */
+ @ObsoleteApi("Use getEndpoint() instead")
public static String getDefaultEndpoint() {
return "spanner.googleapis.com:443";
}
diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/ReadWriteTransaction.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/ReadWriteTransaction.java
index 520a2e180e5..0362ffc2050 100644
--- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/ReadWriteTransaction.java
+++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/ReadWriteTransaction.java
@@ -461,7 +461,10 @@ public void run() {
CallType.SYNC,
SELECT1_STATEMENT,
AnalyzeMode.NONE,
- Options.tag("connection.transaction-keep-alive"));
+ Options.tag(
+ System.getProperty(
+ "spanner.connection.keep_alive_query_tag",
+ "connection.transaction-keep-alive")));
future.addListener(
ReadWriteTransaction.this::maybeScheduleKeepAlivePing, MoreExecutors.directExecutor());
}
diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/GapicSpannerRpc.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/GapicSpannerRpc.java
index b6016f04f78..00ae72f169a 100644
--- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/GapicSpannerRpc.java
+++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/GapicSpannerRpc.java
@@ -56,6 +56,7 @@
import com.google.api.pathtemplate.PathTemplate;
import com.google.cloud.RetryHelper;
import com.google.cloud.RetryHelper.RetryHelperException;
+import com.google.cloud.grpc.GcpManagedChannel;
import com.google.cloud.grpc.GcpManagedChannelBuilder;
import com.google.cloud.grpc.GcpManagedChannelOptions;
import com.google.cloud.grpc.GcpManagedChannelOptions.GcpMetricsOptions;
@@ -240,6 +241,7 @@ public class GapicSpannerRpc implements SpannerRpc {
private final Set executeQueryRetryableCodes;
private final RetrySettings readRetrySettings;
private final Set readRetryableCodes;
+ private final RetrySettings commitRetrySettings;
private final SpannerStub partitionedDmlStub;
private final RetrySettings partitionedDmlRetrySettings;
private final InstanceAdminStubSettings instanceAdminStubSettings;
@@ -266,6 +268,8 @@ public class GapicSpannerRpc implements SpannerRpc {
private static final ConcurrentMap ADMINISTRATIVE_REQUESTS_RATE_LIMITERS =
new ConcurrentHashMap<>();
private final boolean leaderAwareRoutingEnabled;
+ private final int numChannels;
+ private final boolean isGrpcGcpExtensionEnabled;
public static GapicSpannerRpc create(SpannerOptions options) {
return new GapicSpannerRpc(options);
@@ -317,6 +321,8 @@ public GapicSpannerRpc(final SpannerOptions options) {
this.callCredentialsProvider = options.getCallCredentialsProvider();
this.compressorName = options.getCompressorName();
this.leaderAwareRoutingEnabled = options.isLeaderAwareRoutingEnabled();
+ this.numChannels = options.getNumChannels();
+ this.isGrpcGcpExtensionEnabled = options.isGrpcGcpExtensionEnabled();
if (initializeStubs) {
// First check if SpannerOptions provides a TransportChannelProvider. Create one
@@ -398,6 +404,8 @@ public GapicSpannerRpc(final SpannerOptions options) {
options.getSpannerStubSettings().executeStreamingSqlSettings().getRetrySettings();
this.executeQueryRetryableCodes =
options.getSpannerStubSettings().executeStreamingSqlSettings().getRetryableCodes();
+ this.commitRetrySettings =
+ options.getSpannerStubSettings().commitSettings().getRetrySettings();
partitionedDmlRetrySettings =
options
.getSpannerStubSettings()
@@ -508,6 +516,8 @@ public UnaryCallable createUnaryCalla
this.readRetryableCodes = null;
this.executeQueryRetrySettings = null;
this.executeQueryRetryableCodes = null;
+ this.commitRetrySettings =
+ SpannerStubSettings.newBuilder().commitSettings().getRetrySettings();
this.partitionedDmlStub = null;
this.databaseAdminStubSettings = null;
this.instanceAdminStubSettings = null;
@@ -1801,6 +1811,11 @@ public CommitResponse commit(CommitRequest commitRequest, @Nullable Map rollbackAsync(RollbackRequest request, @Nullable Map options) {
GrpcCallContext context =
@@ -1950,7 +1965,20 @@ GrpcCallContext newCallContext(
boolean routeToLeader) {
GrpcCallContext context = GrpcCallContext.createDefault();
if (options != null) {
- context = context.withChannelAffinity(Option.CHANNEL_HINT.getLong(options).intValue());
+ if (this.isGrpcGcpExtensionEnabled) {
+ // Set channel affinity in gRPC-GCP.
+ // Compute bounded channel hint to prevent gRPC-GCP affinity map from getting unbounded.
+ int boundedChannelHint = Option.CHANNEL_HINT.getLong(options).intValue() % this.numChannels;
+ context =
+ context.withCallOptions(
+ context
+ .getCallOptions()
+ .withOption(
+ GcpManagedChannel.AFFINITY_KEY, String.valueOf(boundedChannelHint)));
+ } else {
+ // Set channel affinity in GAX.
+ context = context.withChannelAffinity(Option.CHANNEL_HINT.getLong(options).intValue());
+ }
}
if (compressorName != null) {
// This sets the compressor for Client -> Server.
diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/SpannerRpc.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/SpannerRpc.java
index f063a7a3138..f07a28fb918 100644
--- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/SpannerRpc.java
+++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/SpannerRpc.java
@@ -469,6 +469,10 @@ CommitResponse commit(CommitRequest commitRequest, @Nullable Map opti
ApiFuture commitAsync(
CommitRequest commitRequest, @Nullable Map options);
+ default RetrySettings getCommitRetrySettings() {
+ return SpannerStubSettings.newBuilder().commitSettings().getRetrySettings();
+ }
+
void rollback(RollbackRequest request, @Nullable Map options) throws SpannerException;
ApiFuture rollbackAsync(RollbackRequest request, @Nullable Map options);
diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/v1/stub/SpannerStubSettings.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/v1/stub/SpannerStubSettings.java
index db96f17542a..fa6b86633b3 100644
--- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/v1/stub/SpannerStubSettings.java
+++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/v1/stub/SpannerStubSettings.java
@@ -21,6 +21,7 @@
import com.google.api.core.ApiFunction;
import com.google.api.core.ApiFuture;
import com.google.api.core.BetaApi;
+import com.google.api.core.ObsoleteApi;
import com.google.api.gax.core.GaxProperties;
import com.google.api.gax.core.GoogleCredentialsProvider;
import com.google.api.gax.core.InstantiatingExecutorProvider;
@@ -311,6 +312,7 @@ public static InstantiatingExecutorProvider.Builder defaultExecutorProviderBuild
}
/** Returns the default service endpoint. */
+ @ObsoleteApi("Use getEndpoint() instead")
public static String getDefaultEndpoint() {
return "spanner.googleapis.com:443";
}
diff --git a/google-cloud-spanner/src/main/resources/META-INF/native-image/com.google.cloud.spanner.admin.database.v1/reflect-config.json b/google-cloud-spanner/src/main/resources/META-INF/native-image/com.google.cloud.spanner.admin.database.v1/reflect-config.json
index 9518d8b2191..37bd9977c19 100644
--- a/google-cloud-spanner/src/main/resources/META-INF/native-image/com.google.cloud.spanner.admin.database.v1/reflect-config.json
+++ b/google-cloud-spanner/src/main/resources/META-INF/native-image/com.google.cloud.spanner.admin.database.v1/reflect-config.json
@@ -1646,6 +1646,42 @@
"allDeclaredClasses": true,
"allPublicClasses": true
},
+ {
+ "name": "com.google.spanner.admin.database.v1.BackupSchedule",
+ "queryAllDeclaredConstructors": true,
+ "queryAllPublicConstructors": true,
+ "queryAllDeclaredMethods": true,
+ "allPublicMethods": true,
+ "allDeclaredClasses": true,
+ "allPublicClasses": true
+ },
+ {
+ "name": "com.google.spanner.admin.database.v1.BackupSchedule$Builder",
+ "queryAllDeclaredConstructors": true,
+ "queryAllPublicConstructors": true,
+ "queryAllDeclaredMethods": true,
+ "allPublicMethods": true,
+ "allDeclaredClasses": true,
+ "allPublicClasses": true
+ },
+ {
+ "name": "com.google.spanner.admin.database.v1.BackupScheduleSpec",
+ "queryAllDeclaredConstructors": true,
+ "queryAllPublicConstructors": true,
+ "queryAllDeclaredMethods": true,
+ "allPublicMethods": true,
+ "allDeclaredClasses": true,
+ "allPublicClasses": true
+ },
+ {
+ "name": "com.google.spanner.admin.database.v1.BackupScheduleSpec$Builder",
+ "queryAllDeclaredConstructors": true,
+ "queryAllPublicConstructors": true,
+ "queryAllDeclaredMethods": true,
+ "allPublicMethods": true,
+ "allDeclaredClasses": true,
+ "allPublicClasses": true
+ },
{
"name": "com.google.spanner.admin.database.v1.CopyBackupEncryptionConfig",
"queryAllDeclaredConstructors": true,
@@ -1772,6 +1808,24 @@
"allDeclaredClasses": true,
"allPublicClasses": true
},
+ {
+ "name": "com.google.spanner.admin.database.v1.CreateBackupScheduleRequest",
+ "queryAllDeclaredConstructors": true,
+ "queryAllPublicConstructors": true,
+ "queryAllDeclaredMethods": true,
+ "allPublicMethods": true,
+ "allDeclaredClasses": true,
+ "allPublicClasses": true
+ },
+ {
+ "name": "com.google.spanner.admin.database.v1.CreateBackupScheduleRequest$Builder",
+ "queryAllDeclaredConstructors": true,
+ "queryAllPublicConstructors": true,
+ "queryAllDeclaredMethods": true,
+ "allPublicMethods": true,
+ "allDeclaredClasses": true,
+ "allPublicClasses": true
+ },
{
"name": "com.google.spanner.admin.database.v1.CreateDatabaseMetadata",
"queryAllDeclaredConstructors": true,
@@ -1808,6 +1862,24 @@
"allDeclaredClasses": true,
"allPublicClasses": true
},
+ {
+ "name": "com.google.spanner.admin.database.v1.CrontabSpec",
+ "queryAllDeclaredConstructors": true,
+ "queryAllPublicConstructors": true,
+ "queryAllDeclaredMethods": true,
+ "allPublicMethods": true,
+ "allDeclaredClasses": true,
+ "allPublicClasses": true
+ },
+ {
+ "name": "com.google.spanner.admin.database.v1.CrontabSpec$Builder",
+ "queryAllDeclaredConstructors": true,
+ "queryAllPublicConstructors": true,
+ "queryAllDeclaredMethods": true,
+ "allPublicMethods": true,
+ "allDeclaredClasses": true,
+ "allPublicClasses": true
+ },
{
"name": "com.google.spanner.admin.database.v1.Database",
"queryAllDeclaredConstructors": true,
@@ -1898,6 +1970,24 @@
"allDeclaredClasses": true,
"allPublicClasses": true
},
+ {
+ "name": "com.google.spanner.admin.database.v1.DeleteBackupScheduleRequest",
+ "queryAllDeclaredConstructors": true,
+ "queryAllPublicConstructors": true,
+ "queryAllDeclaredMethods": true,
+ "allPublicMethods": true,
+ "allDeclaredClasses": true,
+ "allPublicClasses": true
+ },
+ {
+ "name": "com.google.spanner.admin.database.v1.DeleteBackupScheduleRequest$Builder",
+ "queryAllDeclaredConstructors": true,
+ "queryAllPublicConstructors": true,
+ "queryAllDeclaredMethods": true,
+ "allPublicMethods": true,
+ "allDeclaredClasses": true,
+ "allPublicClasses": true
+ },
{
"name": "com.google.spanner.admin.database.v1.DropDatabaseRequest",
"queryAllDeclaredConstructors": true,
@@ -1961,6 +2051,24 @@
"allDeclaredClasses": true,
"allPublicClasses": true
},
+ {
+ "name": "com.google.spanner.admin.database.v1.FullBackupSpec",
+ "queryAllDeclaredConstructors": true,
+ "queryAllPublicConstructors": true,
+ "queryAllDeclaredMethods": true,
+ "allPublicMethods": true,
+ "allDeclaredClasses": true,
+ "allPublicClasses": true
+ },
+ {
+ "name": "com.google.spanner.admin.database.v1.FullBackupSpec$Builder",
+ "queryAllDeclaredConstructors": true,
+ "queryAllPublicConstructors": true,
+ "queryAllDeclaredMethods": true,
+ "allPublicMethods": true,
+ "allDeclaredClasses": true,
+ "allPublicClasses": true
+ },
{
"name": "com.google.spanner.admin.database.v1.GetBackupRequest",
"queryAllDeclaredConstructors": true,
@@ -1979,6 +2087,24 @@
"allDeclaredClasses": true,
"allPublicClasses": true
},
+ {
+ "name": "com.google.spanner.admin.database.v1.GetBackupScheduleRequest",
+ "queryAllDeclaredConstructors": true,
+ "queryAllPublicConstructors": true,
+ "queryAllDeclaredMethods": true,
+ "allPublicMethods": true,
+ "allDeclaredClasses": true,
+ "allPublicClasses": true
+ },
+ {
+ "name": "com.google.spanner.admin.database.v1.GetBackupScheduleRequest$Builder",
+ "queryAllDeclaredConstructors": true,
+ "queryAllPublicConstructors": true,
+ "queryAllDeclaredMethods": true,
+ "allPublicMethods": true,
+ "allDeclaredClasses": true,
+ "allPublicClasses": true
+ },
{
"name": "com.google.spanner.admin.database.v1.GetDatabaseDdlRequest",
"queryAllDeclaredConstructors": true,
@@ -2033,6 +2159,24 @@
"allDeclaredClasses": true,
"allPublicClasses": true
},
+ {
+ "name": "com.google.spanner.admin.database.v1.IncrementalBackupSpec",
+ "queryAllDeclaredConstructors": true,
+ "queryAllPublicConstructors": true,
+ "queryAllDeclaredMethods": true,
+ "allPublicMethods": true,
+ "allDeclaredClasses": true,
+ "allPublicClasses": true
+ },
+ {
+ "name": "com.google.spanner.admin.database.v1.IncrementalBackupSpec$Builder",
+ "queryAllDeclaredConstructors": true,
+ "queryAllPublicConstructors": true,
+ "queryAllDeclaredMethods": true,
+ "allPublicMethods": true,
+ "allDeclaredClasses": true,
+ "allPublicClasses": true
+ },
{
"name": "com.google.spanner.admin.database.v1.ListBackupOperationsRequest",
"queryAllDeclaredConstructors": true,
@@ -2069,6 +2213,42 @@
"allDeclaredClasses": true,
"allPublicClasses": true
},
+ {
+ "name": "com.google.spanner.admin.database.v1.ListBackupSchedulesRequest",
+ "queryAllDeclaredConstructors": true,
+ "queryAllPublicConstructors": true,
+ "queryAllDeclaredMethods": true,
+ "allPublicMethods": true,
+ "allDeclaredClasses": true,
+ "allPublicClasses": true
+ },
+ {
+ "name": "com.google.spanner.admin.database.v1.ListBackupSchedulesRequest$Builder",
+ "queryAllDeclaredConstructors": true,
+ "queryAllPublicConstructors": true,
+ "queryAllDeclaredMethods": true,
+ "allPublicMethods": true,
+ "allDeclaredClasses": true,
+ "allPublicClasses": true
+ },
+ {
+ "name": "com.google.spanner.admin.database.v1.ListBackupSchedulesResponse",
+ "queryAllDeclaredConstructors": true,
+ "queryAllPublicConstructors": true,
+ "queryAllDeclaredMethods": true,
+ "allPublicMethods": true,
+ "allDeclaredClasses": true,
+ "allPublicClasses": true
+ },
+ {
+ "name": "com.google.spanner.admin.database.v1.ListBackupSchedulesResponse$Builder",
+ "queryAllDeclaredConstructors": true,
+ "queryAllPublicConstructors": true,
+ "queryAllDeclaredMethods": true,
+ "allPublicMethods": true,
+ "allDeclaredClasses": true,
+ "allPublicClasses": true
+ },
{
"name": "com.google.spanner.admin.database.v1.ListBackupsRequest",
"queryAllDeclaredConstructors": true,
@@ -2357,6 +2537,24 @@
"allDeclaredClasses": true,
"allPublicClasses": true
},
+ {
+ "name": "com.google.spanner.admin.database.v1.UpdateBackupScheduleRequest",
+ "queryAllDeclaredConstructors": true,
+ "queryAllPublicConstructors": true,
+ "queryAllDeclaredMethods": true,
+ "allPublicMethods": true,
+ "allDeclaredClasses": true,
+ "allPublicClasses": true
+ },
+ {
+ "name": "com.google.spanner.admin.database.v1.UpdateBackupScheduleRequest$Builder",
+ "queryAllDeclaredConstructors": true,
+ "queryAllPublicConstructors": true,
+ "queryAllDeclaredMethods": true,
+ "allPublicMethods": true,
+ "allDeclaredClasses": true,
+ "allPublicClasses": true
+ },
{
"name": "com.google.spanner.admin.database.v1.UpdateDatabaseDdlMetadata",
"queryAllDeclaredConstructors": true,
diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/AbstractReadContextTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/AbstractReadContextTest.java
index 65f27d55810..ce7d6b300d1 100644
--- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/AbstractReadContextTest.java
+++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/AbstractReadContextTest.java
@@ -33,8 +33,11 @@
import com.google.spanner.v1.ExecuteSqlRequest;
import com.google.spanner.v1.ExecuteSqlRequest.QueryMode;
import com.google.spanner.v1.ExecuteSqlRequest.QueryOptions;
+import com.google.spanner.v1.ReadRequest;
+import com.google.spanner.v1.ReadRequest.OrderBy;
import com.google.spanner.v1.RequestOptions;
import com.google.spanner.v1.RequestOptions.Priority;
+import com.google.spanner.v1.SessionName;
import com.google.spanner.v1.TransactionSelector;
import java.util.ArrayList;
import java.util.Collection;
@@ -223,6 +226,21 @@ public void testGetExecuteSqlRequestBuilderWithDataBoost() {
assertTrue(request.getDataBoostEnabled());
}
+ @Test
+ public void testGetReadRequestBuilderWithOrderBy() {
+ ReadRequest request =
+ ReadRequest.newBuilder()
+ .setSession(
+ SessionName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]").toString())
+ .setTransaction(TransactionSelector.newBuilder().build())
+ .setTable("table110115790")
+ .setIndex("index100346066")
+ .addAllColumns(new ArrayList())
+ .setOrderByValue(2)
+ .build();
+ assertEquals(OrderBy.ORDER_BY_NO_ORDER, request.getOrderBy());
+ }
+
@Test
public void testGetExecuteBatchDmlRequestBuilderWithPriority() {
ExecuteBatchDmlRequest.Builder request =
diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/BatchCreateSessionsTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/BatchCreateSessionsTest.java
index c252bb19238..8d359428c77 100644
--- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/BatchCreateSessionsTest.java
+++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/BatchCreateSessionsTest.java
@@ -207,13 +207,13 @@ public void testSpannerReturnsAllAvailableSessionsAndThenNoSessions()
}
@Test
- public void testSpannerReturnsResourceExhausted() throws InterruptedException {
+ public void testSpannerReturnsFailedPrecondition() throws InterruptedException {
int minSessions = 100;
int maxSessions = 1000;
int expectedSessions;
DatabaseClientImpl client;
// Make the first BatchCreateSessions return an error.
- mockSpanner.addException(Status.RESOURCE_EXHAUSTED.asRuntimeException());
+ mockSpanner.addException(Status.FAILED_PRECONDITION.asRuntimeException());
try (Spanner spanner = createSpanner(minSessions, maxSessions)) {
// Create a database client which will create a session pool.
client =
diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/DatabaseClientImplTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/DatabaseClientImplTest.java
index 6443c904b86..62a10c0adb4 100644
--- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/DatabaseClientImplTest.java
+++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/DatabaseClientImplTest.java
@@ -52,6 +52,7 @@
import com.google.cloud.spanner.AsyncTransactionManager.TransactionContextFuture;
import com.google.cloud.spanner.MockSpannerServiceImpl.SimulatedExecutionTime;
import com.google.cloud.spanner.MockSpannerServiceImpl.StatementResult;
+import com.google.cloud.spanner.Options.RpcOrderBy;
import com.google.cloud.spanner.Options.RpcPriority;
import com.google.cloud.spanner.Options.TransactionOption;
import com.google.cloud.spanner.ReadContext.QueryAnalyzeMode;
@@ -89,6 +90,7 @@
import com.google.spanner.v1.ExecuteSqlRequest.QueryMode;
import com.google.spanner.v1.ExecuteSqlRequest.QueryOptions;
import com.google.spanner.v1.ReadRequest;
+import com.google.spanner.v1.ReadRequest.OrderBy;
import com.google.spanner.v1.RequestOptions.Priority;
import com.google.spanner.v1.ResultSetMetadata;
import com.google.spanner.v1.ResultSetStats;
@@ -1722,6 +1724,27 @@ public void testExecuteReadWithTag() {
assertThat(request.getRequestOptions().getTransactionTag()).isEmpty();
}
+ @Test
+ public void testExecuteReadWithOrderByOption() {
+ DatabaseClient client =
+ spanner.getDatabaseClient(DatabaseId.of(TEST_PROJECT, TEST_INSTANCE, TEST_DATABASE));
+ try (ResultSet resultSet =
+ client
+ .singleUse()
+ .read(
+ READ_TABLE_NAME,
+ KeySet.singleKey(Key.of(1L)),
+ READ_COLUMN_NAMES,
+ Options.orderBy(RpcOrderBy.NO_ORDER))) {
+ consumeResults(resultSet);
+ }
+
+ List requests = mockSpanner.getRequestsOfType(ReadRequest.class);
+ assertThat(requests).hasSize(1);
+ ReadRequest request = requests.get(0);
+ assertEquals(OrderBy.ORDER_BY_NO_ORDER, request.getOrderBy());
+ }
+
@Test
public void testExecuteReadWithDirectedReadOptions() {
DatabaseClient client =
@@ -3836,7 +3859,8 @@ public void testBatchCreateSessionsFailure_shouldNotPropagateToCloseMethod() {
try {
// Simulate session creation failures on the backend.
mockSpanner.setBatchCreateSessionsExecutionTime(
- SimulatedExecutionTime.ofStickyException(Status.RESOURCE_EXHAUSTED.asRuntimeException()));
+ SimulatedExecutionTime.ofStickyException(
+ Status.FAILED_PRECONDITION.asRuntimeException()));
DatabaseClient client =
spannerWithEmptySessionPool.getDatabaseClient(
DatabaseId.of(TEST_PROJECT, TEST_INSTANCE, TEST_DATABASE));
@@ -3844,7 +3868,7 @@ public void testBatchCreateSessionsFailure_shouldNotPropagateToCloseMethod() {
// non-blocking, and any exceptions will be delayed until actual query execution.
try (ResultSet rs = client.singleUse().executeQuery(SELECT1)) {
SpannerException e = assertThrows(SpannerException.class, rs::next);
- assertThat(e.getErrorCode()).isEqualTo(ErrorCode.RESOURCE_EXHAUSTED);
+ assertThat(e.getErrorCode()).isEqualTo(ErrorCode.FAILED_PRECONDITION);
}
} finally {
mockSpanner.setBatchCreateSessionsExecutionTime(SimulatedExecutionTime.none());
diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/IntegrationTestEnv.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/IntegrationTestEnv.java
index 6dd9c29e23f..2c6f886522e 100644
--- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/IntegrationTestEnv.java
+++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/IntegrationTestEnv.java
@@ -87,6 +87,10 @@ protected void initializeConfig()
throw new NullPointerException("Property " + TEST_ENV_CONFIG_CLASS_NAME + " needs to be set");
}
Class extends TestEnvConfig> configClass;
+ if (EmulatorSpannerHelper.isUsingEmulator()) {
+ // Make sure that we use an owned instance on the emulator.
+ System.setProperty(TEST_INSTANCE_PROPERTY, "");
+ }
configClass = (Class extends TestEnvConfig>) Class.forName(CONFIG_CLASS);
config = configClass.newInstance();
}
@@ -143,7 +147,7 @@ protected void after() {
private void initializeInstance(InstanceId instanceId) throws Exception {
InstanceConfig instanceConfig;
try {
- instanceConfig = instanceAdminClient.getInstanceConfig("regional-us-central1");
+ instanceConfig = instanceAdminClient.getInstanceConfig("regional-us-east4");
} catch (Throwable ignore) {
instanceConfig =
Iterators.get(instanceAdminClient.listInstanceConfigs().iterateAll().iterator(), 0, null);
diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/MockSpannerServiceImpl.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/MockSpannerServiceImpl.java
index 54b992b69ff..5266ecad7c8 100644
--- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/MockSpannerServiceImpl.java
+++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/MockSpannerServiceImpl.java
@@ -808,7 +808,7 @@ public void batchCreateSessions(
batchCreateSessionsExecutionTime.simulateExecutionTime(
exceptions, stickyGlobalExceptions, freezeLock);
if (sessions.size() >= maxTotalSessions) {
- throw Status.RESOURCE_EXHAUSTED
+ throw Status.FAILED_PRECONDITION
.withDescription("Maximum number of sessions reached")
.asRuntimeException();
}
diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/MultiplexedSessionMaintainerTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/MultiplexedSessionMaintainerTest.java
deleted file mode 100644
index ca7f8386894..00000000000
--- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/MultiplexedSessionMaintainerTest.java
+++ /dev/null
@@ -1,310 +0,0 @@
-/*
- * Copyright 2024 Google LLC
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.cloud.spanner;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assume.assumeTrue;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.doAnswer;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-import static org.mockito.MockitoAnnotations.initMocks;
-
-import com.google.cloud.Timestamp;
-import com.google.cloud.spanner.SessionPool.CachedSession;
-import com.google.cloud.spanner.SessionPool.MultiplexedSessionInitializationConsumer;
-import com.google.cloud.spanner.SessionPool.MultiplexedSessionMaintainerConsumer;
-import com.google.cloud.spanner.SessionPool.Position;
-import com.google.cloud.spanner.SessionPool.SessionFutureWrapper;
-import io.opencensus.trace.Tracing;
-import io.opentelemetry.api.OpenTelemetry;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Set;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.stream.Collectors;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-import org.mockito.Mock;
-import org.threeten.bp.Duration;
-import org.threeten.bp.Instant;
-
-@RunWith(JUnit4.class)
-public class MultiplexedSessionMaintainerTest extends BaseSessionPoolTest {
-
- private ExecutorService executor = Executors.newSingleThreadExecutor();
- private @Mock SpannerImpl client;
- private @Mock SessionClient sessionClient;
- private @Mock SpannerOptions spannerOptions;
- private DatabaseId db = DatabaseId.of("projects/p/instances/i/databases/unused");
- private SessionPoolOptions options;
- private FakeClock clock = new FakeClock();
- private List multiplexedSessionsRemoved = new ArrayList<>();
-
- @BeforeClass
- public static void checkUsesMultiplexedSessionPool() {
- assumeTrue("Only run if the maintainer in the session pool is used", false);
- }
-
- @Before
- public void setUp() {
- initMocks(this);
- when(client.getOptions()).thenReturn(spannerOptions);
- when(client.getSessionClient(db)).thenReturn(sessionClient);
- when(sessionClient.getSpanner()).thenReturn(client);
- when(spannerOptions.getNumChannels()).thenReturn(4);
- when(spannerOptions.getDatabaseRole()).thenReturn("role");
- options =
- SessionPoolOptions.newBuilder()
- .setMinSessions(1)
- .setMaxIdleSessions(1)
- .setMaxSessions(5)
- .setIncStep(1)
- .setKeepAliveIntervalMinutes(2)
- .setUseMultiplexedSession(true)
- .setPoolMaintainerClock(clock)
- .build();
- when(spannerOptions.getSessionPoolOptions()).thenReturn(options);
- assumeTrue(options.getUseMultiplexedSession());
- multiplexedSessionsRemoved.clear();
- }
-
- @Test
- public void testMaintainMultiplexedSession_whenNewSessionCreated_assertThatStaleSessionIsRemoved()
- throws Exception {
- doAnswer(
- invocation -> {
- MultiplexedSessionInitializationConsumer consumer =
- invocation.getArgument(0, MultiplexedSessionInitializationConsumer.class);
- ReadContext mockContext = mock(ReadContext.class);
- Timestamp timestamp =
- Timestamp.ofTimeSecondsAndNanos(
- Instant.ofEpochMilli(clock.currentTimeMillis.get()).getEpochSecond(), 0);
- consumer.onSessionReady(
- setupMockSession(
- buildMockMultiplexedSession(client, mockContext, timestamp.toProto()),
- mockContext));
- return null;
- })
- .when(sessionClient)
- .asyncCreateMultiplexedSession(any(MultiplexedSessionInitializationConsumer.class));
- doAnswer(
- invocation -> {
- MultiplexedSessionMaintainerConsumer consumer =
- invocation.getArgument(0, MultiplexedSessionMaintainerConsumer.class);
- ReadContext mockContext = mock(ReadContext.class);
- Timestamp timestamp =
- Timestamp.ofTimeSecondsAndNanos(
- Instant.ofEpochMilli(clock.currentTimeMillis.get()).getEpochSecond(), 0);
- consumer.onSessionReady(
- setupMockSession(
- buildMockMultiplexedSession(client, mockContext, timestamp.toProto()),
- mockContext));
- return null;
- })
- .when(sessionClient)
- .asyncCreateMultiplexedSession(any(MultiplexedSessionMaintainerConsumer.class));
-
- SessionPool pool = createPool();
-
- // Run one maintenance loop.
- CachedSession session1 = pool.getMultiplexedSessionWithFallback().get().get();
- runMaintenanceLoop(clock, pool, 1);
- assertTrue(multiplexedSessionsRemoved.isEmpty());
-
- // Advance clock by 8 days
- clock.currentTimeMillis.addAndGet(Duration.ofDays(8).toMillis());
-
- // Run second maintenance loop. the first session would now be stale since it has now existed
- // for more than 7 days.
- runMaintenanceLoop(clock, pool, 1);
-
- CachedSession session2 = pool.getMultiplexedSessionWithFallback().get().get();
- assertNotEquals(session1.getName(), session2.getName());
- assertEquals(1, multiplexedSessionsRemoved.size());
- assertTrue(getNameOfSessionRemoved().contains(session1.getName()));
-
- // Advance clock by 8 days
- clock.currentTimeMillis.addAndGet(Duration.ofDays(8).toMillis());
-
- // Run third maintenance loop. the second session would now be stale since it has now existed
- // for more than 7 days
- runMaintenanceLoop(clock, pool, 1);
-
- CachedSession session3 = pool.getMultiplexedSessionWithFallback().get().get();
- assertNotEquals(session2.getName(), session3.getName());
- assertEquals(2, multiplexedSessionsRemoved.size());
- assertTrue(getNameOfSessionRemoved().contains(session2.getName()));
- }
-
- @Test
- public void
- testMaintainMultiplexedSession_whenMultiplexedSessionNotStale_assertThatSessionIsNotRemoved() {
- doAnswer(
- invocation -> {
- MultiplexedSessionInitializationConsumer consumer =
- invocation.getArgument(0, MultiplexedSessionInitializationConsumer.class);
- ReadContext mockContext = mock(ReadContext.class);
- Timestamp timestamp =
- Timestamp.ofTimeSecondsAndNanos(
- Instant.ofEpochMilli(clock.currentTimeMillis.get()).getEpochSecond(), 0);
- consumer.onSessionReady(
- setupMockSession(
- buildMockMultiplexedSession(client, mockContext, timestamp.toProto()),
- mockContext));
- return null;
- })
- .when(sessionClient)
- .asyncCreateMultiplexedSession(any(MultiplexedSessionInitializationConsumer.class));
- SessionPool pool = createPool();
-
- // Run one maintenance loop.
- SessionFutureWrapper session1 = pool.getMultiplexedSessionWithFallback();
- runMaintenanceLoop(clock, pool, 1);
- assertTrue(multiplexedSessionsRemoved.isEmpty());
-
- // Advance clock by 4 days
- clock.currentTimeMillis.addAndGet(Duration.ofDays(4).toMillis());
- // Run one maintenance loop. the first session would not be stale yet since it has now existed
- // for less than 7 days.
- runMaintenanceLoop(clock, pool, 1);
- SessionFutureWrapper session2 = pool.getMultiplexedSessionWithFallback();
- assertTrue(multiplexedSessionsRemoved.isEmpty());
- assertEquals(session1.get().getName(), session2.get().getName());
- }
-
- @Test
- public void
- testMaintainMultiplexedSession_whenMultiplexedSessionCreationFailed_testRetryAfterDelay() {
- doAnswer(
- invocation -> {
- MultiplexedSessionInitializationConsumer consumer =
- invocation.getArgument(0, MultiplexedSessionInitializationConsumer.class);
- ReadContext mockContext = mock(ReadContext.class);
- Timestamp timestamp =
- Timestamp.ofTimeSecondsAndNanos(
- Instant.ofEpochMilli(clock.currentTimeMillis.get()).getEpochSecond(), 0);
- consumer.onSessionReady(
- setupMockSession(
- buildMockMultiplexedSession(client, mockContext, timestamp.toProto()),
- mockContext));
- return null;
- })
- .when(sessionClient)
- .asyncCreateMultiplexedSession(any(MultiplexedSessionInitializationConsumer.class));
- doAnswer(
- invocation -> {
- MultiplexedSessionMaintainerConsumer consumer =
- invocation.getArgument(0, MultiplexedSessionMaintainerConsumer.class);
- consumer.onSessionCreateFailure(
- SpannerExceptionFactory.newSpannerException(ErrorCode.DEADLINE_EXCEEDED, ""), 1);
- return null;
- })
- .when(sessionClient)
- .asyncCreateMultiplexedSession(any(MultiplexedSessionMaintainerConsumer.class));
- SessionPool pool = createPool();
-
- // Advance clock by 8 days
- clock.currentTimeMillis.addAndGet(Duration.ofDays(8).toMillis());
-
- // Run one maintenance loop. Attempt replacing stale session should fail.
- SessionFutureWrapper session1 = pool.getMultiplexedSessionWithFallback();
- runMaintenanceLoop(clock, pool, 1);
- assertTrue(multiplexedSessionsRemoved.isEmpty());
- verify(sessionClient, times(1))
- .asyncCreateMultiplexedSession(any(MultiplexedSessionMaintainerConsumer.class));
-
- // Advance clock by 10s and now mock session creation to be successful.
- clock.currentTimeMillis.addAndGet(Duration.ofSeconds(10).toMillis());
- doAnswer(
- invocation -> {
- MultiplexedSessionMaintainerConsumer consumer =
- invocation.getArgument(0, MultiplexedSessionMaintainerConsumer.class);
- ReadContext mockContext = mock(ReadContext.class);
- Timestamp timestamp =
- Timestamp.ofTimeSecondsAndNanos(
- Instant.ofEpochMilli(clock.currentTimeMillis.get()).getEpochSecond(), 0);
- consumer.onSessionReady(
- setupMockSession(
- buildMockMultiplexedSession(client, mockContext, timestamp.toProto()),
- mockContext));
- return null;
- })
- .when(sessionClient)
- .asyncCreateMultiplexedSession(any(MultiplexedSessionMaintainerConsumer.class));
- // Run one maintenance loop. Attempt should be ignored as it has not been 10 minutes since last
- // attempt.
- runMaintenanceLoop(clock, pool, 1);
- SessionFutureWrapper session2 = pool.getMultiplexedSessionWithFallback();
- assertTrue(multiplexedSessionsRemoved.isEmpty());
- assertEquals(session1.get().getName(), session2.get().getName());
- verify(sessionClient, times(1))
- .asyncCreateMultiplexedSession(any(MultiplexedSessionMaintainerConsumer.class));
-
- // Advance clock by 15 minutes
- clock.currentTimeMillis.addAndGet(Duration.ofMinutes(15).toMillis());
- // Run one maintenance loop. Attempt should succeed since its already more than 10 minutes since
- // the last attempt.
- runMaintenanceLoop(clock, pool, 1);
- SessionFutureWrapper session3 = pool.getMultiplexedSessionWithFallback();
- assertTrue(getNameOfSessionRemoved().contains(session1.get().get().getName()));
- assertNotEquals(session1.get().getName(), session3.get().getName());
- verify(sessionClient, times(2))
- .asyncCreateMultiplexedSession(any(MultiplexedSessionMaintainerConsumer.class));
- }
-
- private SessionImpl setupMockSession(final SessionImpl session, final ReadContext mockContext) {
- final ResultSet mockResult = mock(ResultSet.class);
- when(mockContext.executeQuery(any(Statement.class))).thenAnswer(invocation -> mockResult);
- when(mockResult.next()).thenReturn(true);
- return session;
- }
-
- private SessionPool createPool() {
- // Allow sessions to be added to the head of the pool in all cases in this test, as it is
- // otherwise impossible to know which session exactly is getting pinged at what point in time.
- SessionPool pool =
- SessionPool.createPool(
- options,
- new TestExecutorFactory(),
- client.getSessionClient(db),
- clock,
- Position.FIRST,
- new TraceWrapper(Tracing.getTracer(), OpenTelemetry.noop().getTracer(""), false),
- OpenTelemetry.noop());
- pool.multiplexedSessionRemovedListener =
- input -> {
- multiplexedSessionsRemoved.add(input);
- return null;
- };
- return pool;
- }
-
- Set getNameOfSessionRemoved() {
- return multiplexedSessionsRemoved.stream()
- .map(session -> session.getName())
- .collect(Collectors.toSet());
- }
-}
diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/MultiplexedSessionPoolTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/MultiplexedSessionPoolTest.java
deleted file mode 100644
index fcad1ff22c6..00000000000
--- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/MultiplexedSessionPoolTest.java
+++ /dev/null
@@ -1,182 +0,0 @@
-/*
- * Copyright 2024 Google LLC
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.cloud.spanner;
-
-import static com.google.common.truth.Truth.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertThrows;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assume.assumeTrue;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.doAnswer;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-import static org.mockito.MockitoAnnotations.initMocks;
-
-import com.google.cloud.spanner.SessionPool.MultiplexedSessionFuture;
-import com.google.cloud.spanner.SessionPool.MultiplexedSessionInitializationConsumer;
-import com.google.cloud.spanner.SessionPool.SessionFutureWrapper;
-import com.google.cloud.spanner.SpannerImpl.ClosedException;
-import io.opencensus.trace.Tracing;
-import io.opentelemetry.api.OpenTelemetry;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.mockito.Mock;
-import org.threeten.bp.Duration;
-
-/**
- * Tests for {@link com.google.cloud.spanner.SessionPool.MultiplexedSession} component within the
- * {@link SessionPool} class.
- */
-public class MultiplexedSessionPoolTest extends BaseSessionPoolTest {
-
- @Mock SpannerImpl client;
- @Mock SessionClient sessionClient;
- @Mock SpannerOptions spannerOptions;
- private final DatabaseId db = DatabaseId.of("projects/p/instances/i/databases/unused");
- private final TraceWrapper tracer =
- new TraceWrapper(Tracing.getTracer(), OpenTelemetry.noop().getTracer(""), false);
- SessionPoolOptions options;
- SessionPool pool;
-
- private SessionPool createPool() {
- return SessionPool.createPool(
- options,
- new TestExecutorFactory(),
- client.getSessionClient(db),
- tracer,
- OpenTelemetry.noop());
- }
-
- @BeforeClass
- public static void checkUsesMultiplexedSessionPool() {
- assumeTrue("Only run if the maintainer in the session pool is used", false);
- }
-
- @Before
- public void setUp() {
- initMocks(this);
- SpannerOptions.resetActiveTracingFramework();
- SpannerOptions.enableOpenTelemetryTraces();
- when(client.getOptions()).thenReturn(spannerOptions);
- when(client.getSessionClient(db)).thenReturn(sessionClient);
- when(sessionClient.getSpanner()).thenReturn(client);
- when(spannerOptions.getNumChannels()).thenReturn(4);
- when(spannerOptions.getDatabaseRole()).thenReturn("role");
- options =
- SessionPoolOptions.newBuilder()
- .setMinSessions(2)
- .setMaxSessions(2)
- .setUseMultiplexedSession(true)
- .build();
- when(spannerOptions.getSessionPoolOptions()).thenReturn(options);
- assumeTrue(options.getUseMultiplexedSession());
- }
-
- @Test
- public void testGetMultiplexedSession_whenSessionInitializationSucceeded_assertSessionReturned() {
- setupMockMultiplexedSessionCreation();
-
- pool = createPool();
- assertTrue(pool.isValid());
-
- // create 5 requests which require a session
- for (int i = 0; i < 5; i++) {
- // checking out a multiplexed session
- SessionFutureWrapper multiplexedSessionFuture = pool.getMultiplexedSessionWithFallback();
- assertNotNull(multiplexedSessionFuture.get());
- }
- verify(sessionClient, times(1))
- .asyncCreateMultiplexedSession(any(MultiplexedSessionInitializationConsumer.class));
- }
-
- @Test
- public void testGetMultiplexedSession_whenClosedPool_assertSessionReturned() {
- setupMockMultiplexedSessionCreation();
-
- pool = createPool();
- assertTrue(pool.isValid());
- closePoolWithStacktrace();
-
- // checking out a multiplexed session does not throw error even if pool is closed
- MultiplexedSessionFuture multiplexedSessionFuture =
- (MultiplexedSessionFuture) pool.getMultiplexedSessionWithFallback().get();
- assertNotNull(multiplexedSessionFuture);
-
- // checking out a regular session throws error.
- IllegalStateException e = assertThrows(IllegalStateException.class, () -> pool.getSession());
- assertThat(e.getCause()).isInstanceOf(ClosedException.class);
- StringWriter sw = new StringWriter();
- e.getCause().printStackTrace(new PrintWriter(sw));
- assertThat(sw.toString()).contains("closePoolWithStacktrace");
- }
-
- private void closePoolWithStacktrace() {
- pool.closeAsync(new SpannerImpl.ClosedException());
- }
-
- @Test
- public void testGetMultiplexedSession_whenSessionCreationFailed_assertErrorForWaiters() {
- doAnswer(
- invocation -> {
- MultiplexedSessionInitializationConsumer consumer =
- invocation.getArgument(0, MultiplexedSessionInitializationConsumer.class);
- consumer.onSessionCreateFailure(
- SpannerExceptionFactory.newSpannerException(ErrorCode.DEADLINE_EXCEEDED, ""), 1);
- return null;
- })
- .when(sessionClient)
- .asyncCreateMultiplexedSession(any(MultiplexedSessionInitializationConsumer.class));
- options =
- options
- .toBuilder()
- .setMinSessions(2)
- .setUseMultiplexedSession(true)
- .setAcquireSessionTimeout(
- Duration.ofMillis(50)) // block for a max of 50 ms for session to be available
- .build();
- pool = createPool();
-
- // create 5 requests which require a session
- for (int i = 0; i < 5; i++) {
- SpannerException e =
- assertThrows(
- SpannerException.class, () -> pool.getMultiplexedSessionWithFallback().get().get());
- assertEquals(ErrorCode.DEADLINE_EXCEEDED, e.getErrorCode());
- }
- // assert that all 5 requests failed with exception
- assertEquals(0, pool.getNumWaiterTimeouts());
- assertEquals(0, pool.getNumberOfSessionsInPool());
- }
-
- private void setupMockMultiplexedSessionCreation() {
- doAnswer(
- invocation -> {
- MultiplexedSessionInitializationConsumer consumer =
- invocation.getArgument(0, MultiplexedSessionInitializationConsumer.class);
- consumer.onSessionReady(mockSession());
- return null;
- })
- .when(sessionClient)
- .asyncCreateMultiplexedSession(any(MultiplexedSessionInitializationConsumer.class));
- }
-}
diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/OptionsTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/OptionsTest.java
index 8c9a5d957e8..38b7a121731 100644
--- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/OptionsTest.java
+++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/OptionsTest.java
@@ -18,16 +18,19 @@
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
+import com.google.cloud.spanner.Options.RpcOrderBy;
import com.google.cloud.spanner.Options.RpcPriority;
import com.google.spanner.v1.DirectedReadOptions;
import com.google.spanner.v1.DirectedReadOptions.IncludeReplicas;
import com.google.spanner.v1.DirectedReadOptions.ReplicaSelection;
+import com.google.spanner.v1.ReadRequest.OrderBy;
import com.google.spanner.v1.RequestOptions.Priority;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -79,7 +82,8 @@ public void allOptionsPresent() {
Options.limit(10),
Options.prefetchChunks(1),
Options.dataBoostEnabled(true),
- Options.directedRead(DIRECTED_READ_OPTIONS));
+ Options.directedRead(DIRECTED_READ_OPTIONS),
+ Options.orderBy(RpcOrderBy.NO_ORDER));
assertThat(options.hasLimit()).isTrue();
assertThat(options.limit()).isEqualTo(10);
assertThat(options.hasPrefetchChunks()).isTrue();
@@ -87,6 +91,7 @@ public void allOptionsPresent() {
assertThat(options.hasDataBoostEnabled()).isTrue();
assertTrue(options.dataBoostEnabled());
assertTrue(options.hasDirectedReadOptions());
+ assertTrue(options.hasOrderBy());
assertEquals(DIRECTED_READ_OPTIONS, options.directedReadOptions());
}
@@ -101,6 +106,7 @@ public void allOptionsAbsent() {
assertThat(options.hasTag()).isFalse();
assertThat(options.hasDataBoostEnabled()).isFalse();
assertThat(options.hasDirectedReadOptions()).isFalse();
+ assertThat(options.hasOrderBy()).isFalse();
assertNull(options.withExcludeTxnFromChangeStreams());
assertThat(options.toString()).isEqualTo("");
assertThat(options.equals(options)).isTrue();
@@ -182,7 +188,8 @@ public void readOptionsTest() {
Options.limit(limit),
Options.tag(tag),
Options.dataBoostEnabled(true),
- Options.directedRead(DIRECTED_READ_OPTIONS));
+ Options.directedRead(DIRECTED_READ_OPTIONS),
+ Options.orderBy(RpcOrderBy.NO_ORDER));
assertThat(options.toString())
.isEqualTo(
@@ -197,10 +204,14 @@ public void readOptionsTest() {
+ " "
+ "directedReadOptions: "
+ DIRECTED_READ_OPTIONS
+ + " "
+ + "orderBy: "
+ + RpcOrderBy.NO_ORDER
+ " ");
assertThat(options.tag()).isEqualTo(tag);
assertEquals(dataBoost, options.dataBoostEnabled());
assertEquals(DIRECTED_READ_OPTIONS, options.directedReadOptions());
+ assertEquals(OrderBy.ORDER_BY_NO_ORDER, options.orderBy());
}
@Test
@@ -354,6 +365,24 @@ public void testTransactionOptionsPriority() {
assertEquals("priority: " + priority + " ", options.toString());
}
+ @Test
+ public void testReadOptionsOrderBy() {
+ RpcOrderBy orderBy = RpcOrderBy.NO_ORDER;
+ Options options = Options.fromReadOptions(Options.orderBy(orderBy));
+ assertTrue(options.hasOrderBy());
+ assertEquals("orderBy: " + orderBy + " ", options.toString());
+ }
+
+ @Test
+ public void testReadOptionsWithOrderByEquality() {
+ Options optionsWithNoOrderBy1 = Options.fromReadOptions(Options.orderBy(RpcOrderBy.NO_ORDER));
+ Options optionsWithNoOrderBy2 = Options.fromReadOptions(Options.orderBy(RpcOrderBy.NO_ORDER));
+ assertTrue(optionsWithNoOrderBy1.equals(optionsWithNoOrderBy2));
+
+ Options optionsWithPkOrder = Options.fromReadOptions(Options.orderBy(RpcOrderBy.PRIMARY_KEY));
+ assertFalse(optionsWithNoOrderBy1.equals(optionsWithPkOrder));
+ }
+
@Test
public void testQueryOptionsPriority() {
RpcPriority priority = RpcPriority.MEDIUM;
diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SessionImplTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SessionImplTest.java
index 72befe8a2b4..2a850514d0d 100644
--- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SessionImplTest.java
+++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SessionImplTest.java
@@ -138,6 +138,8 @@ public void setUp() {
when(rpc.getExecuteQueryRetryableCodes())
.thenReturn(
SpannerStubSettings.newBuilder().executeStreamingSqlSettings().getRetryableCodes());
+ when(rpc.getCommitRetrySettings())
+ .thenReturn(SpannerStubSettings.newBuilder().commitSettings().getRetrySettings());
session = spanner.getSessionClient(db).createSession();
Span oTspan = mock(Span.class);
ISpan span = new OpenTelemetrySpan(oTspan);
diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SessionPoolOptionsTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SessionPoolOptionsTest.java
index b678d6e46bc..9b15ddea13b 100644
--- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SessionPoolOptionsTest.java
+++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SessionPoolOptionsTest.java
@@ -318,4 +318,95 @@ public void testMultiplexedSessionMaintenanceDuration() {
.build()
.getMultiplexedSessionMaintenanceDuration());
}
+
+ @Test
+ public void testToBuilder() {
+ assertToBuilderRoundtrip(SessionPoolOptions.newBuilder().build());
+ assertToBuilderRoundtrip(
+ SessionPoolOptions.newBuilder()
+ .setUseMultiplexedSession(ThreadLocalRandom.current().nextBoolean())
+ .build());
+ assertToBuilderRoundtrip(
+ SessionPoolOptions.newBuilder()
+ .setMinSessions(ThreadLocalRandom.current().nextInt(400))
+ .build());
+ assertToBuilderRoundtrip(
+ SessionPoolOptions.newBuilder()
+ .setMaxSessions(ThreadLocalRandom.current().nextInt(1, 1000))
+ .build());
+ assertToBuilderRoundtrip(
+ SessionPoolOptions.newBuilder()
+ .setIncStep(ThreadLocalRandom.current().nextInt(1, 1000))
+ .build());
+ assertToBuilderRoundtrip(
+ SessionPoolOptions.newBuilder()
+ .setMaxIdleSessions(ThreadLocalRandom.current().nextInt(1000))
+ .build());
+ assertToBuilderRoundtrip(
+ SessionPoolOptions.newBuilder()
+ .setWriteSessionsFraction(ThreadLocalRandom.current().nextFloat())
+ .build());
+ assertToBuilderRoundtrip(
+ SessionPoolOptions.newBuilder()
+ .setInactiveTransactionRemovalOptions(
+ InactiveTransactionRemovalOptions.newBuilder()
+ .setUsedSessionsRatioThreshold(ThreadLocalRandom.current().nextDouble())
+ .build())
+ .build());
+ assertToBuilderRoundtrip(
+ SessionPoolOptions.newBuilder()
+ .setLoopFrequency(ThreadLocalRandom.current().nextInt(1000))
+ .build());
+ assertToBuilderRoundtrip(
+ SessionPoolOptions.newBuilder()
+ .setMultiplexedSessionMaintenanceLoopFrequency(
+ java.time.Duration.ofMillis(ThreadLocalRandom.current().nextInt(1000)))
+ .build());
+ assertToBuilderRoundtrip(
+ SessionPoolOptions.newBuilder()
+ .setKeepAliveIntervalMinutes(ThreadLocalRandom.current().nextInt(60))
+ .build());
+ assertToBuilderRoundtrip(
+ SessionPoolOptions.newBuilder()
+ .setRemoveInactiveSessionAfter(
+ Duration.ofMillis(ThreadLocalRandom.current().nextLong(10000)))
+ .build());
+ assertToBuilderRoundtrip(
+ SessionPoolOptions.newBuilder().setCloseIfInactiveTransactions().build());
+ assertToBuilderRoundtrip(SessionPoolOptions.newBuilder().setFailOnSessionLeak().build());
+ assertToBuilderRoundtrip(
+ SessionPoolOptions.newBuilder()
+ .setTrackStackTraceOfSessionCheckout(ThreadLocalRandom.current().nextBoolean())
+ .build());
+ assertToBuilderRoundtrip(
+ SessionPoolOptions.newBuilder()
+ .setInitialWaitForSessionTimeoutMillis(ThreadLocalRandom.current().nextLong(1000))
+ .build());
+ assertToBuilderRoundtrip(
+ SessionPoolOptions.newBuilder()
+ .setAutoDetectDialect(ThreadLocalRandom.current().nextBoolean())
+ .build());
+ assertToBuilderRoundtrip(
+ SessionPoolOptions.newBuilder()
+ .setWaitForMinSessions(Duration.ofMillis(ThreadLocalRandom.current().nextLong(10000)))
+ .build());
+ assertToBuilderRoundtrip(
+ SessionPoolOptions.newBuilder()
+ .setAcquireSessionTimeout(
+ Duration.ofMillis(ThreadLocalRandom.current().nextLong(1, 10000)))
+ .build());
+ assertToBuilderRoundtrip(
+ SessionPoolOptions.newBuilder()
+ .setRandomizePositionQPSThreshold(ThreadLocalRandom.current().nextLong(10000))
+ .build());
+ assertToBuilderRoundtrip(
+ SessionPoolOptions.newBuilder()
+ .setMultiplexedSessionMaintenanceDuration(
+ Duration.ofMillis(ThreadLocalRandom.current().nextLong(10000)))
+ .build());
+ }
+
+ static void assertToBuilderRoundtrip(SessionPoolOptions options) {
+ assertEquals(options, options.toBuilder().build());
+ }
}
diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SessionPoolTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SessionPoolTest.java
index 8ffc4f21a10..58b0280cf08 100644
--- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SessionPoolTest.java
+++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SessionPoolTest.java
@@ -64,7 +64,6 @@
import com.google.cloud.spanner.MetricRegistryTestUtils.PointWithFunction;
import com.google.cloud.spanner.ReadContext.QueryAnalyzeMode;
import com.google.cloud.spanner.SessionClient.SessionConsumer;
-import com.google.cloud.spanner.SessionPool.MultiplexedSessionInitializationConsumer;
import com.google.cloud.spanner.SessionPool.PooledSession;
import com.google.cloud.spanner.SessionPool.PooledSessionFuture;
import com.google.cloud.spanner.SessionPool.Position;
@@ -75,6 +74,7 @@
import com.google.cloud.spanner.spi.v1.SpannerRpc;
import com.google.cloud.spanner.spi.v1.SpannerRpc.ResultStreamConsumer;
import com.google.cloud.spanner.v1.stub.SpannerStubSettings;
+import com.google.common.base.Stopwatch;
import com.google.common.collect.Lists;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.Uninterruptibles;
@@ -2023,14 +2023,16 @@ public void testOpenCensusMetricsDisable() {
public void testOpenTelemetrySessionMetrics() throws Exception {
SpannerOptions.resetActiveTracingFramework();
SpannerOptions.enableOpenTelemetryMetrics();
- // Create a session pool with max 2 session and a low timeout for waiting for a session.
+ // Create a session pool with max 3 session and a low timeout for waiting for a session.
if (minSessions == 1) {
options =
SessionPoolOptions.newBuilder()
.setMinSessions(1)
.setMaxSessions(3)
- .setMaxIdleSessions(0)
- .setInitialWaitForSessionTimeoutMillis(50L)
+ // This must be set to null for the setInitialWaitForSessionTimeoutMillis call to have
+ // any effect.
+ .setAcquireSessionTimeout(null)
+ .setInitialWaitForSessionTimeoutMillis(1L)
.build();
FakeClock clock = new FakeClock();
clock.currentTimeMillis.set(System.currentTimeMillis());
@@ -2081,26 +2083,29 @@ public void testOpenTelemetrySessionMetrics() throws Exception {
Future fut =
executor.submit(
() -> {
+ PooledSessionFuture session = pool.getSession();
latch.countDown();
- Session session = pool.getSession();
+ session.get();
session.close();
return null;
});
// Wait until the background thread is actually waiting for a session.
latch.await();
// Wait until the request has timed out.
- int waitCount = 0;
- while (pool.getNumWaiterTimeouts() == 0L && waitCount < 1000) {
- Thread.sleep(5L);
- waitCount++;
+ Stopwatch watch = Stopwatch.createStarted();
+ while (pool.getNumWaiterTimeouts() == 0L && watch.elapsed(TimeUnit.MILLISECONDS) < 100) {
+ Thread.yield();
}
+ assertTrue(pool.getNumWaiterTimeouts() > 0);
// Return the checked out session to the pool so the async request will get a session and
// finish.
session2.close();
// Verify that the async request also succeeds.
fut.get(10L, TimeUnit.SECONDS);
executor.shutdown();
+ assertTrue(executor.awaitTermination(10L, TimeUnit.SECONDS));
+ inMemoryMetricReader.forceFlush();
metricDataCollection = inMemoryMetricReader.collectAllMetrics();
// Max Allowed sessions should be 3
@@ -2212,16 +2217,6 @@ public void testWaitOnMinSessionsWhenSessionsAreCreatedBeforeTimeout() {
}))
.when(sessionClient)
.asyncBatchCreateSessions(Mockito.eq(1), Mockito.anyBoolean(), any(SessionConsumer.class));
- doAnswer(
- invocation ->
- executor.submit(
- () -> {
- MultiplexedSessionInitializationConsumer consumer =
- invocation.getArgument(0, MultiplexedSessionInitializationConsumer.class);
- consumer.onSessionReady(mockMultiplexedSession());
- }))
- .when(sessionClient)
- .asyncCreateMultiplexedSession(any(MultiplexedSessionInitializationConsumer.class));
pool = createPool(new FakeClock(), new FakeMetricRegistry(), SPANNER_DEFAULT_LABEL_VALUES);
pool.maybeWaitOnMinSessions();
diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/TransactionContextImplTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/TransactionContextImplTest.java
index c1da423760d..561bfb89008 100644
--- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/TransactionContextImplTest.java
+++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/TransactionContextImplTest.java
@@ -28,6 +28,7 @@
import com.google.api.core.ApiFutures;
import com.google.cloud.spanner.TransactionRunnerImpl.TransactionContextImpl;
import com.google.cloud.spanner.spi.v1.SpannerRpc;
+import com.google.cloud.spanner.v1.stub.SpannerStubSettings;
import com.google.protobuf.ByteString;
import com.google.protobuf.Timestamp;
import com.google.rpc.Code;
@@ -80,6 +81,8 @@ public void setup() {
when(tracer.spanBuilderWithExplicitParent(
eq(SpannerImpl.BATCH_UPDATE), eq(span), any(Attributes.class)))
.thenReturn(span);
+ when(rpc.getCommitRetrySettings())
+ .thenReturn(SpannerStubSettings.newBuilder().commitSettings().getRetrySettings());
}
private TransactionContextImpl createContext() {
diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/TransactionManagerImplTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/TransactionManagerImplTest.java
index dc28b333c4f..c3fcf1c7480 100644
--- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/TransactionManagerImplTest.java
+++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/TransactionManagerImplTest.java
@@ -35,6 +35,7 @@
import com.google.cloud.grpc.GrpcTransportOptions.ExecutorFactory;
import com.google.cloud.spanner.TransactionManager.TransactionState;
import com.google.cloud.spanner.spi.v1.SpannerRpc;
+import com.google.cloud.spanner.v1.stub.SpannerStubSettings;
import com.google.protobuf.ByteString;
import com.google.protobuf.Empty;
import com.google.spanner.v1.BeginTransactionRequest;
@@ -248,6 +249,8 @@ public void usesPreparedTransaction() {
com.google.protobuf.Timestamp.newBuilder()
.setSeconds(System.currentTimeMillis() * 1000))
.build()));
+ when(rpc.getCommitRetrySettings())
+ .thenReturn(SpannerStubSettings.newBuilder().commitSettings().getRetrySettings());
DatabaseId db = DatabaseId.of("test", "test", "test");
try (SpannerImpl spanner = new SpannerImpl(rpc, options)) {
DatabaseClient client = spanner.getDatabaseClient(db);
@@ -332,6 +335,8 @@ public void inlineBegin() {
com.google.protobuf.Timestamp.newBuilder()
.setSeconds(System.currentTimeMillis() * 1000))
.build()));
+ when(rpc.getCommitRetrySettings())
+ .thenReturn(SpannerStubSettings.newBuilder().commitSettings().getRetrySettings());
DatabaseId db = DatabaseId.of("test", "test", "test");
try (SpannerImpl spanner = new SpannerImpl(rpc, options)) {
DatabaseClient client = spanner.getDatabaseClient(db);
diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/TransactionRunnerImplTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/TransactionRunnerImplTest.java
index 6a707a490dc..f5d9f1841a2 100644
--- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/TransactionRunnerImplTest.java
+++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/TransactionRunnerImplTest.java
@@ -35,6 +35,7 @@
import com.google.cloud.spanner.SessionClient.SessionId;
import com.google.cloud.spanner.TransactionRunnerImpl.TransactionContextImpl;
import com.google.cloud.spanner.spi.v1.SpannerRpc;
+import com.google.cloud.spanner.v1.stub.SpannerStubSettings;
import com.google.common.base.Preconditions;
import com.google.protobuf.ByteString;
import com.google.protobuf.Duration;
@@ -141,6 +142,8 @@ public void setUp() {
CommitResponse.newBuilder()
.setCommitTimestamp(Timestamp.getDefaultInstance())
.build()));
+ when(rpc.getCommitRetrySettings())
+ .thenReturn(SpannerStubSettings.newBuilder().commitSettings().getRetrySettings());
when(rpc.rollbackAsync(Mockito.any(RollbackRequest.class), Mockito.anyMap()))
.thenReturn(ApiFutures.immediateFuture(Empty.getDefaultInstance()));
Span oTspan = mock(Span.class);
@@ -196,6 +199,8 @@ public void usesPreparedTransaction() {
.setCommitTimestamp(
Timestamp.newBuilder().setSeconds(System.currentTimeMillis() * 1000))
.build()));
+ when(rpc.getCommitRetrySettings())
+ .thenReturn(SpannerStubSettings.newBuilder().commitSettings().getRetrySettings());
DatabaseId db = DatabaseId.of("test", "test", "test");
try (SpannerImpl spanner = new SpannerImpl(rpc, options)) {
DatabaseClient client = spanner.getDatabaseClient(db);
diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/admin/database/v1/DatabaseAdminClientHttpJsonTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/admin/database/v1/DatabaseAdminClientHttpJsonTest.java
index 368868a2dce..b5a045b24a0 100644
--- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/admin/database/v1/DatabaseAdminClientHttpJsonTest.java
+++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/admin/database/v1/DatabaseAdminClientHttpJsonTest.java
@@ -17,6 +17,7 @@
package com.google.cloud.spanner.admin.database.v1;
import static com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient.ListBackupOperationsPagedResponse;
+import static com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient.ListBackupSchedulesPagedResponse;
import static com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient.ListBackupsPagedResponse;
import static com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient.ListDatabaseOperationsPagedResponse;
import static com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient.ListDatabaseRolesPagedResponse;
@@ -41,11 +42,16 @@
import com.google.longrunning.Operation;
import com.google.protobuf.Any;
import com.google.protobuf.ByteString;
+import com.google.protobuf.Duration;
import com.google.protobuf.Empty;
import com.google.protobuf.FieldMask;
import com.google.protobuf.Timestamp;
import com.google.spanner.admin.database.v1.Backup;
import com.google.spanner.admin.database.v1.BackupName;
+import com.google.spanner.admin.database.v1.BackupSchedule;
+import com.google.spanner.admin.database.v1.BackupScheduleName;
+import com.google.spanner.admin.database.v1.BackupScheduleSpec;
+import com.google.spanner.admin.database.v1.CreateBackupEncryptionConfig;
import com.google.spanner.admin.database.v1.Database;
import com.google.spanner.admin.database.v1.DatabaseDialect;
import com.google.spanner.admin.database.v1.DatabaseName;
@@ -55,6 +61,7 @@
import com.google.spanner.admin.database.v1.GetDatabaseDdlResponse;
import com.google.spanner.admin.database.v1.InstanceName;
import com.google.spanner.admin.database.v1.ListBackupOperationsResponse;
+import com.google.spanner.admin.database.v1.ListBackupSchedulesResponse;
import com.google.spanner.admin.database.v1.ListBackupsResponse;
import com.google.spanner.admin.database.v1.ListDatabaseOperationsResponse;
import com.google.spanner.admin.database.v1.ListDatabaseRolesResponse;
@@ -1079,12 +1086,17 @@ public void createBackupTest() throws Exception {
.setName(BackupName.of("[PROJECT]", "[INSTANCE]", "[BACKUP]").toString())
.setCreateTime(Timestamp.newBuilder().build())
.setSizeBytes(-1796325715)
+ .setFreeableSizeBytes(1302251206)
+ .setExclusiveSizeBytes(-1085921554)
.addAllReferencingDatabases(new ArrayList())
.setEncryptionInfo(EncryptionInfo.newBuilder().build())
.addAllEncryptionInformation(new ArrayList())
.setDatabaseDialect(DatabaseDialect.forNumber(0))
.addAllReferencingBackups(new ArrayList