{"record":{"id":"136107a977c16b5a","repo":"cayleygraph/cayley","slug":"quad-update-failed-v","errorCode":null,"errorMessage":"quad update failed: %v","messagePattern":"quad update failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"graph/nosql/quadstore.go","lineNumber":284,"sourceCode":"func (qs *QuadStore) updateQuad(ctx context.Context, q quad.Quad, proc graph.Procedure) error {\n\tvar setname string\n\tif proc == graph.Add {\n\t\tsetname = fldQuadAdded\n\t} else if proc == graph.Delete {\n\t\tsetname = fldQuadDeleted\n\t}\n\tdoc := nosql.Document{\n\t\tfldSubject:   nosql.String(hashOf(q.Subject)),\n\t\tfldPredicate: nosql.String(hashOf(q.Predicate)),\n\t\tfldObject:    nosql.String(hashOf(q.Object)),\n\t}\n\tif l := hashOf(q.Label); l != \"\" {\n\t\tdoc[fldLabel] = nosql.String(l)\n\t}\n\terr := qs.db.Update(colQuads, getKeyForQuad(q)).Upsert(doc).\n\t\tInc(setname, 1).Do(ctx)\n\tif err != nil {\n\t\terr = fmt.Errorf(\"quad update failed: %v\", err)\n\t}\n\treturn err\n}\n\nfunc checkQuadValid(q nosql.Document) bool {\n\tadded, _ := asInt(q[fldQuadAdded])\n\tdeleted, _ := asInt(q[fldQuadDeleted])\n\treturn added > deleted\n}\n\nfunc (qs *QuadStore) checkValidQuad(ctx context.Context, key nosql.Key) (bool, error) {\n\tq, err := qs.db.FindByKey(ctx, colQuads, key)\n\tif err == nosql.ErrNotFound {\n\t\treturn false, nil\n\t}\n\tif err != nil {\n\t\terr = fmt.Errorf(\"error checking quad validity: %v\", err)\n\t\treturn false, err","sourceCodeStart":266,"sourceCodeEnd":302,"githubUrl":"https://github.com/cayleygraph/cayley/blob/81dcd7d73e45136bc0d01802a8ba4685d8a533eb/graph/nosql/quadstore.go#L266-L302","documentation":"Returned by QuadStore.updateQuad when the Update(colQuads, key).Upsert(doc).Inc(setname, 1).Do(ctx) call fails. Every applied delta increments (or decrements via setname choice) a counter on the quad document; this error means the backing store rejected or could not complete that write.","triggerScenarios":"ApplyDeltas hitting an unavailable/cancelled database, a quad key too large for the store, driver-level write errors (duplicate key, doc too big), or a read-only replica receiving the update.","commonSituations":"MongoDB primary stepdown mid-transaction; Bolt single-writer contention with concurrent Cayley instances; oversized quads (very long IRIs/values) exceeding the 16MB doc limit is rare but the inc path can still fail on connectivity.","solutions":["Examine the wrapped %v driver error and address it (connectivity, permissions, doc limits).","Verify database reachability and that the quads collection is writable by the configured credentials.","Retry ApplyDeltas — the update is an upsert with an increment, so retrying the same delta is idempotent per quad.","Split large delta batches into smaller ApplyDeltas calls to reduce per-transaction failure surface.","Check ctx deadlines; use a longer timeout for bulk load operations."],"exampleFix":"// before\nerr = fmt.Errorf(\"quad update failed: %v\", err)\n// after\nerr = fmt.Errorf(\"quad update failed: %w\", err)\n// caller: retry transient failures\nfor i := 0; i < 3; i++ {\n    if err := store.ApplyDeltas(ctx, deltas, true); err == nil { break }\n    time.Sleep(time.Duration(1<<i) * 100 * time.Millisecond)\n}","handlingStrategy":"try-catch","validationCode":"if err := ctx.Err(); err != nil { return err }\n// verify store is writable\nw := store.NewQuadWriter(ctx)\nif w == nil { return errors.New(\"writer unavailable\") }\nw.Close()","typeGuard":null,"tryCatchPattern":"if err := store.ApplyDeltas(ctx, deltas, true); err != nil {\n    if isRetryable(err) { // network/timeout causes in wrapped %v\n        return retryWithBackoff(func() error { return store.ApplyDeltas(ctx, deltas, true) })\n    }\n    return err\n}","preventionTips":["Retry upsert+inc deltas — they are idempotent per quad","Keep delta batches small to limit blast radius of a failed write","Ensure the quads collection is writable by configured credentials","Avoid concurrent single-writer backend instances","Set generous timeouts for bulk loads"],"tags":["database","nosql","write-failed","cayley"],"backgroundTag":"database-write-failed","analyzedSha":"81dcd7d73e45136bc0d01802a8ba4685d8a533eb","analyzedAt":"2026-09-06T06:14:12.358Z","contentChangedAt":"2026-09-06T06:14:12.358Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}