Skip to content

Commit c16c1c3

Browse files
committed
chore(datastore): expose GC interfaces, errors, and context proxy
1 parent 0509498 commit c16c1c3

31 files changed

+347
-390
lines changed

e2e/go.mod

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ require (
3939
github.com/aws/aws-sdk-go-v2/service/sts v1.41.3 // indirect
4040
github.com/aws/smithy-go v1.24.0 // indirect
4141
github.com/benbjohnson/clock v1.3.5 // indirect
42+
github.com/beorn7/perks v1.0.1 // indirect
4243
github.com/ccoveille/go-safecast/v2 v2.0.0 // indirect
44+
github.com/cenkalti/backoff/v5 v5.0.3 // indirect
4345
github.com/certifi/gocertifi v0.0.0-20210507211836-431795d63e8d // indirect
4446
github.com/cespare/xxhash/v2 v2.3.0 // indirect
4547
github.com/creasty/defaults v1.8.0 // indirect
@@ -61,17 +63,23 @@ require (
6163
github.com/jzelinskie/stringz v0.0.3 // indirect
6264
github.com/mattn/go-colorable v0.1.14 // indirect
6365
github.com/mattn/go-isatty v0.0.20 // indirect
66+
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
6467
github.com/onsi/ginkgo/v2 v2.26.0 // indirect
6568
github.com/onsi/gomega v1.38.2 // indirect
6669
github.com/planetscale/vtprotobuf v0.6.1-0.20240917153116-6f2963f01587 // indirect
6770
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
71+
github.com/prometheus/client_golang v1.23.2 // indirect
72+
github.com/prometheus/client_model v0.6.2 // indirect
73+
github.com/prometheus/common v0.67.5 // indirect
74+
github.com/prometheus/procfs v0.19.2 // indirect
6875
github.com/rs/zerolog v1.34.0 // indirect
6976
github.com/shopspring/decimal v1.4.0 // indirect
7077
github.com/stoewer/go-strcase v1.3.1 // indirect
7178
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
7279
go.opentelemetry.io/otel v1.40.0 // indirect
7380
go.opentelemetry.io/otel/metric v1.40.0 // indirect
7481
go.opentelemetry.io/otel/trace v1.40.0 // indirect
82+
go.yaml.in/yaml/v2 v2.4.3 // indirect
7583
golang.org/x/crypto v0.46.0 // indirect
7684
golang.org/x/exp v0.0.0-20250819193227-8b4c13bb791b // indirect
7785
golang.org/x/mod v0.31.0 // indirect

e2e/go.sum

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,6 @@ github.com/benbjohnson/clock v1.3.5 h1:VvXlSJBzZpA/zum6Sj74hxwYI2DIxRWuNIoXAzHZz
8585
github.com/benbjohnson/clock v1.3.5/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
8686
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
8787
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
88-
github.com/bits-and-blooms/bitset v1.24.2 h1:M7/NzVbsytmtfHbumG+K2bremQPMJuqv1JD3vOaFxp0=
89-
github.com/bits-and-blooms/bitset v1.24.2/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8=
90-
github.com/bits-and-blooms/bloom/v3 v3.7.1 h1:WXovk4TRKZttAMJfoQx6K2DM0zNIt8w+c67UqO+etV0=
91-
github.com/bits-and-blooms/bloom/v3 v3.7.1/go.mod h1:rZzYLLje2dfzXfAkJNxQQHsKurAyK55KUnL43Euk0hU=
9288
github.com/brianvoe/gofakeit/v6 v6.28.0 h1:Xib46XXuQfmlLS2EXRuJpqcw8St6qSZz75OUo0tgAW4=
9389
github.com/brianvoe/gofakeit/v6 v6.28.0/go.mod h1:Xj58BMSnFqcn/fAQeSK+/PLtC5kSb7FJIq4JyGa8vEs=
9490
github.com/ccoveille/go-safecast/v2 v2.0.0 h1:+5eyITXAUj3wMjad6cRVJKGnC7vDS55zk0INzJagub0=
@@ -109,8 +105,6 @@ github.com/cncf/xds/go v0.0.0-20251022180443-0feb69152e9f/go.mod h1:HlzOvOjVBOfT
109105
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
110106
github.com/creasty/defaults v1.8.0 h1:z27FJxCAa0JKt3utc0sCImAEb+spPucmKoOdLHvHYKk=
111107
github.com/creasty/defaults v1.8.0/go.mod h1:iGzKe6pbEHnpMPtfDXZEr0NVxWnPTjb1bbDy08fPzYM=
112-
github.com/dalzilio/rudd v1.1.1-0.20230806153452-9e08a6ea8170 h1:bHEN1z3EOO/IXHTQ8ZcmGoW4gTJt+mSrH2Sd458uo0E=
113-
github.com/dalzilio/rudd v1.1.1-0.20230806153452-9e08a6ea8170/go.mod h1:IxPC4Bdi3WqUwyGBMgLrWWGx67aRtUAZmOZrkIr7qaM=
114108
github.com/dave/jennifer v1.7.1 h1:B4jJJDHelWcDhlRQxWeo0Npa/pYKBLrirAQoTN45txo=
115109
github.com/dave/jennifer v1.7.1/go.mod h1:nXbxhEmQfOZhWml3D1cDK5M1FLnMSozpbFN/m3RmGZc=
116110
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=

internal/datastore/common/errors.go

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414

1515
log "github.com/authzed/spicedb/internal/logging"
1616
"github.com/authzed/spicedb/pkg/spiceerrors"
17-
"github.com/authzed/spicedb/pkg/tuple"
1817
)
1918

2019
// SerializationError is returned when there's been a serialization
@@ -92,60 +91,6 @@ func NewReadOnlyTransactionError(err error) error {
9291
}
9392
}
9493

