spicedb icon indicating copy to clipboard operation
spicedb copied to clipboard

Optionally return status on WriteRelationships

Open benvernier-sc opened this issue 9 months ago • 1 comments

This PR is part of a proof of concept for https://github.com/authzed/spicedb/issues/1903.

It temporarily uses a replace statement in go.mod to use the files generated in https://github.com/benvernier-sc/authzed-go/tree/write_relationships_status from https://github.com/authzed/api/pull/106.

It defines a new core protobuf message RelationTupleUpdateStatus that corresponds to the RelationshipUpdateStatus from the API protobuf.

It then updates the signature of ReadWriteTransaction.WriteRelationships from

type ReadWriteTransaction interface {
    // [...]
    WriteRelationships(ctx context.Context, mutations []*core.RelationTupleUpdate) error
    // [...]
}

to

type ReadWriteTransaction interface {
    // [...]
    WriteRelationships(ctx context.Context, mutations []*core.RelationTupleUpdate, returnStatus bool) ([]*core.RelationTupleUpdateStatus, error)
    // [...]
}

This allows to specify whether the store should return the status of the operations or not, and adds a return field with said statuses that are only guaranteed to be populated if returnStatus was true.

All the usages of WriteRelationships store method were updated to ensure the code would still compile. The WriteRelationships gRPC handler was updated to actually pass the WithStatus option from the request and use the returned statuses.

So far only the Postgres implementation has been updated to honor the new options. All scenarios have been tested locally, but no automated tests have been written so far.

benvernier-sc avatar May 21 '24 04:05 benvernier-sc