Skip to content

Commit

Permalink
Merge pull request #1695 from josephschorr/cleaner-revisions
Browse files Browse the repository at this point in the history
Major cleanup and improvements around revision handling in the datastores
  • Loading branch information
josephschorr authored Dec 22, 2023
2 parents ecb23d0 + 1fc3e2b commit 6e72bb7
Show file tree
Hide file tree
Showing 62 changed files with 1,195 additions and 471 deletions.
9 changes: 9 additions & 0 deletions e2e/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,37 @@ require (
require (
github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230512164433-5d1fd1a340c9 // indirect
github.com/authzed/cel-go v0.17.5 // indirect
github.com/benbjohnson/clock v1.3.5 // indirect
github.com/certifi/gocertifi v0.0.0-20210507211836-431795d63e8d // indirect
github.com/cockroachdb/apd v1.1.0 // indirect
github.com/creasty/defaults v1.7.0 // indirect
github.com/dave/jennifer v1.6.1 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/envoyproxy/protoc-gen-validate v1.0.2 // indirect
github.com/fatih/structtag v1.2.0 // indirect
github.com/go-logr/logr v1.3.0 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
github.com/jzelinskie/stringz v0.0.2 // indirect
github.com/lib/pq v1.10.9 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/planetscale/vtprotobuf v0.5.1-0.20231212170721-e7d721933795 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/rs/zerolog v1.31.0 // indirect
github.com/samber/lo v1.38.1 // indirect
github.com/shopspring/decimal v1.3.1 // indirect
github.com/stoewer/go-strcase v1.3.0 // indirect
go.opentelemetry.io/otel v1.21.0 // indirect
go.opentelemetry.io/otel/metric v1.21.0 // indirect
go.opentelemetry.io/otel/trace v1.21.0 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
golang.org/x/mod v0.13.0 // indirect
Expand Down
7 changes: 7 additions & 0 deletions e2e/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ github.com/cncf/udpa/go v0.0.0-20220112060539-c52dc94e7fbe h1:QQ3GSy+MqSHxm/d8nC
github.com/cncf/udpa/go v0.0.0-20220112060539-c52dc94e7fbe/go.mod h1:6pvJx4me5XPnfI9Z40ddWsdw2W/uZgQLFXToKeRcDiI=
github.com/cncf/xds/go v0.0.0-20230607035331-e9ce68804cb4 h1:/inchEIKaYC1Akx+H+gqO04wryn5h75LSazbRlnya1k=
github.com/cncf/xds/go v0.0.0-20230607035331-e9ce68804cb4/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cockroachdb/apd v1.1.0 h1:3LFP3629v+1aKXU5Q37mxmRxX/pIu1nijXydLShEq5I=
github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ=
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/creasty/defaults v1.7.0 h1:eNdqZvc5B509z18lD8yc212CAqJNvfT1Jq6L8WowdBA=
github.com/creasty/defaults v1.7.0/go.mod h1:iGzKe6pbEHnpMPtfDXZEr0NVxWnPTjb1bbDy08fPzYM=
Expand Down Expand Up @@ -91,6 +93,7 @@ github.com/go-kit/log v0.2.1/go.mod h1:NwTd00d/i8cPZ3xOwwiv2PO5MOcx78fFErGNcVmBj
github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A=
github.com/go-logfmt/logfmt v0.5.1 h1:otpy5pqBCBZ1ng9RQ0dPu4PN7ba75Y/aA+UpowDyNVA=
github.com/go-logfmt/logfmt v0.5.1/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.3.0 h1:2y3SDp0ZXuc6/cjLSZ+Q3ir+QB9T/iG5yYRXqsagWSY=
github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
Expand Down Expand Up @@ -158,6 +161,8 @@ github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 h1:SOEGU9fKiNWd/HOJuq
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0/go.mod h1:dXGbAdH5GtBTC4WfIxhKZfyBF/HBFgRZSWwZ9g/He9o=
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 h1:P6pPBnrTSX3DEVR4fDembhRWSsG5rVo6hYhAB/ADZrk=
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0/go.mod h1:vmVJ0l/dxyfGW6FmdpVm2joNMFikkuWg0EoCKLGUMNw=
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/lthibault/jitterbug v2.0.0+incompatible h1:qouq51IKzlMx25+15jbxhC/d79YyTj0q6XFoptNqaUw=
github.com/lthibault/jitterbug v2.0.0+incompatible/go.mod h1:2l7akWd27PScEs6YkjyUVj/8hKgNhbbQ3KiJgJtlf6o=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
Expand All @@ -174,6 +179,7 @@ github.com/ngrok/sqlmw v0.0.0-20220520173518-97c9c04efc79 h1:Dmx8g2747UTVPzSkmoh
github.com/ngrok/sqlmw v0.0.0-20220520173518-97c9c04efc79/go.mod h1:E26fwEtRNigBfFfHDWsklmo0T7Ixbg0XXgck+Hq4O9k=
github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/planetscale/vtprotobuf v0.5.1-0.20231212170721-e7d721933795 h1:pH+U6pJP0BhxqQ4njBUjOg0++WMMvv3eByWzB+oATBY=
github.com/planetscale/vtprotobuf v0.5.1-0.20231212170721-e7d721933795/go.mod h1:t/avpk3KcrXxUnYOhZhMXJlSEyie6gQbtLq5NM3loB8=
Expand Down Expand Up @@ -212,6 +218,7 @@ github.com/stoewer/go-strcase v1.3.0/go.mod h1:fAH5hQ5pehh+j3nZfvwdk2RgEgQjAoM8w
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
Expand Down
6 changes: 3 additions & 3 deletions e2e/newenemy/newenemy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/stretchr/testify/require"
"google.golang.org/grpc/metadata"

"github.com/authzed/spicedb/pkg/datastore/revision"
"github.com/authzed/spicedb/internal/datastore/revisions"
"github.com/authzed/spicedb/pkg/zedtoken"

"github.com/authzed/spicedb/e2e"
Expand Down Expand Up @@ -396,8 +396,8 @@ func checkDataNoNewEnemy(ctx context.Context, t testing.TB, slowNodeID int, crdb
ns2AllowlistLeader := getLeaderNodeForNamespace(ctx, crdb[2].Conn(), allowlists[i].Relationship.Subject.Object.ObjectType)

r1leader, r2leader := getLeaderNode(ctx, crdb[2].Conn(), blockusers[i].Relationship), getLeaderNode(ctx, crdb[2].Conn(), allowlists[i].Relationship)
z1, _ := zedtoken.DecodeRevision(r1.WrittenAt, revision.DecimalDecoder{})
z2, _ := zedtoken.DecodeRevision(r2.WrittenAt, revision.DecimalDecoder{})
z1, _ := zedtoken.DecodeRevision(r1.WrittenAt, revisions.CommonDecoder{Kind: revisions.HybridLogicalClock})
z2, _ := zedtoken.DecodeRevision(r2.WrittenAt, revisions.CommonDecoder{Kind: revisions.HybridLogicalClock})
t.Log(sleep, z1, z2, z1.GreaterThan(z2), r1leader, r2leader, ns1BlocklistLeader, ns1UserLeader, ns2ResourceLeader, ns2AllowlistLeader)

if z1.GreaterThan(z2) {
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ require (
github.com/cenkalti/backoff/v4 v4.2.1
github.com/cespare/xxhash/v2 v2.2.0
github.com/cloudspannerecosystem/spanner-change-streams-tail v0.3.1
github.com/cockroachdb/apd v1.1.0
github.com/creasty/defaults v1.7.0
github.com/dalzilio/rudd v1.1.1-0.20230806153452-9e08a6ea8170
github.com/dlmiddlecote/sqlstats v1.0.2
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ github.com/cncf/udpa/go v0.0.0-20220112060539-c52dc94e7fbe/go.mod h1:6pvJx4me5XP
github.com/cncf/xds/go v0.0.0-20210922020428-25de7278fc84/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cncf/xds/go v0.0.0-20230607035331-e9ce68804cb4 h1:/inchEIKaYC1Akx+H+gqO04wryn5h75LSazbRlnya1k=
github.com/cncf/xds/go v0.0.0-20230607035331-e9ce68804cb4/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cockroachdb/apd v1.1.0 h1:3LFP3629v+1aKXU5Q37mxmRxX/pIu1nijXydLShEq5I=
github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ=
github.com/containerd/console v1.0.3/go.mod h1:7LqA/THxQ86k76b8c/EMSiaJ3h1eZkMkXar0TQ1gf3U=
github.com/containerd/continuity v0.3.0 h1:nisirsYROK15TAMVukJOUyGJjz4BNQJBVsNvAXZJ/eg=
github.com/containerd/continuity v0.3.0/go.mod h1:wJEAIwKOm/pBZuBd0JmeTvnLquTB1Ag8espWhkykbPM=
Expand Down
121 changes: 97 additions & 24 deletions internal/datastore/common/changes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ import (
"strings"
"testing"

"github.com/shopspring/decimal"
"github.com/stretchr/testify/require"

"github.com/authzed/spicedb/internal/datastore/revisions"
"github.com/authzed/spicedb/pkg/datastore"
"github.com/authzed/spicedb/pkg/datastore/revision"
core "github.com/authzed/spicedb/pkg/proto/core/v1"
"github.com/authzed/spicedb/pkg/tuple"
)
Expand All @@ -21,17 +20,13 @@ const (
)

var (
rev1 = revision.NewFromDecimal(decimal.NewFromInt(1))
rev2 = revision.NewFromDecimal(decimal.NewFromInt(2))
rev3 = revision.NewFromDecimal(decimal.NewFromInt(3))
revOneMillion = revision.NewFromDecimal(decimal.NewFromInt(1_000_000))
revOneMillionOne = revision.NewFromDecimal(decimal.NewFromInt(1_000_001))
rev1 = revisions.NewForTransactionID(1)
rev2 = revisions.NewForTransactionID(2)
rev3 = revisions.NewForTransactionID(3)
revOneMillion = revisions.NewForTransactionID(1_000_000)
revOneMillionOne = revisions.NewForTransactionID(1_000_001)
)

func revisionFromTransactionID(txID uint64) revision.Decimal {
return revision.NewFromDecimal(decimal.NewFromInt(int64(txID)))
}

func TestChanges(t *testing.T) {
type changeEntry struct {
revision uint64
Expand Down Expand Up @@ -310,38 +305,38 @@ func TestChanges(t *testing.T) {
require := require.New(t)

ctx := context.Background()
ch := NewChanges(revision.DecimalKeyFunc, datastore.WatchRelationships|datastore.WatchSchema)
ch := NewChanges(revisions.TransactionIDKeyFunc, datastore.WatchRelationships|datastore.WatchSchema)
for _, step := range tc.script {
if step.relationship != "" {
rel := tuple.MustParse(step.relationship)
err := ch.AddRelationshipChange(ctx, revisionFromTransactionID(step.revision), rel, step.op)
err := ch.AddRelationshipChange(ctx, revisions.NewForTransactionID(step.revision), rel, step.op)
require.NoError(err)
}

for _, changed := range step.changedDefinitions {
ch.AddChangedDefinition(ctx, revisionFromTransactionID(step.revision), changed)
ch.AddChangedDefinition(ctx, revisions.NewForTransactionID(step.revision), changed)
}

for _, ns := range step.deletedNamespaces {
ch.AddDeletedNamespace(ctx, revisionFromTransactionID(step.revision), ns)
ch.AddDeletedNamespace(ctx, revisions.NewForTransactionID(step.revision), ns)
}

for _, c := range step.deletedCaveats {
ch.AddDeletedCaveat(ctx, revisionFromTransactionID(step.revision), c)
ch.AddDeletedCaveat(ctx, revisions.NewForTransactionID(step.revision), c)
}
}

require.Equal(
canonicalize(tc.expected),
canonicalize(ch.AsRevisionChanges(revision.DecimalKeyLessThanFunc)),
canonicalize(ch.AsRevisionChanges(revisions.TransactionIDKeyLessThanFunc)),
)
})
}
}

func TestFilteredSchemaChanges(t *testing.T) {
ctx := context.Background()
ch := NewChanges(revision.DecimalKeyFunc, datastore.WatchSchema)
ch := NewChanges(revisions.TransactionIDKeyFunc, datastore.WatchSchema)
require.True(t, ch.IsEmpty())

require.NoError(t, ch.AddRelationshipChange(ctx, rev1, tuple.MustParse("document:firstdoc#viewer@user:tom"), core.RelationTupleUpdate_TOUCH))
Expand All @@ -350,7 +345,7 @@ func TestFilteredSchemaChanges(t *testing.T) {

func TestFilteredRelationshipChanges(t *testing.T) {
ctx := context.Background()
ch := NewChanges(revision.DecimalKeyFunc, datastore.WatchRelationships)
ch := NewChanges(revisions.TransactionIDKeyFunc, datastore.WatchRelationships)
require.True(t, ch.IsEmpty())

ch.AddDeletedNamespace(ctx, rev3, "deletedns3")
Expand All @@ -359,7 +354,7 @@ func TestFilteredRelationshipChanges(t *testing.T) {

func TestFilterAndRemoveRevisionChanges(t *testing.T) {
ctx := context.Background()
ch := NewChanges(revision.DecimalKeyFunc, datastore.WatchRelationships|datastore.WatchSchema)
ch := NewChanges(revisions.TransactionIDKeyFunc, datastore.WatchRelationships|datastore.WatchSchema)

require.True(t, ch.IsEmpty())

Expand All @@ -369,7 +364,7 @@ func TestFilterAndRemoveRevisionChanges(t *testing.T) {

require.False(t, ch.IsEmpty())

results := ch.FilterAndRemoveRevisionChanges(revision.DecimalKeyLessThanFunc, rev3)
results := ch.FilterAndRemoveRevisionChanges(revisions.TransactionIDKeyLessThanFunc, rev3)
require.Equal(t, 2, len(results))
require.False(t, ch.IsEmpty())

Expand All @@ -388,7 +383,7 @@ func TestFilterAndRemoveRevisionChanges(t *testing.T) {
},
}, results)

remaining := ch.AsRevisionChanges(revision.DecimalKeyLessThanFunc)
remaining := ch.AsRevisionChanges(revisions.TransactionIDKeyLessThanFunc)
require.Equal(t, 1, len(remaining))

require.Equal(t, []datastore.RevisionChanges{
Expand All @@ -400,15 +395,93 @@ func TestFilterAndRemoveRevisionChanges(t *testing.T) {
},
}, remaining)

results = ch.FilterAndRemoveRevisionChanges(revision.DecimalKeyLessThanFunc, revOneMillion)
results = ch.FilterAndRemoveRevisionChanges(revisions.TransactionIDKeyLessThanFunc, revOneMillion)
require.Equal(t, 1, len(results))
require.True(t, ch.IsEmpty())

results = ch.FilterAndRemoveRevisionChanges(revision.DecimalKeyLessThanFunc, revOneMillionOne)
results = ch.FilterAndRemoveRevisionChanges(revisions.TransactionIDKeyLessThanFunc, revOneMillionOne)
require.Equal(t, 0, len(results))
require.True(t, ch.IsEmpty())
}

func TestHLCOrdering(t *testing.T) {
ctx := context.Background()

ch := NewChanges(revisions.HLCKeyFunc, datastore.WatchRelationships|datastore.WatchSchema)
require.True(t, ch.IsEmpty())

rev1, err := revisions.HLCRevisionFromString("1.1")
require.NoError(t, err)

rev0, err := revisions.HLCRevisionFromString("1.0")
require.NoError(t, err)

err = ch.AddRelationshipChange(ctx, rev1, tuple.MustParse("document:foo#viewer@user:tom"), core.RelationTupleUpdate_DELETE)
require.NoError(t, err)

err = ch.AddRelationshipChange(ctx, rev0, tuple.MustParse("document:foo#viewer@user:tom"), core.RelationTupleUpdate_TOUCH)
require.NoError(t, err)

remaining := ch.AsRevisionChanges(revisions.HLCKeyLessThanFunc)
require.Equal(t, 2, len(remaining))

require.Equal(t, []datastore.RevisionChanges{
{
Revision: rev0,
RelationshipChanges: []*core.RelationTupleUpdate{
tuple.Touch(tuple.MustParse("document:foo#viewer@user:tom")),
},
DeletedNamespaces: []string{},
DeletedCaveats: []string{},
ChangedDefinitions: []datastore.SchemaDefinition{},
},
{
Revision: rev1,
RelationshipChanges: []*core.RelationTupleUpdate{
tuple.Delete(tuple.MustParse("document:foo#viewer@user:tom")),
},
DeletedNamespaces: []string{},
DeletedCaveats: []string{},
ChangedDefinitions: []datastore.SchemaDefinition{},
},
}, remaining)
}

func TestHLCSameRevision(t *testing.T) {
ctx := context.Background()

ch := NewChanges(revisions.HLCKeyFunc, datastore.WatchRelationships|datastore.WatchSchema)
require.True(t, ch.IsEmpty())

rev0, err := revisions.HLCRevisionFromString("1.0")
require.NoError(t, err)

rev0again, err := revisions.HLCRevisionFromString("1.0")
require.NoError(t, err)

err = ch.AddRelationshipChange(ctx, rev0, tuple.MustParse("document:foo#viewer@user:tom"), core.RelationTupleUpdate_TOUCH)
require.NoError(t, err)

err = ch.AddRelationshipChange(ctx, rev0again, tuple.MustParse("document:foo#viewer@user:sarah"), core.RelationTupleUpdate_TOUCH)
require.NoError(t, err)

remaining := ch.AsRevisionChanges(revisions.HLCKeyLessThanFunc)
require.Equal(t, 1, len(remaining))

require.Equal(t, []datastore.RevisionChanges{
{
Revision: rev0,
RelationshipChanges: []*core.RelationTupleUpdate{
tuple.Touch(tuple.MustParse("document:foo#viewer@user:tom")),
tuple.Touch(tuple.MustParse("document:foo#viewer@user:sarah")),
},
DeletedNamespaces: []string{},
DeletedCaveats: []string{},
ChangedDefinitions: []datastore.SchemaDefinition{},
},
}, remaining)
}

func TestCanonicalize(t *testing.T) {
testCases := []struct {
name string
Expand Down
11 changes: 5 additions & 6 deletions internal/datastore/common/gc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,18 @@ import (
"testing"
"time"

"github.com/authzed/spicedb/internal/datastore/revisions"
"github.com/authzed/spicedb/pkg/datastore"
"github.com/authzed/spicedb/pkg/datastore/revision"

"github.com/prometheus/client_golang/prometheus"
promclient "github.com/prometheus/client_model/go"
"github.com/shopspring/decimal"
"github.com/stretchr/testify/require"
)

// Fake garbage collector that returns a new incremented revision each time
// TxIDBefore is called.
type fakeGC struct {
lastRevision int64
lastRevision uint64
deleter gcDeleter
metrics gcMetrics
lock sync.RWMutex
Expand Down Expand Up @@ -56,7 +55,7 @@ func (gc *fakeGC) TxIDBefore(_ context.Context, _ time.Time) (datastore.Revision

gc.lastRevision++

rev := revision.NewFromDecimal(decimal.NewFromInt(gc.lastRevision))
rev := revisions.NewForTransactionID(gc.lastRevision)

return rev, nil
}
Expand All @@ -67,9 +66,9 @@ func (gc *fakeGC) DeleteBeforeTx(_ context.Context, rev datastore.Revision) (Del

gc.metrics.deleteBeforeTxCount++

revInt := rev.(revision.Decimal).Decimal.IntPart()
revInt := rev.(revisions.TransactionIDRevision).TransactionID()

return gc.deleter.DeleteBeforeTx(revInt)
return gc.deleter.DeleteBeforeTx(int64(revInt))
}

func (gc *fakeGC) HasGCRun() bool {
Expand Down
5 changes: 3 additions & 2 deletions internal/datastore/crdb/caveat.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
sq "github.com/Masterminds/squirrel"
"github.com/jackc/pgx/v5"

"github.com/authzed/spicedb/internal/datastore/revisions"
"github.com/authzed/spicedb/pkg/datastore"
core "github.com/authzed/spicedb/pkg/proto/core/v1"
)
Expand Down Expand Up @@ -58,7 +59,7 @@ func (cr *crdbReader) ReadCaveatByName(ctx context.Context, name string) (*core.
return nil, datastore.NoRevision, fmt.Errorf(errReadCaveat, name, err)
}
cr.addOverlapKey(name)
return loaded, revisionFromTimestamp(timestamp), nil
return loaded, revisions.NewHLCForTime(timestamp), nil
}

func (cr *crdbReader) LookupCaveatsWithNames(ctx context.Context, caveatNames []string) ([]datastore.RevisionedCaveat, error) {
Expand Down Expand Up @@ -116,7 +117,7 @@ func (cr *crdbReader) lookupCaveats(ctx context.Context, caveatNames []string) (
}
caveats = append(caveats, datastore.RevisionedCaveat{
Definition: loaded,
LastWrittenRevision: revisionFromTimestamp(bat.timestamp),
LastWrittenRevision: revisions.NewHLCForTime(bat.timestamp),
})
}

Expand Down
Loading

0 comments on commit 6e72bb7

Please sign in to comment.