WriteRelationship status to know what to do on rol...
# spicedb
j
if the write call completes, then its safe to mimick on the other data source; it'll be guaranteed for the relationship to exist/not exist depending on the semantics
b
Yes, the use case here is as follows: - I already have a relation
group:A member user:B
- I start a transaction in my client, make a call to SpiceDB to
TOUCH group:A member user:B
and write some data to my database as well - Something happens in my client, I need to rollback the transaction - In this case calling
DELETE group:A member user:B
would actually leave SpiceDB in a different state to what it was before, because the relationship already existed, therefore the cleanup I do in my rollback handler should be a no-op instead of calling SpiceDB to delete
j
if you already have the relationship, why are you calling TOUCH?
presumably you're not going to be adding it in the other datastore
b
It's a case where I might be receiving an incoming request, I want to dual write to SpiceDB and my own DB, I write to SpiceDB first to have the ZedToken, only then I try to write to my own DB and might realise that data already exists
j
this is what preconditions are designed to handle
you'd set the precondition to say "fail this transaction if the relationship already exists" (or doesn't, in the case of a DELETE)
then you'd get back a signal that the change doens't need to be applied at all
b
How would that work in a case where my input to
WriteRelationships
might include 5 updates for example, and one of the relationships might already exist but the other 4 still need to be written to SpiceDB?
j
right now it would cancel the entire transaction
but it would indicate which preconditions failed
b
I see, so I could then correlate which precondition failed with which relationship I was trying to write (if let's say I add one precondition per relationship) and retry the call without that one as I'd know it would be a no-op?
j
Pretty much
It should return which precondition failed in the error response
In full detail
b
If multiple preconditions aren't satisfied, do I get the full list of the failed ones, or does it stop after the first failed one?
j
We could look into adding info on which touch or deletes impacted but it would slow down writes
It stops after the first
So if we did add that it would have to be optional
b
Yeah it might be good to have an optional way of specifying that you'd like info back in the
WriteRelationshipsResponse
j
File an issue and we’ll look into it; there will be a performance penalty in certain data stores though
b
130 Views