Skip to content

Commit d027619

Browse files
committed
chore: simplify godocs
1 parent 1121cb3 commit d027619

3 files changed

Lines changed: 35 additions & 47 deletions

File tree

internal/datastore/memdb/memdb.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,11 @@ func NewMemdbDatastore(
7171
{
7272
revision: nowRevision(),
7373
schemaHash: "",
74-
// A snapshot of the empty database rather than the database
75-
// itself: reads at this revision must see the datastore as it
76-
// was when it was created, not as it is now.
74+
// A snapshot of the still-empty database rather than the
75+
// database itself, so that a read at the creation revision
76+
// above sees the datastore as it was created rather than as it
77+
// is now. Every later entry likewise holds a snapshot frozen
78+
// at its own revision.
7779
db: db.Snapshot(),
7880
},
7981
},

internal/datastore/memdb/revisions.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,8 @@ func (mdb *memdbDatastore) OptimizedRevision(_ context.Context) (datastore.Revis
8282
optimized = now
8383
}
8484

85-
// Quantization rounds downward, so a datastore created moments ago would
86-
// otherwise advertise a boundary from before it held any snapshot at all.
87-
// No snapshot can serve that revision, so advertise the head revision
88-
// instead: the same fallback Postgres makes when the bucket it rounded back
89-
// to contains no transaction. This can only happen within one quantization
90-
// window of the datastore being created.
85+
// Rounding down can land before the oldest snapshot, which no read can be
86+
// served at. Advertise head instead, as Postgres does for an empty bucket.
9187
if optimized.LessThan(mdb.revisions[0].revision) {
9288
optimized = mdb.headRevisionNoLock()
9389
}

pkg/datastore/test/consistency.go

Lines changed: 28 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,25 @@ import (
1919
"github.com/authzed/spicedb/pkg/zedtoken"
2020
)
2121

22-
// readYourWritesIterations is how many times ReadYourWritesTest repeats its
23-
// write-then-read sequence within a single run.
22+
// readYourWritesIterations is how many write-then-read rounds
23+
// ReadYourWritesTest runs.
2424
const readYourWritesIterations = 50
2525

26-
// ReadYourWritesTest asserts that a write is visible at the revision the API's
27-
// consistency rules select for that write's own ZedToken.
26+
// ReadYourWritesTest asserts that a write is visible at the revision resolved
27+
// from its own ZedToken.
28+
// That is the path a permission check takes right after a write: the write's
29+
// revision becomes a token, the consistency middleware turns the token back
30+
// into a revision, and the data is read there.
2831
//
29-
// It walks the same path as a permission check issued immediately after a
30-
// write: the revision the write returns is encoded into a ZedToken, the
31-
// consistency middleware turns that token back into a revision, and the data
32-
// is read at that revision.
33-
// A datastore that resolves or serves that revision incorrectly loses
34-
// read-your-writes for every caller that round-trips a ZedToken.
32+
// Both consistency modes that carry a token are covered:
3533
//
36-
// Both token-carrying consistency modes are covered:
34+
// - at_exact_snapshot resolves to the token's revision, so the read sees that
35+
// write and nothing later.
36+
// - at_least_as_fresh resolves to the token's revision or the optimized
37+
// revision, whichever is later, so the read never precedes the write.
3738
//
38-
// - at_exact_snapshot resolves to exactly the token's revision, so the read
39-
// sees the world as of that write and nothing later.
40-
// - at_least_as_fresh resolves to the later of the token's revision and the
41-
// datastore's optimized revision, so the read never lands before the write.
42-
//
43-
// The sequence is repeated against one datastore, because the revision a write
44-
// lands on depends on wall-clock timing, quantization boundaries and the
45-
// datastore's own commit ordering: a single pass lands at one arbitrary offset
46-
// into the quantization window and misses whatever the next offset exposes.
39+
// The sequence repeats because each pass lands at a different offset in the
40+
// quantization window, and one offset does not cover the others.
4741
func ReadYourWritesTest(t *testing.T, tester DatastoreTester) {
4842
// Quantization decides which half of at_least_as_fresh does the work.
4943
// With no window the optimized revision has already caught up to the write
@@ -184,34 +178,30 @@ func readYourWrites(t *testing.T, tester DatastoreTester, quantization time.Dura
184178
// ReadYourConcurrentWritesTest keeps in flight at once.
185179
const readYourConcurrentWritesWriters = 16
186180

187-
// readYourConcurrentWritesRounds is how many times ReadYourConcurrentWritesTest
188-
// repeats that concurrent round.
181+
// readYourConcurrentWritesRounds is how many times
182+
// ReadYourConcurrentWritesTest repeats that round.
189183
const readYourConcurrentWritesRounds = 8
190184

191-
// concurrentWrite is one writer's result from a round of
192-
// ReadYourConcurrentWritesTest, recorded in the goroutine that made the write
193-
// and asserted on afterwards by the test goroutine.
185+
// concurrentWrite is one writer's result, recorded in the goroutine that wrote
186+
// it and asserted on later by the test goroutine.
194187
type concurrentWrite struct {
195188
rel tuple.Relationship
196189
rev datastore.Revision
197190
err error
198191
}
199192

200-
// ReadYourConcurrentWritesTest asserts that a write is visible at the revision
201-
// its own ZedToken names when it was committed alongside other writes.
193+
// ReadYourConcurrentWritesTest asserts what ReadYourWritesTest does, for
194+
// writes that commit together.
202195
//
203-
// ReadYourWritesTest issues its writes one at a time, so each one is alone in
204-
// whatever batch the datastore commits it in. A datastore that builds a
205-
// revision out of a commit timestamp and then drops the tiebreaker ordering
206-
// writes that share that timestamp still answers correctly there, because the
207-
// tiebreaker is always zero. Keeping several writes in flight removes that
208-
// condition: writes do share a commit timestamp, and the tiebreaker has to
209-
// survive into the revision for the answers to stay right.
196+
// One write at a time never shares a commit timestamp, so a datastore that
197+
// drops the tiebreaker between writes at the same timestamp still answers
198+
// correctly there.
199+
// Keeping writes in flight makes them share a timestamp, so the tiebreaker has
200+
// to survive into the revision.
210201
//
211-
// The failure this catches is a lost read-your-writes. WriteRelationships
212-
// returns a ZedToken whose revision sorts below the write it names, so a
213-
// CheckPermission carrying that token cannot see the relationship the caller
214-
// just wrote.
202+
// The failure it catches is a lost read-your-writes: the ZedToken names a
203+
// revision that sorts below the write it came from, so a check carrying that
204+
// token cannot see it.
215205
func ReadYourConcurrentWritesTest(t *testing.T, tester DatastoreTester) {
216206
req := require.New(t)
217207

0 commit comments

Comments
 (0)