Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions internal/servers/destination/v0/destinations.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (s *Server) Migrate(ctx context.Context, req *pb.Migrate_Request) (*pb.Migr
if err := json.Unmarshal(req.Tables, &tablesV2); err != nil {
return nil, status.Errorf(codes.InvalidArgument, "failed to unmarshal tables: %v", err)
}
tables := TablesV2ToV3(tablesV2)
tables := TablesV2ToV3(tablesV2).FlattenTables()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is the destination server, presumably it got the list from the source - so shouldn't the tables already be flattened? I know there can be issues if you flatten a list of tables twice, so we either need to be 100% sure or make FlattenTables idempotent :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. yeah that's a foot gun. not sure what's hapening already. ok let's make it idempotent.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

SetDestinationManagedCqColumns(tables)
s.setPKsForTables(tables)

Expand Down Expand Up @@ -97,7 +97,7 @@ func (s *Server) Write2(msg pb.Destination_Write2Server) error {
return status.Errorf(codes.InvalidArgument, "failed to unmarshal source spec: %v", err)
}
}
tables := TablesV2ToV3(tablesV2)
tables := TablesV2ToV3(tablesV2).FlattenTables()
syncTime := r.Timestamp.AsTime()
SetDestinationManagedCqColumns(tables)
s.setPKsForTables(tables)
Expand Down Expand Up @@ -201,12 +201,8 @@ func (s *Server) DeleteStale(ctx context.Context, req *pb.DeleteStale_Request) (
if err := json.Unmarshal(req.Tables, &tablesV2); err != nil {
return nil, status.Errorf(codes.InvalidArgument, "failed to unmarshal tables: %v", err)
}
tables := TablesV2ToV3(tablesV2)
tables := TablesV2ToV3(tablesV2).FlattenTables()
SetDestinationManagedCqColumns(tables)
schemas := make(schemav2.Schemas, len(tables.FlattenTables()))
for i, table := range tables.FlattenTables() {
schemas[i] = table.ToArrowSchema()
}
if err := s.Plugin.DeleteStale(ctx, tables, req.Source, req.Timestamp.AsTime()); err != nil {
return nil, err
}
Expand Down
11 changes: 10 additions & 1 deletion schema/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,16 @@ func (tt Tables) FlattenTables() Tables {
tables = append(tables, t)
tables = append(tables, t.Relations.FlattenTables()...)
}
return tables
tableNames := make(map[string]bool)
dedupedTables := make(Tables, 0, len(tables))
for _, t := range tables {
if _, found := tableNames[t.Name]; !found {
dedupedTables = append(dedupedTables, t)
tableNames[t.Name] = true
}
}

return dedupedTables
}

func (tt Tables) TableNames() []string {
Expand Down
4 changes: 4 additions & 0 deletions schema/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ func TestTablesFlatten(t *testing.T) {
if len(tables) != 2 {
t.Fatal("expected 2 tables")
}
tables = Tables{testTable}.FlattenTables()
if len(tables) != 2 {
t.Fatal("expected 2 tables")
}
}

func TestTablesFilterDFS(t *testing.T) {
Expand Down