forked from cockroachdb/cockroach
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
kvnemesis: validate writes and locking reads under weak isolation txns
Fixes cockroachdb#100169. This commit updates kvnemesis to validate the atomicity of writes and locking reads under weak isolation transactions, leaving only non-locking reads unvalidated. This strengthens the validation of weak isolation transactions, which were previously in the mix but ignored during validation. In the future, we could explore adding some validation for non-locking reads as well, although this will be both more complex and isolation level dependent (snapshot and read committed behave differently). This enhancement serves an important role in testing the correctness of replicated locking reads under weak isolation transactions, both in that they are never lost like unreplicated locks, and that they enforce isolation even after being released by bumping the timestamp cache on release to the commit timestamp (7702ff8 and 0e6de2b). If I remove either of those two commits, kvnemesis now fails. While here, the commit also bumps the maximum number of operations per transaction from 3 to 5. This creates more interesting transactions. Release note: None
- Loading branch information
1 parent
c5474dd
commit 7ff1c79
Showing
16 changed files
with
444 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
...mesis/testdata/TestValidate/weak_isolation_transaction_with_atomic_locking_replicated_get
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
echo | ||
---- | ||
db0.Put(ctx, tk(1), sv(1)) // @0.000000001,0 <nil> | ||
db0.Put(ctx, tk(1), sv(2)) // @0.000000002,0 <nil> | ||
db0.Txn(ctx, func(ctx context.Context, txn *kv.Txn) error { | ||
txn.SetIsoLevel(isolation.Snapshot) | ||
txn.GetForShareGuaranteedDurability(ctx, tk(1)) // (v2, <nil>) | ||
txn.Put(ctx, tk(3), sv(3)) // <nil> | ||
return nil | ||
}) // @0.000000003,0 <nil> | ||
/Table/100/"0000000000000001"/0.000000001,0 @ s1 v1 | ||
/Table/100/"0000000000000001"/0.000000002,0 @ s2 v2 | ||
/Table/100/"0000000000000003"/0.000000003,0 @ s3 v3 |
13 changes: 13 additions & 0 deletions
13
...estValidate/weak_isolation_transaction_with_atomic_locking_replicated_get_and_missing_key
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
echo | ||
---- | ||
db0.Put(ctx, tk(1), sv(1)) // @0.000000001,0 <nil> | ||
db0.Put(ctx, tk(1), sv(2)) // @0.000000002,0 <nil> | ||
db0.Txn(ctx, func(ctx context.Context, txn *kv.Txn) error { | ||
txn.SetIsoLevel(isolation.Snapshot) | ||
txn.GetForShareGuaranteedDurability(ctx, tk(1)) // (<nil>, <nil>) | ||
txn.Put(ctx, tk(3), sv(3)) // <nil> | ||
return nil | ||
}) // @0.000000003,0 <nil> | ||
/Table/100/"0000000000000001"/0.000000001,0 @ s1 v1 | ||
/Table/100/"0000000000000001"/0.000000002,0 @ s2 v2 | ||
/Table/100/"0000000000000003"/0.000000003,0 @ s3 v3 |
15 changes: 15 additions & 0 deletions
15
...esis/testdata/TestValidate/weak_isolation_transaction_with_atomic_locking_replicated_scan
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
echo | ||
---- | ||
db0.Put(ctx, tk(1), sv(1)) // @0.000000001,0 <nil> | ||
db0.Put(ctx, tk(1), sv(2)) // @0.000000002,0 <nil> | ||
db0.Put(ctx, tk(2), sv(3)) // @0.000000001,0 <nil> | ||
db0.Txn(ctx, func(ctx context.Context, txn *kv.Txn) error { | ||
txn.SetIsoLevel(isolation.Snapshot) | ||
txn.ScanForShareGuaranteedDurability(ctx, tk(1), tk(3), 0) // (/Table/100/"0000000000000001":v2, /Table/100/"0000000000000002":v3, <nil>) | ||
txn.Put(ctx, tk(3), sv(4)) // <nil> | ||
return nil | ||
}) // @0.000000003,0 <nil> | ||
/Table/100/"0000000000000001"/0.000000001,0 @ s1 v1 | ||
/Table/100/"0000000000000001"/0.000000002,0 @ s2 v2 | ||
/Table/100/"0000000000000002"/0.000000001,0 @ s3 v3 | ||
/Table/100/"0000000000000003"/0.000000003,0 @ s4 v4 |
15 changes: 15 additions & 0 deletions
15
...stValidate/weak_isolation_transaction_with_atomic_locking_replicated_scan_and_missing_key
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
echo | ||
---- | ||
db0.Put(ctx, tk(1), sv(1)) // @0.000000001,0 <nil> | ||
db0.Put(ctx, tk(1), sv(2)) // @0.000000002,0 <nil> | ||
db0.Put(ctx, tk(2), sv(3)) // @0.000000001,0 <nil> | ||
db0.Txn(ctx, func(ctx context.Context, txn *kv.Txn) error { | ||
txn.SetIsoLevel(isolation.Snapshot) | ||
txn.ScanForShareGuaranteedDurability(ctx, tk(1), tk(3), 0) // (/Table/100/"0000000000000001":v2, <nil>) | ||
txn.Put(ctx, tk(3), sv(4)) // <nil> | ||
return nil | ||
}) // @0.000000003,0 <nil> | ||
/Table/100/"0000000000000001"/0.000000001,0 @ s1 v1 | ||
/Table/100/"0000000000000001"/0.000000002,0 @ s2 v2 | ||
/Table/100/"0000000000000002"/0.000000001,0 @ s3 v3 | ||
/Table/100/"0000000000000003"/0.000000003,0 @ s4 v4 |
10 changes: 10 additions & 0 deletions
10
pkg/kv/kvnemesis/testdata/TestValidate/weak_isolation_transaction_with_atomic_writes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
echo | ||
---- | ||
db0.Txn(ctx, func(ctx context.Context, txn *kv.Txn) error { | ||
txn.SetIsoLevel(isolation.Snapshot) | ||
txn.Put(ctx, tk(1), sv(1)) // <nil> | ||
txn.Put(ctx, tk(2), sv(2)) // <nil> | ||
return nil | ||
}) // @0.000000002,0 <nil> | ||
/Table/100/"0000000000000001"/0.000000002,0 @ s1 v1 | ||
/Table/100/"0000000000000002"/0.000000002,0 @ s2 v2 |
15 changes: 15 additions & 0 deletions
15
...kv/kvnemesis/testdata/TestValidate/weak_isolation_transaction_with_non-atomic_deleterange
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
echo | ||
---- | ||
db0.Put(ctx, tk(1), sv(1)) // @0.000000001,0 <nil> | ||
db0.Put(ctx, tk(2), sv(2)) // @0.000000002,0 <nil> | ||
db0.Put(ctx, tk(3), sv(3)) // @0.000000001,0 <nil> | ||
db0.Txn(ctx, func(ctx context.Context, txn *kv.Txn) error { | ||
txn.SetIsoLevel(isolation.Snapshot) | ||
txn.DelRange(ctx, tk(1), tk(4), true /* @s4 */) // (/Table/100/"0000000000000001", /Table/100/"0000000000000003", <nil>) | ||
return nil | ||
}) // @0.000000003,0 <nil> | ||
/Table/100/"0000000000000001"/0.000000001,0 @ s1 v1 | ||
/Table/100/"0000000000000001"/0.000000003,0 @ s4 v4 | ||
/Table/100/"0000000000000002"/0.000000002,0 @ s2 v2 | ||
/Table/100/"0000000000000003"/0.000000001,0 @ s3 v3 | ||
/Table/100/"0000000000000003"/0.000000003,0 @ s4 v4 |
14 changes: 14 additions & 0 deletions
14
...s/testdata/TestValidate/weak_isolation_transaction_with_non-atomic_locking_replicated_get
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
echo | ||
---- | ||
db0.Put(ctx, tk(1), sv(1)) // @0.000000001,0 <nil> | ||
db0.Put(ctx, tk(1), sv(2)) // @0.000000002,0 <nil> | ||
db0.Txn(ctx, func(ctx context.Context, txn *kv.Txn) error { | ||
txn.SetIsoLevel(isolation.Snapshot) | ||
txn.GetForShareGuaranteedDurability(ctx, tk(1)) // (v1, <nil>) | ||
txn.Put(ctx, tk(3), sv(3)) // <nil> | ||
return nil | ||
}) // @0.000000003,0 <nil> | ||
/Table/100/"0000000000000001"/0.000000001,0 @ s1 v1 | ||
/Table/100/"0000000000000001"/0.000000002,0 @ s2 v2 | ||
/Table/100/"0000000000000003"/0.000000003,0 @ s3 v3 | ||
committed snapshot txn non-atomic timestamps: [r]/Table/100/"0000000000000001":[0.000000001,0, 0.000000002,0)->v1 [w]/Table/100/"0000000000000003":0.000000003,0->v3@s3 |
16 changes: 16 additions & 0 deletions
16
.../testdata/TestValidate/weak_isolation_transaction_with_non-atomic_locking_replicated_scan
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
echo | ||
---- | ||
db0.Put(ctx, tk(1), sv(1)) // @0.000000001,0 <nil> | ||
db0.Put(ctx, tk(1), sv(2)) // @0.000000002,0 <nil> | ||
db0.Put(ctx, tk(2), sv(3)) // @0.000000001,0 <nil> | ||
db0.Txn(ctx, func(ctx context.Context, txn *kv.Txn) error { | ||
txn.SetIsoLevel(isolation.Snapshot) | ||
txn.ScanForShareGuaranteedDurability(ctx, tk(1), tk(3), 0) // (/Table/100/"0000000000000001":v1, /Table/100/"0000000000000002":v3, <nil>) | ||
txn.Put(ctx, tk(3), sv(4)) // <nil> | ||
return nil | ||
}) // @0.000000003,0 <nil> | ||
/Table/100/"0000000000000001"/0.000000001,0 @ s1 v1 | ||
/Table/100/"0000000000000001"/0.000000002,0 @ s2 v2 | ||
/Table/100/"0000000000000002"/0.000000001,0 @ s3 v3 | ||
/Table/100/"0000000000000003"/0.000000003,0 @ s4 v4 | ||
committed snapshot txn non-atomic timestamps: [r]/Table/100/"0000000000000001":[0.000000001,0, 0.000000002,0)->v1 [r]/Table/100/"0000000000000002":[0.000000001,0, <max>)->v3 [w]/Table/100/"0000000000000003":0.000000003,0->v4@s4 |
13 changes: 13 additions & 0 deletions
13
...testdata/TestValidate/weak_isolation_transaction_with_non-atomic_locking_unreplicated_get
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
echo | ||
---- | ||
db0.Put(ctx, tk(1), sv(1)) // @0.000000001,0 <nil> | ||
db0.Put(ctx, tk(1), sv(2)) // @0.000000002,0 <nil> | ||
db0.Txn(ctx, func(ctx context.Context, txn *kv.Txn) error { | ||
txn.SetIsoLevel(isolation.Snapshot) | ||
txn.GetForShare(ctx, tk(1)) // (v1, <nil>) | ||
txn.Put(ctx, tk(3), sv(3)) // <nil> | ||
return nil | ||
}) // @0.000000003,0 <nil> | ||
/Table/100/"0000000000000001"/0.000000001,0 @ s1 v1 | ||
/Table/100/"0000000000000001"/0.000000002,0 @ s2 v2 | ||
/Table/100/"0000000000000003"/0.000000003,0 @ s3 v3 |
15 changes: 15 additions & 0 deletions
15
...estdata/TestValidate/weak_isolation_transaction_with_non-atomic_locking_unreplicated_scan
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
echo | ||
---- | ||
db0.Put(ctx, tk(1), sv(1)) // @0.000000001,0 <nil> | ||
db0.Put(ctx, tk(1), sv(2)) // @0.000000002,0 <nil> | ||
db0.Put(ctx, tk(2), sv(3)) // @0.000000001,0 <nil> | ||
db0.Txn(ctx, func(ctx context.Context, txn *kv.Txn) error { | ||
txn.SetIsoLevel(isolation.Snapshot) | ||
txn.ScanForShare(ctx, tk(1), tk(3), 0) // (/Table/100/"0000000000000001":v1, /Table/100/"0000000000000002":v3, <nil>) | ||
txn.Put(ctx, tk(3), sv(4)) // <nil> | ||
return nil | ||
}) // @0.000000003,0 <nil> | ||
/Table/100/"0000000000000001"/0.000000001,0 @ s1 v1 | ||
/Table/100/"0000000000000001"/0.000000002,0 @ s2 v2 | ||
/Table/100/"0000000000000002"/0.000000001,0 @ s3 v3 | ||
/Table/100/"0000000000000003"/0.000000003,0 @ s4 v4 |
13 changes: 13 additions & 0 deletions
13
...vnemesis/testdata/TestValidate/weak_isolation_transaction_with_non-atomic_non-locking_get
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
echo | ||
---- | ||
db0.Put(ctx, tk(1), sv(1)) // @0.000000001,0 <nil> | ||
db0.Put(ctx, tk(1), sv(2)) // @0.000000002,0 <nil> | ||
db0.Txn(ctx, func(ctx context.Context, txn *kv.Txn) error { | ||
txn.SetIsoLevel(isolation.Snapshot) | ||
txn.Get(ctx, tk(1)) // (v1, <nil>) | ||
txn.Put(ctx, tk(3), sv(3)) // <nil> | ||
return nil | ||
}) // @0.000000003,0 <nil> | ||
/Table/100/"0000000000000001"/0.000000001,0 @ s1 v1 | ||
/Table/100/"0000000000000001"/0.000000002,0 @ s2 v2 | ||
/Table/100/"0000000000000003"/0.000000003,0 @ s3 v3 |
15 changes: 15 additions & 0 deletions
15
...nemesis/testdata/TestValidate/weak_isolation_transaction_with_non-atomic_non-locking_scan
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
echo | ||
---- | ||
db0.Put(ctx, tk(1), sv(1)) // @0.000000001,0 <nil> | ||
db0.Put(ctx, tk(1), sv(2)) // @0.000000002,0 <nil> | ||
db0.Put(ctx, tk(2), sv(3)) // @0.000000001,0 <nil> | ||
db0.Txn(ctx, func(ctx context.Context, txn *kv.Txn) error { | ||
txn.SetIsoLevel(isolation.Snapshot) | ||
txn.Scan(ctx, tk(1), tk(3), 0) // (/Table/100/"0000000000000001":v1, /Table/100/"0000000000000002":v3, <nil>) | ||
txn.Put(ctx, tk(3), sv(4)) // <nil> | ||
return nil | ||
}) // @0.000000003,0 <nil> | ||
/Table/100/"0000000000000001"/0.000000001,0 @ s1 v1 | ||
/Table/100/"0000000000000001"/0.000000002,0 @ s2 v2 | ||
/Table/100/"0000000000000002"/0.000000001,0 @ s3 v3 | ||
/Table/100/"0000000000000003"/0.000000003,0 @ s4 v4 |
11 changes: 11 additions & 0 deletions
11
pkg/kv/kvnemesis/testdata/TestValidate/weak_isolation_transaction_with_non-atomic_writes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
echo | ||
---- | ||
db0.Txn(ctx, func(ctx context.Context, txn *kv.Txn) error { | ||
txn.SetIsoLevel(isolation.Snapshot) | ||
txn.Put(ctx, tk(1), sv(1)) // <nil> | ||
txn.Put(ctx, tk(2), sv(2)) // <nil> | ||
return nil | ||
}) // @0.000000002,0 <nil> | ||
/Table/100/"0000000000000001"/0.000000001,0 @ s1 v1 | ||
/Table/100/"0000000000000002"/0.000000002,0 @ s2 v2 | ||
committed snapshot txn non-atomic timestamps: [w]/Table/100/"0000000000000001":0.000000001,0->v1@s1 [w]/Table/100/"0000000000000002":0.000000002,0->v2@s2 |
Oops, something went wrong.