Skip to content

Group S2S batch-sync mappings by EC ID before KV updates #882

Description

@ChristianPavilonis

Summary

Reduce S2S batch-sync KV operations by grouping validated mappings by normalized EC ID before updating the identity graph.

The endpoint accepts up to 1,000 mappings. Each valid mapping currently performs its own read-modify-write, so repeated mappings for one EC can produce repeated KV reads, writes, and CAS contention. In the worst changed-value case, one request performs roughly 2,000 KV operations before retries.

Proposed direction

Validate mappings individually, group valid mappings by normalized EC ID, and apply the final partner UID for each distinct EC with one CAS-protected read-modify-write. Preserve per-input response accounting and deterministic last-write-wins behavior.

Acceptance criteria

  • KV read-modify-write count is bounded by the number of distinct valid EC IDs rather than mapping count.
  • Validation errors remain associated with their original input indexes.
  • For multiple valid mappings targeting the same EC and partner, the last valid mapping in request order is the persisted value.
  • Missing and withdrawn entries reject every affected mapping consistently.
  • Accepted/rejected counts and HTTP status behavior remain compatible with the current endpoint contract.
  • Infrastructure-failure and abort semantics are explicitly documented and tested after grouping.
  • Tests cover duplicate EC IDs, conflicting UIDs, mixed valid/invalid mappings, tombstones, missing entries, and CAS conflicts.

Relevant code

  • crates/trusted-server-core/src/ec/batch_sync.rs
  • crates/trusted-server-core/src/ec/kv.rs

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions