Skip to content
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

feat(bigtable): allow restore backup to different instance (#3489) #4014

Merged
merged 22 commits into from May 3, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 9 additions & 2 deletions bigtable/admin.go
Expand Up @@ -1457,10 +1457,17 @@ func UpdateInstanceAndSyncClusters(ctx context.Context, iac *InstanceAdminClient

// RestoreTable creates a table from a backup. The table will be created in the same cluster as the backup.
func (ac *AdminClient) RestoreTable(ctx context.Context, table, cluster, backup string) error {
return ac.RestoreTableTo(ctx, ac.instance, table, cluster, backup)
}

// RestoreTableTo creates a new table by restoring from this completed backup.
//
// diffInstance is an instance in which the new table will be restored to.
// Instance must be in the same project as the project containing backup.
func (ac *AdminClient) RestoreTableTo(ctx context.Context, diffInstance, table, cluster, backup string) error {
kolea2 marked this conversation as resolved.
Show resolved Hide resolved
ctx = mergeOutgoingMetadata(ctx, ac.md)
prefix := ac.instancePrefix()
prefix := "projects/" + ac.project + "/instances/" + diffInstance
kolea2 marked this conversation as resolved.
Show resolved Hide resolved
backupPath := ac.backupPath(cluster, backup)

req := &btapb.RestoreTableRequest{
Parent: prefix,
TableId: table,
Expand Down
45 changes: 45 additions & 0 deletions bigtable/integration_test.go
Expand Up @@ -2257,6 +2257,26 @@ func TestIntegration_AdminBackup(t *testing.T) {
table := testEnv.Config().Table
cluster := testEnv.Config().Cluster

iAdminClient, err := testEnv.NewInstanceAdminClient()
if err != nil {
t.Fatalf("NewInstanceAdminClient: %v", err)
}
defer iAdminClient.Close()
diffInstance := testEnv.Config().Instance + "-diff"
diffCluster := cluster + "-diff"
conf := &InstanceConf{
InstanceId: diffInstance,
ClusterId: diffCluster,
DisplayName: "different test instance",
Zone: instanceToCreateZone2,
InstanceType: DEVELOPMENT,
kolea2 marked this conversation as resolved.
Show resolved Hide resolved
Labels: map[string]string{"test-label-key": "test-label-value"},
}
defer iAdminClient.DeleteInstance(ctx, diffInstance)
// Create different instance to restore table.
if err := iAdminClient.CreateInstance(ctx, conf); err != nil {
t.Fatalf("CreateInstance: %v", err)
}
// Delete the table at the end of the test. Schedule ahead of time
// in case the client fails
defer deleteTable(ctx, t, adminClient, table)
Expand Down Expand Up @@ -2353,6 +2373,31 @@ func TestIntegration_AdminBackup(t *testing.T) {
if _, err := adminClient.TableInfo(ctx, restoredTable); err != nil {
t.Fatalf("Restored TableInfo: %v", err)
}
// Restore backup to different instance
diffTable := table + "-diff-restored"
diffConf := IntegrationTestConfig{
Project: testEnv.Config().Project,
Instance: diffInstance,
Cluster: diffCluster,
Table: diffTable,
}
env := &ProdEnv{
config: diffConf,
}
dAdminClient, err := env.NewAdminClient()
if err != nil {
t.Fatalf("NewAdminClient: %v", err)
}
defer dAdminClient.Close()

defer deleteTable(ctx, t, dAdminClient, diffTable)
if err = adminClient.RestoreTableTo(ctx, diffInstance, diffTable, cluster, "mybackup"); err != nil {
t.Fatalf("RestoreTableTo: %v", err)
kolea2 marked this conversation as resolved.
Show resolved Hide resolved
}
_, err = dAdminClient.TableInfo(ctx, diffTable)
kolea2 marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
t.Fatalf("Restored to different instance TableInfo: %v", err)
kolea2 marked this conversation as resolved.
Show resolved Hide resolved
}

// Delete backup
if err = adminClient.DeleteBackup(ctx, cluster, backupName); err != nil {
Expand Down