Grove.GC behaviour (Grove v0.1.1)

View Source

Behaviour 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

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

crdt_state()

@type crdt_state() :: term()

gc_stats()

@type gc_stats() :: %{
  removed_entries: non_neg_integer(),
  remaining_entries: non_neg_integer()
}

opts()

@type opts() :: keyword()

Callbacks

collect(crdt_state, opts)

@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.

gc_info(crdt_state)

(optional)
@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.

needs_gc?(crdt_state, opts)

@callback needs_gc?(crdt_state(), opts()) :: boolean()

Checks if garbage collection is recommended.

Options:

  • :threshold - Minimum empty entries before GC is recommended (default: 0)