Skip to content

Commit

Permalink
crdb: touch overlap key on namespace write
Browse files Browse the repository at this point in the history
this will ensure that namespace write transactions conflict with tuple
write transactions, and prevent the newenemy problem for interactions
such as:

- write namespace (always fully consistent)
- write a tuple
- do a check with the revision from the tuple write
  • Loading branch information
ecordell committed Jan 4, 2022
1 parent 6c294c7 commit 41f1a6b
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion internal/datastore/crdb/namespace.go
Expand Up @@ -44,6 +44,8 @@ var (
func (cds *crdbDatastore) WriteNamespace(ctx context.Context, newConfig *v0.NamespaceDefinition) (datastore.Revision, error) {
var hlcNow decimal.Decimal
if err := cds.execute(ctx, cds.conn, pgx.TxOptions{}, func(tx pgx.Tx) error {
keySet := newKeySet()
cds.AddOverlapKey(keySet, newConfig.Name)
serialized, err := proto.Marshal(newConfig)
if err != nil {
return err
Expand All @@ -54,7 +56,12 @@ func (cds *crdbDatastore) WriteNamespace(ctx context.Context, newConfig *v0.Name
if err != nil {
return err
}
return cds.conn.QueryRow(
for k := range keySet {
if _, err := tx.Exec(ctx, queryTouchTransaction, k); err != nil {
return err
}
}
return tx.QueryRow(
datastore.SeparateContextWithTracing(ctx), writeSQL, writeArgs...,
).Scan(&hlcNow)
}); err != nil {
Expand Down

0 comments on commit 41f1a6b

Please sign in to comment.