Skip to content

Commit

Permalink
vtgate: fix race condition iterating tables and views from schema tra…
Browse files Browse the repository at this point in the history
…cker

Signed-off-by: Brendan Dougherty <[email protected]>
  • Loading branch information
brendar committed Jul 31, 2023
1 parent f2c1e01 commit 8c84e88
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions go/vt/vtgate/schema/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,12 @@ func (t *Tracker) Tables(ks string) map[string][]vindexes.Column {
return map[string][]vindexes.Column{} // we know nothing about this KS, so that is the info we can give out
}

return m
dup := make(map[string][]vindexes.Column, len(m))
for k, v := range m {
dup[k] = v
}

return dup
}

// Views returns all known views in the keyspace with their definition.
Expand All @@ -221,7 +226,18 @@ func (t *Tracker) Views(ks string) map[string]sqlparser.SelectStatement {
if t.views == nil {
return nil
}
return t.views.m[ks]

m := t.views.m[ks]
if m == nil {
return nil
}

dup := make(map[string]sqlparser.SelectStatement, len(m))
for k, v := range m {
dup[k] = v
}

return dup
}

func (t *Tracker) updateSchema(th *discovery.TabletHealth) bool {
Expand Down

0 comments on commit 8c84e88

Please sign in to comment.