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

importccl: create tables before ingesting data #37338

Merged
merged 3 commits into from May 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 0 additions & 2 deletions pkg/ccl/backupccl/backup.go
Expand Up @@ -52,8 +52,6 @@ const (
// BackupDescriptorCheckpointName is the file name used to store the
// serialized BackupDescriptor proto while the backup is in progress.
BackupDescriptorCheckpointName = "BACKUP-CHECKPOINT"
// BackupFormatInitialVersion is the first version of backup and its files.
BackupFormatInitialVersion uint32 = 0
// BackupFormatDescriptorTrackingVersion added tracking of complete DBs.
BackupFormatDescriptorTrackingVersion uint32 = 1
)
Expand Down
16 changes: 8 additions & 8 deletions pkg/ccl/backupccl/restore.go
Expand Up @@ -906,25 +906,25 @@ func WriteTableDescs(
b.CPut(sqlbase.MakeDescMetadataKey(desc.ID), sqlbase.WrapDescriptor(desc), nil)
b.CPut(sqlbase.MakeNameMetadataKey(keys.RootNamespaceID, desc.Name), desc.ID, nil)
}
for _, table := range tables {
if wrote, ok := wroteDBs[table.ParentID]; ok {
table.Privileges = wrote.GetPrivileges()
for i := range tables {
if wrote, ok := wroteDBs[tables[i].ParentID]; ok {
tables[i].Privileges = wrote.GetPrivileges()
} else {
parentDB, err := sqlbase.GetDatabaseDescFromID(ctx, txn, table.ParentID)
parentDB, err := sqlbase.GetDatabaseDescFromID(ctx, txn, tables[i].ParentID)
if err != nil {
return pgerror.NewAssertionErrorWithWrappedErrf(err,
"failed to lookup parent DB %d", log.Safe(table.ParentID))
"failed to lookup parent DB %d", log.Safe(tables[i].ParentID))
}
// TODO(mberhault): CheckPrivilege wants a planner.
if err := sql.CheckPrivilegeForUser(ctx, user, parentDB, privilege.CREATE); err != nil {
return err
}
// Default is to copy privs from restoring parent db, like CREATE TABLE.
// TODO(dt): Make this more configurable.
table.Privileges = parentDB.GetPrivileges()
tables[i].Privileges = parentDB.GetPrivileges()
}
b.CPut(table.GetDescMetadataKey(), sqlbase.WrapDescriptor(table), nil)
b.CPut(table.GetNameMetadataKey(), table.ID, nil)
b.CPut(tables[i].GetDescMetadataKey(), sqlbase.WrapDescriptor(tables[i]), nil)
b.CPut(tables[i].GetNameMetadataKey(), tables[i].ID, nil)
}
for _, kv := range extra {
b.InitPut(kv.Key, &kv.Value, false)
Expand Down