Bedrock.DataPlane.Resolver.Conflicts (bedrock v0.6.0)

View Source

Optimized conflict tracking that separates point writes from range operations.

Uses MapSets for O(1) point conflict detection and interval trees only for true range operations. Point writes are detected by the pattern where end_key == start_key <> <<0>>.

This provides significant performance improvements for import scenarios with many unique point writes.

Summary

Functions

Adds conflicts for a new version to the structure. If the version matches the most recent version, merges the conflicts instead of creating a new entry.

Checks if any of the given conflicts overlap with existing conflicts at versions greater than the specified version.

Returns metrics about the conflict structure for debugging.

Creates a new empty versioned conflicts structure with no floor: reads at any version check cleanly against the (complete, empty) history.

Creates a new empty versioned conflicts structure floored at oldest_version: history before it is unknown (not empty), so reads below it abort.

Removes conflicts older than the specified version and advances the floor to it (monotonically), so reads below the pruned horizon abort instead of checking against incomplete history.

Separates conflicts into point writes and true ranges based on key patterns. Point writes have end_key == start_key <> <<0>>.

Types

t()

@type t() :: %Bedrock.DataPlane.Resolver.Conflicts{
  oldest_version: Bedrock.version() | nil,
  versions: [
    {Bedrock.version(), MapSet.t(binary()),
     Bedrock.DataPlane.Resolver.Tree.t() | nil}
  ]
}

Functions

add_conflicts(conflicts, new_conflicts, version)

@spec add_conflicts(t(), [Bedrock.key_range()], Bedrock.version()) :: t()

Adds conflicts for a new version to the structure. If the version matches the most recent version, merges the conflicts instead of creating a new entry.

check_conflicts(conflicts, conflicts, version)

@spec check_conflicts(t(), [Bedrock.key_range()], Bedrock.version()) :: :ok | :abort

Checks if any of the given conflicts overlap with existing conflicts at versions greater than the specified version.

Aborts outright when the version is below oldest_version: entries in that range have been pruned, so absence of overlap proves nothing.

metrics(conflicts)

@spec metrics(t()) :: %{
  version_count: non_neg_integer(),
  total_points: non_neg_integer(),
  total_ranges: non_neg_integer()
}

Returns metrics about the conflict structure for debugging.

new()

@spec new() :: t()

Creates a new empty versioned conflicts structure with no floor: reads at any version check cleanly against the (complete, empty) history.

new(oldest_version)

@spec new(Bedrock.version()) :: t()

Creates a new empty versioned conflicts structure floored at oldest_version: history before it is unknown (not empty), so reads below it abort.

remove_old_conflicts(conflicts, min_version)

@spec remove_old_conflicts(t(), Bedrock.version()) :: t()

Removes conflicts older than the specified version and advances the floor to it (monotonically), so reads below the pruned horizon abort instead of checking against incomplete history.

separate_conflicts(conflicts)

@spec separate_conflicts([Bedrock.key_range()]) ::
  {MapSet.t(binary()), [Bedrock.key_range()]}

Separates conflicts into point writes and true ranges based on key patterns. Point writes have end_key == start_key <> <<0>>.