cayleygraph/cayley · error

error cleaning up nodes: %v

Error message

error cleaning up nodes: %v

What it means

Returned by QuadStore.cleanupNodes when the conditional Delete on the nodes collection fails. After applying deltas, nodes whose fldSize dropped to 0 are deleted via a field filter (Path fldSize == nosql.Int(0)); this error wraps the driver error from that Delete(...).Do(ctx) call.

Source

Thrown at graph/nosql/quadstore.go:261

	if inc == 0 {
		return nil
	}
	d := toDocumentValue(&qs.opt, name)
	err := qs.db.Update(colNodes, key).Upsert(d).Inc(fldSize, inc).Do(ctx)
	if err != nil {
		return fmt.Errorf("error updating node: %v", err)
	}
	return nil
}

func (qs *QuadStore) cleanupNodes(ctx context.Context, keys []nosql.Key) error {
	err := qs.db.Delete(colNodes).Keys(keys...).WithFields(nosql.FieldFilter{
		Path:   []string{fldSize},
		Filter: nosql.Equal,
		Value:  nosql.Int(0),
	}).Do(ctx)
	if err != nil {
		err = fmt.Errorf("error cleaning up nodes: %v", err)
	}
	return err
}

func (qs *QuadStore) updateQuad(ctx context.Context, q quad.Quad, proc graph.Procedure) error {
	var setname string
	if proc == graph.Add {
		setname = fldQuadAdded
	} else if proc == graph.Delete {
		setname = fldQuadDeleted
	}
	doc := nosql.Document{
		fldSubject:   nosql.String(hashOf(q.Subject)),
		fldPredicate: nosql.String(hashOf(q.Predicate)),
		fldObject:    nosql.String(hashOf(q.Object)),
	}
	if l := hashOf(q.Label); l != "" {
		doc[fldLabel] = nosql.String(l)

View on GitHub (pinned to 81dcd7d73e)

Solutions

  1. Read the wrapped driver error; fix database connectivity/permissions first.
  2. Ensure the DB user has delete privileges on the nodes collection.
  3. Confirm the chosen NoSQL backend supports filtered (WithFields/Equal) deletes; if not, switch backend or upgrade the driver integration.
  4. Increase the context timeout and retry the delta application.
  5. If deletes keep failing, nodes with size 0 are only cosmetic garbage — you can run the cleanup manually later, but fix the root cause.

Example fix

// before
if err != nil {
    err = fmt.Errorf("error cleaning up nodes: %v", err)
}
// after
if err != nil {
    return fmt.Errorf("error cleaning up nodes: %w", err) // inspect the cause
}
// caller side: use a longer-lived context for batch cleanup
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()
Defensive patterns

Strategy: try-catch

Validate before calling

// check DB privileges/connectivity before delta application
if err := dbPing(ctx, spec); err != nil {
    return fmt.Errorf(

When it happens

Trigger: Applying deltas that remove the last reference to a node while the NoSQL backend fails the filtered delete: connection loss, ctx cancellation, driver not supporting the Equal field filter, or a backend that rejects conditional deletes.

Common situations: NoSQL driver lacking field-filter delete support (some backends only support key deletes); network drop during ApplyDeltas cleanup phase; MongoDB authentication/authorization lacking delete permission on the collection.

Related errors


AI-assisted analysis of cayleygraph/cayley@81dcd7d73e (2026-09-06). Data as JSON: /api/errors/950226b1f233b4ee. Report an issue: GitHub.