Skip to content

Commit

Permalink
gluetidb: exclude non-public indices when restoring
Browse files Browse the repository at this point in the history
  • Loading branch information
kennytm committed Apr 2, 2020
1 parent 5c280d8 commit d9e67b6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
10 changes: 10 additions & 0 deletions pkg/backup/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,16 @@ func BuildBackupRangeAndSchema(
zap.Stringer("table", tableInfo.Name),
zap.Int64("AutoIncID", globalAutoID))

// remove all non-public indices
n := 0
for _, index := range tableInfo.Indices {
if index.State == model.StatePublic {
tableInfo.Indices[n] = index
n++
}
}
tableInfo.Indices = tableInfo.Indices[:n]

if dbData == nil {
dbData, err = json.Marshal(dbInfo)
if err != nil {
Expand Down
11 changes: 10 additions & 1 deletion pkg/gluetidb/glue.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,16 @@ func (gs *tidbSession) CreateDatabase(ctx context.Context, schema *model.DBInfo)
// CreateTable implements glue.Session
func (gs *tidbSession) CreateTable(ctx context.Context, dbName model.CIStr, table *model.TableInfo) error {
d := domain.GetDomain(gs.se).DDL()
return d.CreateTableWithInfo(gs.se, dbName, table.Clone(), ddl.OnExistIgnore, true)

// Clone() does not clone partitions yet :(
table = table.Clone()
if table.Partition != nil {
newPartition := *table.Partition
newPartition.Definitions = append([]model.PartitionDefinition{}, table.Partition.Definitions...)
table.Partition = &newPartition
}

return d.CreateTableWithInfo(gs.se, dbName, table, ddl.OnExistIgnore, true)
}

// Close implements glue.Session
Expand Down

0 comments on commit d9e67b6

Please sign in to comment.