Skip to content

Conversation

@atakavci
Copy link
Collaborator

Introduce new channel handler and extract command tracking logic and add Netty pipeline handler

Summary

This PR refactors the failover module to separate command tracking concerns and introduces a Netty pipeline handler for comprehensive command result tracking.

Changes

1. New DatabaseCommandTracker class

  • Extracts command tracking logic from DatabaseEndpointImpl and DatabasePubSubEndpointImpl
  • Implements CommandWriter interface for delegation pattern
  • Manages circuit breaker binding and channel lifecycle
  • Tracks timeout exceptions via onComplete() callbacks
  • Records exceptions thrown during write operations
  • Handles both single and batch command writes

2. New MultiDbOutboundAdapter Netty handler

  • Intercepts write operations in the Netty pipeline
  • Tracks non-timeout exceptions and successes via command completion callbacks
  • Complements DatabaseCommandTracker for comprehensive result tracking
  • Registered after CommandHandler in the pipeline

3. Refactored DatabaseEndpointImpl and DatabasePubSubEndpointImpl

  • Simplified by delegating to DatabaseCommandTracker
  • Implements CommandWriter interface
  • Manages channel lifecycle (notifyChannelActive/notifyChannelInactive)
  • Reduced code duplication (~60 lines removed from each class)

Architecture

The new architecture splits command result tracking into two layers:

  1. DatabaseCommandTracker (callback-based):

    • Tracks timeout exceptions via onComplete() callbacks
    • Records exceptions thrown during write operations
    • Manages circuit breaker state checks
  2. MultiDbOutboundAdapter (pipeline-based):

    • Tracks write failures in the Netty pipeline
    • Tracks non-timeout exceptions and successes via command completion
    • Provides comprehensive coverage of all command results

Tests

  • New: DatabaseCommandTrackerUnitTests (527 lines) - comprehensive unit tests
  • New: MultiDbOutboundAdapterUnitTests (309 lines) - unit tests for pipeline handler
  • New: DatabasePubSubEndpointTrackerTests (310 lines) - PubSub-specific tests
  • Updated: DatabaseEndpointCallbackTests - refactored to focus on integration behavior and avoid duplication

All tests passing: 44 unit tests covering the new architecture

Benefits

  • ✅ Separation of concerns (tracking logic extracted from endpoints)
  • ✅ Reduced code duplication
  • ✅ Comprehensive command result tracking (both callback and pipeline-based)
  • ✅ Better testability with focused unit tests
  • ✅ Maintains backward compatibility

@atakavci atakavci requested review from ggivo and tishun December 16, 2025 13:18
@atakavci atakavci self-assigned this Dec 16, 2025
@atakavci atakavci added the type: feature A new feature label Dec 16, 2025
@atakavci atakavci changed the title [automatic failover] Record failures for each attempt of write on channel(DefaultEndpint) including retries [automatic failover] Record failures for each attempt of write on channel including retries Dec 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: feature A new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant