From 723e6ec3eb152499b8ebb203a8b708b28d7a3e03 Mon Sep 17 00:00:00 2001 From: kennytm Date: Thu, 2 Apr 2020 06:56:12 +0800 Subject: [PATCH] gluetidb: exclude non-public indices when restoring --- pkg/gluetidb/glue.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/pkg/gluetidb/glue.go b/pkg/gluetidb/glue.go index f6378c6e9..6856b4e75 100644 --- a/pkg/gluetidb/glue.go +++ b/pkg/gluetidb/glue.go @@ -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