table: fix data race in select builder usage

When table is used with SelectBuilder it triggers data race on Where()
condition usage.

This change copies underlining slices on table creation to allow safe
concurrent usage of the table.
This commit is contained in:
Aleksandar Jankovic
2020-02-25 12:35:44 +01:00
committed by Michal Jan Matczuk
parent c36e6c5e66
commit ab2a96d9f3
2 changed files with 60 additions and 1 deletions

View File

@@ -45,7 +45,8 @@ func New(m Metadata) *Table { // nolint: gocritic
for _, k := range m.SortKey {
t.primaryKeyCmp = append(t.primaryKeyCmp, qb.Eq(k))
}
t.partKeyCmp = t.primaryKeyCmp[:len(t.metadata.PartKey)]
t.partKeyCmp = make([]qb.Cmp, len(m.PartKey))
copy(t.partKeyCmp, t.primaryKeyCmp[:len(t.metadata.PartKey)])
// prepare get stmt
t.get.stmt, t.get.names = qb.Select(m.Name).Where(t.primaryKeyCmp...).ToCql()