Skip to content

Commit

Permalink
Merge pull request #652 from josephschorr/cleanup-core
Browse files Browse the repository at this point in the history
Cleanup the core messages now that v0 is gone
  • Loading branch information
jakedt authored Jun 20, 2022
2 parents baa4abc + 094c1f7 commit c6f3b29
Show file tree
Hide file tree
Showing 48 changed files with 1,281 additions and 1,648 deletions.
21 changes: 8 additions & 13 deletions internal/datastore/common/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,21 +247,16 @@ func NewPGXExecutor(txSource TxFactory) ExecuteQueryFunc {
var tuples []*core.RelationTuple
for rows.Next() {
nextTuple := &core.RelationTuple{
ObjectAndRelation: &core.ObjectAndRelation{},
User: &core.User{
UserOneof: &core.User_Userset{
Userset: &core.ObjectAndRelation{},
},
},
ResourceAndRelation: &core.ObjectAndRelation{},
Subject: &core.ObjectAndRelation{},
}
userset := nextTuple.User.GetUserset()
err := rows.Scan(
&nextTuple.ObjectAndRelation.Namespace,
&nextTuple.ObjectAndRelation.ObjectId,
&nextTuple.ObjectAndRelation.Relation,
&userset.Namespace,
&userset.ObjectId,
&userset.Relation,
&nextTuple.ResourceAndRelation.Namespace,
&nextTuple.ResourceAndRelation.ObjectId,
&nextTuple.ResourceAndRelation.Relation,
&nextTuple.Subject.Namespace,
&nextTuple.Subject.ObjectId,
&nextTuple.Subject.Relation,
)
if err != nil {
return nil, fmt.Errorf(errUnableToQueryTuples, err)
Expand Down
14 changes: 5 additions & 9 deletions internal/datastore/crdb/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,19 +113,15 @@ func (cds *crdbDatastore) Watch(ctx context.Context, afterRevision datastore.Rev

oneChange := &core.RelationTupleUpdate{
Tuple: &core.RelationTuple{
ObjectAndRelation: &core.ObjectAndRelation{
ResourceAndRelation: &core.ObjectAndRelation{
Namespace: pkValues[0],
ObjectId: pkValues[1],
Relation: pkValues[2],
},
User: &core.User{
UserOneof: &core.User_Userset{
Userset: &core.ObjectAndRelation{
Namespace: pkValues[3],
ObjectId: pkValues[4],
Relation: pkValues[5],
},
},
Subject: &core.ObjectAndRelation{
Namespace: pkValues[3],
ObjectId: pkValues[4],
Relation: pkValues[5],
},
},
}
Expand Down
6 changes: 3 additions & 3 deletions internal/datastore/memdb/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,16 @@ func (r relationship) Relationship() *v1.Relationship {

func (r relationship) RelationTuple() *core.RelationTuple {
return &core.RelationTuple{
ObjectAndRelation: &core.ObjectAndRelation{
ResourceAndRelation: &core.ObjectAndRelation{
Namespace: r.namespace,
ObjectId: r.resourceID,
Relation: r.relation,
},
User: &core.User{UserOneof: &core.User_Userset{Userset: &core.ObjectAndRelation{
Subject: &core.ObjectAndRelation{
Namespace: r.subjectNamespace,
ObjectId: r.subjectObjectID,
Relation: r.subjectRelation,
}}},
},
}
}

Expand Down
22 changes: 9 additions & 13 deletions internal/datastore/mysql/datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,21 +337,17 @@ func newMySQLExecutor(tx querier) common.ExecuteQueryFunc {
var tuples []*core.RelationTuple
for rows.Next() {
nextTuple := &core.RelationTuple{
ObjectAndRelation: &core.ObjectAndRelation{},
User: &core.User{
UserOneof: &core.User_Userset{
Userset: &core.ObjectAndRelation{},
},
},
ResourceAndRelation: &core.ObjectAndRelation{},
Subject: &core.ObjectAndRelation{},
}
userset := nextTuple.User.GetUserset()

err := rows.Scan(
&nextTuple.ObjectAndRelation.Namespace,
&nextTuple.ObjectAndRelation.ObjectId,
&nextTuple.ObjectAndRelation.Relation,
&userset.Namespace,
&userset.ObjectId,
&userset.Relation,
&nextTuple.ResourceAndRelation.Namespace,
&nextTuple.ResourceAndRelation.ObjectId,
&nextTuple.ResourceAndRelation.Relation,
&nextTuple.Subject.Namespace,
&nextTuple.Subject.ObjectId,
&nextTuple.Subject.Relation,
)
if err != nil {
return nil, fmt.Errorf(errUnableToQueryTuples, err)
Expand Down
18 changes: 9 additions & 9 deletions internal/datastore/mysql/datastore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,16 +173,16 @@ func GarbageCollectionTest(t *testing.T, ds datastore.Datastore) {
// Write a relationship.

tpl := &corev1.RelationTuple{
ObjectAndRelation: &corev1.ObjectAndRelation{
ResourceAndRelation: &corev1.ObjectAndRelation{
Namespace: "resource",
ObjectId: "someresource",
Relation: "reader",
},
User: &corev1.User{UserOneof: &corev1.User_Userset{Userset: &corev1.ObjectAndRelation{
Subject: &corev1.ObjectAndRelation{
Namespace: "user",
ObjectId: "someuser",
Relation: "...",
}}},
},
}
relationship := tuple.ToRelationship(tpl)

Expand Down Expand Up @@ -321,16 +321,16 @@ func GarbageCollectionByTimeTest(t *testing.T, ds datastore.Datastore) {

// Write a relationship.
tpl := &corev1.RelationTuple{
ObjectAndRelation: &corev1.ObjectAndRelation{
ResourceAndRelation: &corev1.ObjectAndRelation{
Namespace: "resource",
ObjectId: "someresource",
Relation: "reader",
},
User: &corev1.User{UserOneof: &corev1.User_Userset{Userset: &corev1.ObjectAndRelation{
Subject: &corev1.ObjectAndRelation{
Namespace: "user",
ObjectId: "someuser",
Relation: "...",
}}},
},
}
relationship := tuple.ToRelationship(tpl)

Expand Down Expand Up @@ -406,16 +406,16 @@ func ChunkedGarbageCollectionTest(t *testing.T, ds datastore.Datastore) {
var tuples []*corev1.RelationTuple
for i := 0; i < chunkRelationshipCount; i++ {
tpl := &corev1.RelationTuple{
ObjectAndRelation: &corev1.ObjectAndRelation{
ResourceAndRelation: &corev1.ObjectAndRelation{
Namespace: "resource",
ObjectId: fmt.Sprintf("resource-%d", i),
Relation: "reader",
},
User: &corev1.User{UserOneof: &corev1.User_Userset{Userset: &corev1.ObjectAndRelation{
Subject: &corev1.ObjectAndRelation{
Namespace: "user",
ObjectId: "someuser",
Relation: "...",
}}},
},
}
tuples = append(tuples, tpl)
}
Expand Down
27 changes: 11 additions & 16 deletions internal/datastore/mysql/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,25 +113,20 @@ func (mds *Datastore) loadChanges(
stagedChanges := common.NewChanges()

for rows.Next() {
userset := &core.ObjectAndRelation{}
tpl := &core.RelationTuple{
ObjectAndRelation: &core.ObjectAndRelation{},
User: &core.User{
UserOneof: &core.User_Userset{
Userset: userset,
},
},
nextTuple := &core.RelationTuple{
ResourceAndRelation: &core.ObjectAndRelation{},
Subject: &core.ObjectAndRelation{},
}

var createdTxn uint64
var deletedTxn uint64
err = rows.Scan(
&tpl.ObjectAndRelation.Namespace,
&tpl.ObjectAndRelation.ObjectId,
&tpl.ObjectAndRelation.Relation,
&userset.Namespace,
&userset.ObjectId,
&userset.Relation,
&nextTuple.ResourceAndRelation.Namespace,
&nextTuple.ResourceAndRelation.ObjectId,
&nextTuple.ResourceAndRelation.Relation,
&nextTuple.Subject.Namespace,
&nextTuple.Subject.ObjectId,
&nextTuple.Subject.Relation,
&createdTxn,
&deletedTxn,
)
Expand All @@ -140,11 +135,11 @@ func (mds *Datastore) loadChanges(
}

if createdTxn > afterRevision && createdTxn <= newRevision {
stagedChanges.AddChange(ctx, revisionFromTransaction(createdTxn), tpl, core.RelationTupleUpdate_TOUCH)
stagedChanges.AddChange(ctx, revisionFromTransaction(createdTxn), nextTuple, core.RelationTupleUpdate_TOUCH)
}

if deletedTxn > afterRevision && deletedTxn <= newRevision {
stagedChanges.AddChange(ctx, revisionFromTransaction(deletedTxn), tpl, core.RelationTupleUpdate_DELETE)
stagedChanges.AddChange(ctx, revisionFromTransaction(deletedTxn), nextTuple, core.RelationTupleUpdate_DELETE)
}
}
if err = rows.Err(); err != nil {
Expand Down
20 changes: 10 additions & 10 deletions internal/datastore/postgres/postgres_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,16 +139,16 @@ func GarbageCollectionTest(t *testing.T, ds datastore.Datastore) {

// Write a relationship.
tpl := &core.RelationTuple{
ObjectAndRelation: &core.ObjectAndRelation{
ResourceAndRelation: &core.ObjectAndRelation{
Namespace: "resource",
ObjectId: "someresource",
Relation: "reader",
},
User: &core.User{UserOneof: &core.User_Userset{Userset: &core.ObjectAndRelation{
Subject: &core.ObjectAndRelation{
Namespace: "user",
ObjectId: "someuser",
Relation: "...",
}}},
},
}
relationship := tuple.ToRelationship(tpl)

Expand Down Expand Up @@ -312,16 +312,16 @@ func GarbageCollectionByTimeTest(t *testing.T, ds datastore.Datastore) {

// Write a relationship.
tpl := &core.RelationTuple{
ObjectAndRelation: &core.ObjectAndRelation{
ResourceAndRelation: &core.ObjectAndRelation{
Namespace: "resource",
ObjectId: "someresource",
Relation: "reader",
},
User: &core.User{UserOneof: &core.User_Userset{Userset: &core.ObjectAndRelation{
Subject: &core.ObjectAndRelation{
Namespace: "user",
ObjectId: "someuser",
Relation: "...",
}}},
},
}
relationship := tuple.ToRelationship(tpl)

Expand Down Expand Up @@ -396,16 +396,16 @@ func ChunkedGarbageCollectionTest(t *testing.T, ds datastore.Datastore) {
var tpls []*core.RelationTuple
for i := 0; i < chunkRelationshipCount; i++ {
tpl := &core.RelationTuple{
ObjectAndRelation: &core.ObjectAndRelation{
ResourceAndRelation: &core.ObjectAndRelation{
Namespace: "resource",
ObjectId: fmt.Sprintf("resource-%d", i),
Relation: "reader",
},
User: &core.User{UserOneof: &core.User_Userset{Userset: &core.ObjectAndRelation{
Subject: &core.ObjectAndRelation{
Namespace: "user",
ObjectId: "someuser",
Relation: "...",
}}},
},
}
tpls = append(tpls, tpl)
}
Expand Down Expand Up @@ -611,7 +611,7 @@ func BenchmarkPostgresQuery(b *testing.B) {
defer iter.Close()

for tpl := iter.Next(); tpl != nil; tpl = iter.Next() {
require.Equal(testfixtures.DocumentNS.Name, tpl.ObjectAndRelation.Namespace)
require.Equal(testfixtures.DocumentNS.Name, tpl.ResourceAndRelation.Namespace)
}
require.NoError(iter.Err())
}
Expand Down
27 changes: 11 additions & 16 deletions internal/datastore/postgres/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,25 +118,20 @@ func (pgd *pgDatastore) loadChanges(
stagedChanges := common.NewChanges()

for rows.Next() {
userset := &core.ObjectAndRelation{}
tpl := &core.RelationTuple{
ObjectAndRelation: &core.ObjectAndRelation{},
User: &core.User{
UserOneof: &core.User_Userset{
Userset: userset,
},
},
nextTuple := &core.RelationTuple{
ResourceAndRelation: &core.ObjectAndRelation{},
Subject: &core.ObjectAndRelation{},
}

var createdTxn uint64
var deletedTxn uint64
err = rows.Scan(
&tpl.ObjectAndRelation.Namespace,
&tpl.ObjectAndRelation.ObjectId,
&tpl.ObjectAndRelation.Relation,
&userset.Namespace,
&userset.ObjectId,
&userset.Relation,
&nextTuple.ResourceAndRelation.Namespace,
&nextTuple.ResourceAndRelation.ObjectId,
&nextTuple.ResourceAndRelation.Relation,
&nextTuple.Subject.Namespace,
&nextTuple.Subject.ObjectId,
&nextTuple.Subject.Relation,
&createdTxn,
&deletedTxn,
)
Expand All @@ -145,11 +140,11 @@ func (pgd *pgDatastore) loadChanges(
}

if createdTxn > afterRevision && createdTxn <= newRevision {
stagedChanges.AddChange(ctx, revisionFromTransaction(createdTxn), tpl, core.RelationTupleUpdate_TOUCH)
stagedChanges.AddChange(ctx, revisionFromTransaction(createdTxn), nextTuple, core.RelationTupleUpdate_TOUCH)
}

if deletedTxn > afterRevision && deletedTxn <= newRevision {
stagedChanges.AddChange(ctx, revisionFromTransaction(deletedTxn), tpl, core.RelationTupleUpdate_DELETE)
stagedChanges.AddChange(ctx, revisionFromTransaction(deletedTxn), nextTuple, core.RelationTupleUpdate_DELETE)
}
}
if err = rows.Err(); err != nil {
Expand Down
14 changes: 5 additions & 9 deletions internal/datastore/proxy/hedging_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,19 +295,15 @@ func TestDatastoreE2E(t *testing.T) {

expectedTuples := []*core.RelationTuple{
{
ObjectAndRelation: &core.ObjectAndRelation{
ResourceAndRelation: &core.ObjectAndRelation{
Namespace: "test",
ObjectId: "test",
Relation: "test",
},
User: &core.User{
UserOneof: &core.User_Userset{
Userset: &core.ObjectAndRelation{
Namespace: "test",
ObjectId: "test",
Relation: "test",
},
},
Subject: &core.ObjectAndRelation{
Namespace: "test",
ObjectId: "test",
Relation: "test",
},
},
}
Expand Down
21 changes: 8 additions & 13 deletions internal/datastore/spanner/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,21 +94,16 @@ func queryExecutor(txSource txFactory) common.ExecuteQueryFunc {

if err := iter.Do(func(row *spanner.Row) error {
nextTuple := &core.RelationTuple{
ObjectAndRelation: &core.ObjectAndRelation{},
User: &core.User{
UserOneof: &core.User_Userset{
Userset: &core.ObjectAndRelation{},
},
},
ResourceAndRelation: &core.ObjectAndRelation{},
Subject: &core.ObjectAndRelation{},
}
userset := nextTuple.User.GetUserset()
err := row.Columns(
&nextTuple.ObjectAndRelation.Namespace,
&nextTuple.ObjectAndRelation.ObjectId,
&nextTuple.ObjectAndRelation.Relation,
&userset.Namespace,
&userset.ObjectId,
&userset.Relation,
&nextTuple.ResourceAndRelation.Namespace,
&nextTuple.ResourceAndRelation.ObjectId,
&nextTuple.ResourceAndRelation.Relation,
&nextTuple.Subject.Namespace,
&nextTuple.Subject.ObjectId,
&nextTuple.Subject.Relation,
)
if err != nil {
return err
Expand Down
Loading

0 comments on commit c6f3b29

Please sign in to comment.