95-
// CreateRelationshipExistsError is an error returned when attempting to CREATE an already-existing
96-
// relationship.
97-
type CreateRelationshipExistsError struct {
98-
error
99-
100-
// Relationship is the relationship that caused the error. May be nil, depending on the datastore.
101-
Relationship *tuple.Relationship
102-
}
103-
104-
// GRPCStatus implements retrieving the gRPC status for the error.
105-
func (err CreateRelationshipExistsError) GRPCStatus() *status.Status {
106-
if err.Relationship == nil {
107-
return spiceerrors.WithCodeAndDetails(
108-
err,
109-
codes.AlreadyExists,
110-
spiceerrors.ForReason(
111-
v1.ErrorReason_ERROR_REASON_ATTEMPT_TO_RECREATE_RELATIONSHIP,
112-
map[string]string{},
113-
),
114-
)
115-
}
116-
117-
relationship := tuple.ToV1Relationship(*err.Relationship)
118-
return spiceerrors.WithCodeAndDetails(
119-
err,
120-
codes.AlreadyExists,
121-
spiceerrors.ForReason(
122-
v1.ErrorReason_ERROR_REASON_ATTEMPT_TO_RECREATE_RELATIONSHIP,
123-
map[string]string{
124-
"relationship": tuple.V1StringRelationshipWithoutCaveatOrExpiration(relationship),
125-
"resource_type": relationship.Resource.ObjectType,
126-
"resource_object_id": relationship.Resource.ObjectId,
127-
"resource_relation": relationship.Relation,
128-
"subject_type": relationship.Subject.Object.ObjectType,
129-
"subject_object_id": relationship.Subject.Object.ObjectId,
130-
"subject_relation": relationship.Subject.OptionalRelation,
131-
},
132-
),
133-
)
134-
}
135-
136-
// NewCreateRelationshipExistsError creates a new CreateRelationshipExistsError.
137-
func NewCreateRelationshipExistsError(relationship *tuple.Relationship) error {
138-
msg := "could not CREATE one or more relationships, as they already existed. If this is persistent, please switch to TOUCH operations or specify a precondition"
139-
if relationship != nil {
140-
msg = fmt.Sprintf("could not CREATE relationship `%s`, as it already existed. If this is persistent, please switch to TOUCH operations or specify a precondition", tuple.StringWithoutCaveatOrExpiration(*relationship))
141-
}
142-
143-
return CreateRelationshipExistsError{
144-
errors.New(msg),
145-
relationship,
146-
}
147-
}
148-
14994
var (
15095
portMatchRegex = regexp.MustCompile("invalid port \\\"(.+)\\\" after host")
15196
parseMatchRegex = regexp.MustCompile("parse \\\"(.+)\\\":")

internal/datastore/common/sql.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"time"
1111

1212
sq "github.com/Masterminds/squirrel"
13-
"go.opentelemetry.io/otel"
1413
"go.opentelemetry.io/otel/attribute"
1514

1615
v1 "github.com/authzed/authzed-go/proto/authzed/api/v1"
@@ -48,8 +47,6 @@ var (
4847
// SubObjectIDKey is a tracing attribute representing the the subject object
4948
// ID.
5049
SubObjectIDKey = attribute.Key("authzed.com/spicedb/sql/subObjectId")
51-
52-
tracer = otel.Tracer("spicedb/internal/datastore/common")
5350
)
5451

5552
// PaginationFilterType is an enumerator for pagination filter types.

internal/datastore/context.go

Lines changed: 0 additions & 150 deletions
This file was deleted.

internal/datastore/crdb/crdb.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"golang.org/x/sync/errgroup"
2323
"resenje.org/singleflight"
2424

25-
datastoreinternal "github.com/authzed/spicedb/internal/datastore"
2625
"github.com/authzed/spicedb/internal/datastore/common"
2726
"github.com/authzed/spicedb/internal/datastore/crdb/migrations"
2827
"github.com/authzed/spicedb/internal/datastore/crdb/pool"
@@ -254,7 +253,7 @@ func NewCRDBDatastore(ctx context.Context, url string, options ...Option) (datas
254253
return nil, err
255254
}
256255

257-
return datastoreinternal.NewSeparatingContextDatastoreProxy(ds), nil
256+
return datastore.NewSeparatingContextDatastoreProxy(ds), nil
258257
}
259258

