Skip to content

Commit

Permalink
Use existing vindexes when they are identical to what we wanted to cr…
Browse files Browse the repository at this point in the history
…eate

Signed-off-by: Matt Lord <[email protected]>
  • Loading branch information
mattlord committed Jun 10, 2024
1 parent b49494e commit 2be60e9
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions go/vt/vtctl/workflow/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3768,7 +3768,7 @@ func (s *Server) prepareCreateLookup(ctx context.Context, workflow, keyspace str
targetVSchema.Tables = make(map[string]*vschemapb.Table)
}
if existing, ok := sourceVSchema.Vindexes[vindexName]; ok {
if !proto.Equal(existing, vindex) {
if !proto.Equal(existing, vindex) { // If the exact same vindex already exists then we can re-use it
return nil, nil, nil, vterrors.Errorf(vtrpcpb.Code_INTERNAL, "a conflicting vindex named %s already exists in the %s keyspace", vindexName, keyspace)
}
}
Expand All @@ -3781,13 +3781,19 @@ func (s *Server) prepareCreateLookup(ctx context.Context, workflow, keyspace str
if colVindex.Name != vindexName {
continue
}
colName := colVindex.Column
if len(colVindex.Columns) != 0 {
colName = colVindex.Columns[0]
}
if colName == sourceVindexColumns[0] {
return nil, nil, nil, vterrors.Errorf(vtrpcpb.Code_INVALID_ARGUMENT, "a conflicting ColumnVindex on column %s in table %s already exists in the %s keyspace",
colName, sourceTableName, keyspace)
var colNames []string
if len(colVindex.Columns) == 0 {
colNames = []string{colVindex.Column}
} else {
colNames = colVindex.Columns
}
// If this is the exact same definition then we can use the existing one. If they
// are not the same then they are two distinct conflicting vindexes and we should
// not proceed.
if !slices.Equal(colNames, sourceVindexColumns) {
log.Errorf("DEBUG: existing Vindex: %v, new Vindex: %v", colVindex, vindex)
return nil, nil, nil, vterrors.Errorf(vtrpcpb.Code_INVALID_ARGUMENT, "a conflicting ColumnVindex on column(s) %s in table %s already exists in the %s keyspace",
strings.Join(colNames, ","), sourceTableName, keyspace)
}
}

Expand Down

0 comments on commit 2be60e9

Please sign in to comment.