-
Notifications
You must be signed in to change notification settings - Fork 132
feat: Spanner copy backup ct #1718
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
Conversation
Warning: This pull request is touching the following templated files:
|
Here is the summary of changes. You are about to add 1 region tag.
This comment is generated by snippet-bot.
|
* OperationFuture<Backup, CopyBackupMetadata> op = dbAdminClient | ||
* .copyBackup( | ||
* instanceId, | ||
* sourceBackup, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: sourceBackupId
* "projects/my-project/locations/some-location/keyRings/my-keyring/cryptoKeys/my-key")); | ||
* | ||
* Backup backupToCopy = dbAdminClient | ||
* .newBackupBuilder(destinationBackupId) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we need a sourceBackupId?
public OperationFuture<Backup, CopyBackupMetadata> copyBackup(Backup backupInfo) | ||
throws SpannerException { | ||
Preconditions.checkArgument( | ||
backupInfo.getId() != null, "Cannot create a backup without a source backup"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't the id the destination backup? (from your javadocs?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should also check for the destination backup id as you are doing here
@@ -0,0 +1,42 @@ | |||
diff --git a/samples/snippets/pom.xml b/samples/snippets/pom.xml | |||
index f5d1351a..9ede6f23 100644 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this file?
@@ -44,8 +44,14 @@ | |||
<dependency> | |||
<groupId>com.google.cloud</groupId> | |||
<artifactId>google-cloud-spanner</artifactId> | |||
<version>6.19.1-SNAPSHOT</version> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we added this for testing, but forgot to remove it?
</dependency> | ||
<!-- [END spanner_install_with_bom] --> | ||
<dependency> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
OperationFuture<Backup, CopyBackupMetadata> op = dbAdminClient.copyBackup(backup); | ||
try { | ||
// Wait for the backup operation to complete. | ||
backup = op.get(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a timeout here (it could be a long one).
.getProgress() | ||
.getStartTime(); | ||
} catch (InvalidProtocolBufferException e) { | ||
return null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
returning null makes me worried. Should we throw a RuntimeException?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is OK in this case. We use this to order operations by start time, and this just ensures that if the listBackupOperations
happens to return an operation without a start time (or some other invalid operation) that we just ignore it.
// any referencing backup prevents the backup from being deleted. When the | ||
// copy operation is done (either successfully completed or cancelled or the | ||
// destination backup is deleted), the reference to the backup is removed. | ||
repeated string referencing_backups = 11 [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did we expose this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to expose this in the BackupInfo and when reading the response proto we need to map this.
// multiple APIs: CreateBackup, UpdateBackup, CopyBackup. When updating or | ||
// copying an existing backup, the expiration time specified must be | ||
// less than `Backup.max_expire_time`. | ||
google.protobuf.Timestamp max_expire_time = 12 [(google.api.field_behavior) = OUTPUT_ONLY]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did we expose this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to expose this in the BackupInfo and when reading the response proto we need to map this.
message CopyBackupRequest { | ||
// Required. The name of the destination instance that will contain the backup copy. | ||
// Values are of the form: `projects/<project>/instances/<instance>`. | ||
string parent = 1 [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems we need to populate this, did we?
// any referencing backup prevents the backup from being deleted. When the | ||
// copy operation is done (either successfully completed or cancelled or the | ||
// destination backup is deleted), the reference to the backup is removed. | ||
repeated string referencing_backups = 11 [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to expose this in the BackupInfo and when reading the response proto we need to map this.
// multiple APIs: CreateBackup, UpdateBackup, CopyBackup. When updating or | ||
// copying an existing backup, the expiration time specified must be | ||
// less than `Backup.max_expire_time`. | ||
google.protobuf.Timestamp max_expire_time = 12 [(google.api.field_behavior) = OUTPUT_ONLY]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to expose this in the BackupInfo and when reading the response proto we need to map this.
public OperationFuture<Backup, CopyBackupMetadata> copyBackup(Backup backupInfo) | ||
throws SpannerException { | ||
Preconditions.checkArgument( | ||
backupInfo.getId() != null, "Cannot create a backup without a source backup"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should also check for the destination backup id as you are doing here
CopyBackupRequest.newBuilder() | ||
.setParent(instanceName) | ||
.setBackupId(backupId) | ||
.setSourceBackup(backupId) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be sourceBackupId
.setSourceBackup(sourceBackupId) | ||
.build(); | ||
|
||
Timestamp expireTime = Timestamp.ofTimeMicroseconds(TimeUnit.MICROSECONDS.convert( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the expireTime in the backup to be copied
System.currentTimeMillis() + TimeUnit.DAYS.toMillis(14), TimeUnit.MILLISECONDS)); | ||
|
||
// Initiate the requefst which returns an OperationFuture. | ||
System.out.println("Copying backup [" + backup.getId() + "]..."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the destination backup id, let's print the source backup
@@ -1840,6 +1887,9 @@ static void updateBackup(DatabaseAdminClient dbAdminClient, BackupId backupId) { | |||
TimeUnit.SECONDS.toMicros(backup.getExpireTime().getSeconds()) | |||
+ TimeUnit.NANOSECONDS.toMicros(backup.getExpireTime().getNanos()) | |||
+ TimeUnit.DAYS.toMicros(30L)); | |||
int timeDiff = expireTime.compareTo(backup.getExpireTime()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be removed for now
* | ||
* @param sourceInstanceId the id of the instance where the database to backup is located and | ||
* where the backup will be created. | ||
* @param sourceBackup the source backup id. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: here also sourceBackupId
to be consistent
final String instanceName = backupInfo.getInstanceId().getName(); | ||
final String databaseName = backupInfo.getDatabase().getName(); | ||
final String backupId = backupInfo.getId().getBackup(); | ||
final Backup.Builder backupBuilder = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we are actually using this builder anywhere. Could we remove it?
.getProgress() | ||
.getStartTime(); | ||
} catch (InvalidProtocolBufferException e) { | ||
return null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is OK in this case. We use this to order operations by start time, and this just ensures that if the listBackupOperations
happens to return an operation without a start time (or some other invalid operation) that we just ignore it.
OperationFuture<Backup, CopyBackupMetadata> copyBackUp( | ||
com.google.cloud.spanner.Backup backupInfo) throws SpannerException; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: remove extra empty line
.setEncryptionInfo(ENCRYPTION_INFO) | ||
.setState(com.google.spanner.admin.database.v1.Backup.State.CREATING) | ||
.build(); | ||
com.google.spanner.admin.database.v1.Backup.newBuilder() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More of a question than an action item, but: Do you know why the formatter is changing the indentation here? Are you just using the normal mvn com.coveo:fmt-maven-plugin:format
command, or is this a new format plugin?
feat: max expire time and referencing backup
Closing this PR in the interest of https://github.com/googleapis/java-spanner/pull/1778/files (which contains fixes by @asthamohta and removes autogenerated code) |
chore: upgrade native image checks to graalvm-22.3.0 Source-Link: googleapis/synthtool@5e52896 Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-java:latest@sha256:27b1b1884dce60460d7521b23c2a73376cba90c0ef3d9f0d32e4bdb786959cfd
chore: upgrade native image checks to graalvm-22.3.0 Source-Link: googleapis/synthtool@5e52896 Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-java:latest@sha256:27b1b1884dce60460d7521b23c2a73376cba90c0ef3d9f0d32e4bdb786959cfd Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:
Fixes #<issue_number_goes_here> ☕️