{"record":{"id":"3a7ab4fa34796c54","repo":"cayleygraph/cayley","slug":"error-updating-node-v","errorCode":null,"errorMessage":"error updating node: %v","messagePattern":"error updating node: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"graph/nosql/quadstore.go","lineNumber":249,"sourceCode":"\t\treturn \"\"\n\t}\n\th := quad.HashOf(s)\n\treturn base64.StdEncoding.EncodeToString(h)\n}\n\nfunc (qs *QuadStore) nameToKey(name quad.Value) nosql.Key {\n\tnode := qs.hashOf(name)\n\treturn node.key()\n}\n\nfunc (qs *QuadStore) updateNodeBy(ctx context.Context, key nosql.Key, name quad.Value, inc int) error {\n\tif inc == 0 {\n\t\treturn nil\n\t}\n\td := toDocumentValue(&qs.opt, name)\n\terr := qs.db.Update(colNodes, key).Upsert(d).Inc(fldSize, inc).Do(ctx)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error updating node: %v\", err)\n\t}\n\treturn nil\n}\n\nfunc (qs *QuadStore) cleanupNodes(ctx context.Context, keys []nosql.Key) error {\n\terr := qs.db.Delete(colNodes).Keys(keys...).WithFields(nosql.FieldFilter{\n\t\tPath:   []string{fldSize},\n\t\tFilter: nosql.Equal,\n\t\tValue:  nosql.Int(0),\n\t}).Do(ctx)\n\tif err != nil {\n\t\terr = fmt.Errorf(\"error cleaning up nodes: %v\", err)\n\t}\n\treturn err\n}\n\nfunc (qs *QuadStore) updateQuad(ctx context.Context, q quad.Quad, proc graph.Procedure) error {\n\tvar setname string","sourceCodeStart":231,"sourceCodeEnd":267,"githubUrl":"https://github.com/cayleygraph/cayley/blob/81dcd7d73e45136bc0d01802a8ba4685d8a533eb/graph/nosql/quadstore.go#L231-L267","documentation":"This error is returned by QuadStore.updateNodeBy when the underlying NoSQL document store (qs.db) fails to run an Update/Upsert/Inc operation on the nodes collection while applying a delta. It wraps the driver-level error from the Update(...).Do(ctx) call. The node's fldSize counter could not be incremented (or the node upserted), so the ApplyDeltas transaction for this node fails.","triggerScenarios":"Calling ApplyDeltas with a delta on a node when the backing NoSQL database (e.g. MongoDB, Bolt) is unavailable, the ctx is cancelled/timed out, the key/collection is corrupted or locked, or the driver rejects the update (e.g. document too large, connection dropped mid-write).","commonSituations":"MongoDB connection pool exhaustion or replica stepdown during bulk quad writes; context deadline exceeded during large ApplyDeltas batches; misconfigured NoSQL URI so the store is unreachable; concurrent writers hitting a locked Bolt/single-writer database.","solutions":["Inspect the wrapped %v cause (the driver error) — fix the underlying database connectivity or error first.","Verify the NoSQL connection URI/config in the Cayley spec file and test connectivity with a simple read before writing.","Retry ApplyDeltas; nosql updates are per-key upserts so re-applying the same delta batch after failure is generally safe for idempotent deltas.","Check ctx cancellation/timeouts — increase timeout or split the delta batch into smaller ApplyDeltas calls.","Upgrade/verify the specific NoSQL driver version matches what your Cayley build expects."],"exampleFix":"// before\nerr := qs.db.Update(colNodes, key).Upsert(d).Inc(fldSize, inc).Do(ctx)\n// after\nctx, cancel := context.WithTimeout(ctx, 30*time.Second)\ndefer cancel()\nif err := qs.db.Update(colNodes, key).Upsert(d).Inc(fldSize, inc).Do(ctx); err != nil {\n    return fmt.Errorf(\"error updating node: %w\", err)\n}","handlingStrategy":"try-catch","validationCode":"// before ApplyDeltas, ping the store\nif _, err := store.Quads(ctx); err != nil {\n    return fmt.Errorf(\"store unreachable, skipping ApplyDeltas: %w\", err)\n}\nif err := ctx.Err(); err != nil {\n    return err\n}","typeGuard":null,"tryCatchPattern":"if err := store.ApplyDeltas(ctx, deltas, true); err != nil {\n    var wrapped interface{ Unwrap() error }\n    if errors.As(err, &wrapped) {\n        log.Printf(\"node update failed, cause: %v\", errors.Unwrap(err))\n    }\n    // retry idempotent delta batch with backoff\n}","preventionTips":["Ensure the NoSQL backend is reachable and writable before bulk writes","Use adequate context timeouts for large delta batches","Apply deltas in reasonably sized batches so failures are cheap to retry","Monitor driver-level connection health (MongoDB ping, etc.)","Run a single writer against single-writer backends like Bolt"],"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"}