Skip to content

Refactor V3MutationService and V3CompatibleTableBinding to eliminate duplicate code #195

@em3s

Description

@em3s

Background

V3MutationService.kt and V3CompatibleTableBinding.kt contain 95%+ identical code between mutateEdge and mutateMultiEdge methods. This duplication has already caused a bug: mutateMultiEdge is missing LockAcquisitionFailedException error handling that mutateEdge has — errors propagate and fail the entire request instead of returning ERROR status and clearing stale locks.

Task

  • V3CompatibleTableBinding: Extract buildHBaseMutations() private helper (100% identical HBase mutation construction: Put, Increment, Delete)
  • V3CompatibleTableBinding: Extract decodeCurrentState() private helper (identical state decoding logic)
  • V3MutationService: Extract resolveMutationContext() helper (label validation + context initialization)
  • V3MutationService: Extract writeCdc() helper (CDC message creation + publish)
  • V3MutationService: Extract handleMutationError() helper and apply to both methods
  • Bug fix: Add onErrorResume for LockAcquisitionFailedException to mutateMultiEdge

Done When

  • All existing tests pass (./gradlew :engine:test, ./gradlew :server:test)
  • No changes to public API signatures (controller compatibility preserved)
  • No changes to core module types
  • mutateMultiEdge handles LockAcquisitionFailedException identically to mutateEdge

Notes

  • Minimal extraction approach — small helper functions, no heavyweight generics or sealed interfaces
  • Expected reduction: V3CompatibleTableBinding ~65 lines, V3MutationService ~50 lines
  • Key difference between Edge/MultiEdge: Pair<Any, Any> (source, target) vs single Any (id) key

Created by claude code (opus 4.6)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions