Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

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 723e6ec
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion pkg/gluetidb/glue.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,26 @@ 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)

// remove all non-public indices (perhaps they shouldn't be backed up in the first place)
n := 0
for _, index := range table.Indices {
if index.State == model.StatePublic {
table.Indices[n] = index
n++
}
}
table.Indices = table.Indices[:n]

// 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 723e6ec

Please sign in to comment.