260259
type crdbDatastore struct {

internal/datastore/crdb/crdb_test.go

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,7 @@ const (
5757
veryLargeGCInterval = 90000 * time.Second
5858
)
5959

60-
// Implement the TestableDatastore interface
61-
func (cds *crdbDatastore) ExampleRetryableError() error {
62-
return &pgconn.PgError{
63-
Code: pool.CrdbRetryErrCode,
64-
}
65-
}
60+
var crdbFactory = test.NewTesterFactory(&pgconn.PgError{Code: pool.CrdbRetryErrCode})
6661

6762
func crdbTestVersion() string {
6863
ver := os.Getenv("CRDB_TEST_VERSION")
@@ -76,7 +71,7 @@ func crdbTestVersion() string {
7671
func TestCRDBDatastoreWithoutIntegrity(t *testing.T) {
7772
t.Parallel()
7873
b := testdatastore.RunCRDBForTesting(t, "", crdbTestVersion())
79-
test.All(t, test.DatastoreTesterFunc(func(_ testing.TB, revisionQuantization, gcInterval, gcWindow time.Duration, watchBufferLength uint16) (datastore.Datastore, error) {
74+
test.All(t, crdbFactory.NewTester(test.DatastoreTesterFunc(func(_ testing.TB, revisionQuantization, gcInterval, gcWindow time.Duration, watchBufferLength uint16) (datastore.Datastore, error) {
8075
ctx := context.Background()
8176
ds := b.NewDatastore(t, func(engine, uri string) datastore.Datastore {
8277
ds, err := NewCRDBDatastore(
@@ -97,7 +92,7 @@ func TestCRDBDatastoreWithoutIntegrity(t *testing.T) {
9792
})
9893

9994
return ds, nil
100-
}), false)
95+
})), false)
10196

10297
t.Run("TestWatchStreaming", createDatastoreTest(
10398
b,
@@ -204,7 +199,7 @@ func TestCRDBDatastoreWithIntegrity(t *testing.T) { //nolint:tparallel
204199
t.Parallel()
205200
b := testdatastore.RunCRDBForTesting(t, "", crdbTestVersion())
206201

207-
test.All(t, test.DatastoreTesterFunc(func(_ testing.TB, revisionQuantization, gcInterval, gcWindow time.Duration, watchBufferLength uint16) (datastore.Datastore, error) {
202+
test.All(t, crdbFactory.NewTester(test.DatastoreTesterFunc(func(_ testing.TB, revisionQuantization, gcInterval, gcWindow time.Duration, watchBufferLength uint16) (datastore.Datastore, error) {
208203
ctx := context.Background()
209204
ds := b.NewDatastore(t, func(engine, uri string) datastore.Datastore {
210205
ds, err := NewCRDBDatastore(
@@ -229,7 +224,7 @@ func TestCRDBDatastoreWithIntegrity(t *testing.T) { //nolint:tparallel
229224
})
230225

231226
return ds, nil
232-
}), false)
227+
})), false)
233228

234229
unwrappedTester := test.DatastoreTesterFunc(func(_ testing.TB, revisionQuantization, gcInterval, gcWindow time.Duration, watchBufferLength uint16) (datastore.Datastore, error) {
235230
ctx := context.Background()

internal/datastore/memdb/memdb_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,17 @@ import (
1919
"github.com/authzed/spicedb/pkg/tuple"
2020
)
2121

22+
var memdbFactory = test.NewTesterFactory(ErrSerialization)
23+
2224
type memDBTest struct{}
2325

24-
func (mdbt memDBTest) New(_ testing.TB, revisionQuantization, _, gcWindow time.Duration, watchBufferLength uint16) (datastore.Datastore, error) {
26+
func (memDBTest) New(_ testing.TB, revisionQuantization, _, gcWindow time.Duration, watchBufferLength uint16) (datastore.Datastore, error) {
2527
return NewMemdbDatastore(watchBufferLength, revisionQuantization, gcWindow)
2628
}
2729

2830
func TestMemdbDatastore(t *testing.T) {
2931
t.Parallel()
30-
test.All(t, memDBTest{}, true)
32+
test.All(t, memdbFactory.NewTester(memDBTest{}), true)
3133
}
3234

3335
func TestConcurrentWritePanic(t *testing.T) {

internal/datastore/memdb/readwrite.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111

1212
v1 "github.com/authzed/authzed-go/proto/authzed/api/v1"
1313

14-
"github.com/authzed/spicedb/internal/datastore/common"
1514
"github.com/authzed/spicedb/pkg/datastore"
1615
"github.com/authzed/spicedb/pkg/datastore/options"
1716
core "github.com/authzed/spicedb/pkg/proto/core/v1"
@@ -90,7 +89,7 @@ func (rwt *memdbReadWriteTx) write(tx *memdb.Txn, mutations ...tuple.Relationshi
9089
if err != nil {
9190
return err
9291
}
93-
return common.NewCreateRelationshipExistsError(&rt)
92+
return datastore.NewCreateRelationshipExistsError(&rt)
9493
}
9594
if err := tx.Insert(tableRelationship, rel); err != nil {
9695
return fmt.Errorf("error inserting relationship: %w", err)

0 commit comments

Comments
 (0)