Skip to content

Commit

Permalink
fix: copy backup issue when backup is done across different instance …
Browse files Browse the repository at this point in the history
…IDs (#2732)

* fix: prevent illegal negative timeout values into thread sleep() method while retrying exceptions in unit tests.

* For details on issue see - #2206

* Fixing lint issues.

* fix: reproduce issue with copy backup.

* fix: copy backup issue when backup is done across different instance IDs.

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

---------

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
  • Loading branch information
arpan14 and gcf-owl-bot[bot] authored Nov 14, 2023
1 parent 8618042 commit 7f6b158
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
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

0 comments on commit 7f6b158

Please sign in to comment.