Skip to content

CLEAR at any graph size: record the clear in the commit instead of retracting each fact #2254

Open

Description

@bplatz

Problem

CLEAR retracts every current fact of the graph, one retraction flake per fact, in one commit. It goes through whole_graph_facts under FLUREE_MAX_GRAPH_SCAN_FLAKES (10M by default), so CLEAR of a larger graph fails with a resource-limit error. Raising or disabling the cap doesn't make it scale, because the cost grows with the graph in four places:

  • Staging memory: every fact is materialized, with two copies per fact.
  • Commit: the blob holds one retraction per fact, so it is large to write, replay, push and pull.
  • Novelty: it can roughly double in one commit, because backpressure is checked only at commit entry.
  • Index build: every leaf of the graph is rewritten, and every fact gains a history entry.

#1691 (streaming diff) bounds the memory only. Splitting the clear into several commits would make it non-atomic.

The same per-fact path also serves COPY / MOVE's destination clear and a Graph Store PUT with an empty body.

Proposal: CLEAR as a commit marker, reusing DROP's machinery

After a CLEAR and after a DROP, the graph's current state is the same: empty. The two differ only in what a view as of an earlier t sees: after a CLEAR, the old facts stay queryable. So a CLEAR can be recorded the way a drop is:

  • Commit: records "graph cleared at t", by IRI, next to graph_drops. It is O(1) and needs no scan cap.
  • Views as of t or later: reuse what a drop does. Hide the graph in the index (without_graphs), reset its statistics, rebuild search indexes over it, and have staging treat the graph's earlier facts as absent.
  • Views before t (the new part): the index mask becomes conditional on the view's t rather than unconditional. Facts in novelty get real retractions at t when the commit is applied, which is bounded by the novelty size limit.
  • Index build past the clear, in one of two ways:
    • (a) Per-fact retractions: the indexer writes the retractions into history. No index-format change, and memory stays bounded. The work and disk growth are still proportional to the graph, but it happens in the background.
    • (b) An archived generation: the root keeps the graph's pre-clear index as a generation valid for views before t, so the clear costs nothing at build time either. This is an index-format change, so it belongs on next.
  • Policy: a CLEAR by a restricted identity is judged per flake, so it keeps today's per-fact path and its cap. The marker is for unrestricted identities, as DROP is.
  • Branch operations, push and pull: these follow the drop rules, since a marker commit has the same shape.

Suggested order: the marker with (a) first, then (b) later if the background rewrite cost matters.

Tests

  • A CLEAR of a graph past the scan cap commits, leaves the graph empty at the head, and keeps it readable as of an earlier t, both before and after an index build covers it.
  • A write after the clear, including the same fact again, is a fresh assertion.
  • COPY / MOVE destinations and an empty Graph Store PUT take the same path.

Activity

  1. added
    enhancement
    P2
    area:transact
    performance
    on Nov 3, 2026
  2. added this to the 5.0.0 milestone on Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2area:transactenhancementperformance

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions