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 Dec 28, 2021
1 parent 698ec60 commit 5a01ad7
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 5a01ad7

Please sign in to comment.