spicedb
spicedb copied to clipboard
Getting a duplicated transaction exists when trying to do a write request
What platforms are affected?
linux
What architectures are affected?
arm64
What SpiceDB version are you using?
V1.32.0
Steps to Reproduce
Not 100 certain how this happened, but I have a job that just ends up writing requests to backfill data into spice db and its responsible for migrating thousands of records 500 at at a time (individual writes)
Code that writes the relationship, it worked for thousands, but now get stuck every time on the next record
const request = v1.WriteRelationshipsRequest.create({
updates: [
{
operation: v1.RelationshipUpdate_Operation.CREATE,
relationship: {
resource: getObjectReference(organizationId, ResourceType.Organization),
relation: MobileUserTypeToPermissionSetMap[userType],
subject: getSubjectReference(userId, SubjectType.User),
},
},
],
})
return this.writeRelationship(request)
Expected Result
A relationship is written and can proceed to write futher relationships
Actual Result
{"level":"warn","protocol":"grpc","grpc.component":"server","grpc.service":"authzed.api.v1.PermissionsService","grpc.method":"WriteRelationships","grpc.method_type":"unary","requestID":"cqmiho24mabc73f9a96g","peer.address":"172.28.0.1:42310","grpc.start_time":"2024-08-02T18:43:44Z","grpc.code":"Aborted","grpc.error":"max retries exceeded: error when trying to create a new transaction: ERROR: duplicate key value violates unique constraint \"pk_rttx\" (SQLSTATE 23505)","grpc.time_ms":56895,"time":"2024-08-02T18:44:41Z","message":"finished call"}
That error indicates that you're likely overloading the Postgres instance; are you performing these writes concurrently? There is a limit after which Postgres won't allow further concurrent writes, especially large ones
It was loading one after another, not a lot at the same time. After this happened it kept happening on any subsequent write (on the first one) even after turning off and on the postgres instance, but there could have been some reads before the writes.
The odd thing is that I skipped a specific record and then it started to work again.
@nate-kis And does it still happen now? Is the relationship being written in the table already?
@nate-kis Anymore details?
No, I haven't been able to reproduce it since, I'll close for now unless I get it again