Grove.GC behaviour (Grove v0.1.1)
View SourceBehaviour for garbage collection strategies.
CRDTs can accumulate metadata over time (empty tag sets, orphaned entries). GC strategies clean up this metadata to prevent unbounded growth.
Strategies
Grove.GC.Structural- Remove structurally dead entries (safe, no coordination)
Usage
# Check if GC is needed
if Grove.GC.Structural.needs_gc?(set, threshold: 100) do
{:ok, cleaned, stats} = Grove.GC.Structural.collect(set)
end
# Get GC metadata
info = Grove.GC.Structural.gc_info(set)
# => %{empty_entries: 5, entry_count: 100, total_tags: 250}
Summary
Callbacks
Performs garbage collection on a CRDT state.
Returns metadata about the CRDT's garbage collection state.
Checks if garbage collection is recommended.
Types
@type crdt_state() :: term()
@type gc_stats() :: %{ removed_entries: non_neg_integer(), remaining_entries: non_neg_integer() }
@type opts() :: keyword()
Callbacks
@callback collect(crdt_state(), opts()) :: {:ok, crdt_state(), gc_stats()} | {:error, term()}
Performs garbage collection on a CRDT state.
Returns the cleaned state and statistics about what was removed.
@callback gc_info(crdt_state()) :: map()
Returns metadata about the CRDT's garbage collection state.
This includes counts of empty entries, total tags, memory estimates, etc.
@callback needs_gc?(crdt_state(), opts()) :: boolean()
Checks if garbage collection is recommended.
Options:
:threshold- Minimum empty entries before GC is recommended (default: 0)