Skip to content

fix: copy backup issue when backup is done across different instance IDs #2732

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Nov 14, 2023
Merged
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,20 @@ If you are using Maven without the BOM, add this to your dependencies:
If you are using Gradle 5.x or later, add this to your dependencies:

```Groovy
implementation platform('com.google.cloud:libraries-bom:26.25.0')
implementation platform('com.google.cloud:libraries-bom:26.27.0')

implementation 'com.google.cloud:google-cloud-spanner'
```
If you are using Gradle without BOM, add this to your dependencies:

```Groovy
implementation 'com.google.cloud:google-cloud-spanner:6.52.1'
implementation 'com.google.cloud:google-cloud-spanner:6.53.0'
```

If you are using SBT, add this to your dependencies:

```Scala
libraryDependencies += "com.google.cloud" % "google-cloud-spanner" % "6.52.1"
libraryDependencies += "com.google.cloud" % "google-cloud-spanner" % "6.53.0"
```
<!-- {x-version-update-end} -->

Expand Down Expand Up @@ -432,7 +432,7 @@ Java is a registered trademark of Oracle and/or its affiliates.
[kokoro-badge-link-5]: http://storage.googleapis.com/cloud-devrel-public/java/badges/java-spanner/java11.html
[stability-image]: https://img.shields.io/badge/stability-stable-green
[maven-version-image]: https://img.shields.io/maven-central/v/com.google.cloud/google-cloud-spanner.svg
[maven-version-link]: https://central.sonatype.com/artifact/com.google.cloud/google-cloud-spanner/6.52.1
[maven-version-link]: https://central.sonatype.com/artifact/com.google.cloud/google-cloud-spanner/6.53.0
[authentication]: https://github.com/googleapis/google-cloud-java#authentication
[auth-scopes]: https://developers.google.com/identity/protocols/oauth2/scopes
[predefined-iam-roles]: https://cloud.google.com/iam/docs/understanding-roles#predefined_roles
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,6 @@ public Builder setVersionTime(Timestamp versionTime) {

@Override
public Builder setDatabase(DatabaseId database) {
Preconditions.checkArgument(
database.getInstanceId().equals(id.getInstanceId()),
"The instance of the source database must be equal to the instance of the backup.");
this.database = Preconditions.checkNotNull(database);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
public class DatabaseAdminClientImplTest {
private static final String PROJECT_ID = "my-project";
private static final String INSTANCE_ID = "my-instance";
private static final String INSTANCE_ID_2 = "my-instance-2";
private static final String INSTANCE_NAME = "projects/my-project/instances/my-instance";
private static final String DB_ID = "my-db";
private static final String DB_NAME = "projects/my-project/instances/my-instance/databases/my-db";
Expand Down Expand Up @@ -591,6 +592,41 @@ public void copyBackupWithBackupObject() throws ExecutionException, InterruptedE
assertThat(op.get().getId().getName()).isEqualTo(BK_NAME);
}

@Test
public void copyBackupWithBackupObject_onDifferentInstances()
throws ExecutionException, InterruptedException {
Backup testProto =
Backup.newBuilder()
.setName(BK_NAME)
.setDatabase("projects/my-project/instances/my-instance-2/databases/my-db")
.setState(Backup.State.READY)
.build();
final OperationFuture<Backup, CopyBackupMetadata> rawOperationFuture =
OperationFutureUtil.immediateOperationFuture(
"copyBackup", testProto, CopyBackupMetadata.getDefaultInstance());
final Timestamp expireTime =
Timestamp.ofTimeMicroseconds(
TimeUnit.MILLISECONDS.toMicros(System.currentTimeMillis())
+ TimeUnit.HOURS.toMicros(28));
final Timestamp versionTime =
Timestamp.ofTimeMicroseconds(
TimeUnit.MILLISECONDS.toMicros(System.currentTimeMillis()) - TimeUnit.DAYS.toMicros(2));
final com.google.cloud.spanner.Backup requestBackup =
client
.newBackupBuilder(BackupId.of(PROJECT_ID, INSTANCE_ID_2, BK_ID))
.setExpireTime(expireTime)
.setVersionTime(versionTime)
.build();
BackupId sourceBackupId = BackupId.of(PROJECT_ID, INSTANCE_ID, BK_ID);

when(rpc.copyBackup(sourceBackupId, requestBackup)).thenReturn(rawOperationFuture);

final OperationFuture<com.google.cloud.spanner.Backup, CopyBackupMetadata> op =
client.copyBackup(sourceBackupId, requestBackup);
assertThat(op.isDone()).isTrue();
assertThat(op.get().getId().getName()).isEqualTo(BK_NAME);
}

@Test
public void copyEncryptedBackup() throws ExecutionException, InterruptedException {
final OperationFuture<Backup, CopyBackupMetadata> rawOperationFuture =
Expand Down