Repository navigation
Description
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 tograph_drops. It is O(1) and needs no scan cap. - Views as of
tor 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'strather than unconditional. Facts in novelty get real retractions attwhen 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 onnext.
- Policy: a
CLEARby a restricted identity is judged per flake, so it keeps today's per-fact path and its cap. The marker is for unrestricted identities, asDROPis. - 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
CLEARof a graph past the scan cap commits, leaves the graph empty at the head, and keeps it readable as of an earliert, both before and after an index build covers it. - A write after the clear, including the same fact again, is a fresh assertion.
COPY/MOVEdestinations and an empty Graph StorePUTtake the same path.
Activity