Class PartitionMigrationPipeline

java.lang.Object
com.loomcache.server.cluster.PartitionMigrationPipeline

public class PartitionMigrationPipeline extends Object
Partition migration pipeline for data redistribution during cluster topology changes.

Performs real data movement through five stages:

  • PREPARE: Lock the partition, mark it as migrating, capture source data snapshot
  • COPY: Copy all entries belonging to this partition from source maps to target buffer
  • VERIFY: Compare CRC32 checksums and entry counts between source snapshot and copied data
  • COMMIT: Update partition ownership in the PartitionTable
  • CLEANUP: Remove migrated entries from the source node's maps

Thread safety: Uses ReentrantLock for pipeline coordination, per-partition locks for migration isolation, and ConcurrentHashMap for concurrent progress tracking.

Since:
1.0
  • Field Details

  • Constructor Details

  • Method Details

    • maxConcurrentMigrations

      public int maxConcurrentMigrations()
    • enqueueMigration

      public PartitionMigrationPipeline.MigrationTask enqueueMigration(int partitionId, String sourceNode, String targetNode, long dataSize)
      Enqueue a migration task to be processed by the pipeline.
      Parameters:
      partitionId - partition identifier (slot ID)
      sourceNode - source node ID
      targetNode - target node ID
      dataSize - estimated size in bytes
      Returns:
      the created migration task
    • processMigrations

      public void processMigrations()
      Execute migrations from the queue up to the concurrency limit. Should be called regularly or triggered by a scheduler.
    • processMigrationsSync

      public void processMigrationsSync()
      Execute migrations synchronously (for testing). Processes all queued tasks in the calling thread.
    • cleanupCommittedMigration

      public void cleanupCommittedMigration(int partitionId)
      Clean up source data for a migration that has already been staged and whose ownership cutover has been installed by the migration manager.
    • rollbackStagedMigration

      public void rollbackStagedMigration(int partitionId)
      Roll back a staged migration whose batch cutover failed before ownership was safely installed. Source data is preserved; copied target data is removed if it still matches the staged snapshot.
    • isPartitionMigrating

      public boolean isPartitionMigrating(int partitionId)
      Check if a partition is currently being migrated.
      Parameters:
      partitionId - partition to check
      Returns:
      true if the partition is locked for migration
    • cancelMigration

      public boolean cancelMigration(int partitionId)
      Cancel an in-flight migration.
      Parameters:
      partitionId - partition to cancel
      Returns:
      true if cancellation was successful
    • getStats

      Get current statistics.
      Returns:
      migration statistics
    • getProgress

      public @Nullable PartitionMigrationPipeline.MigrationProgress getProgress(int partitionId)
      Get progress for a specific migration.
      Parameters:
      partitionId - partition identifier
      Returns:
      migration progress, or null if not found
    • getActiveMigrations

      public Set<Integer> getActiveMigrations()
      Get all active migrations.
      Returns:
      set of active partition IDs
    • getPendingCount

      public int getPendingCount()
      Get count of pending tasks in queue.
      Returns:
      number of pending migrations
    • getTask

      public @Nullable PartitionMigrationPipeline.MigrationTask getTask(int partitionId)
      Get the state of a specific migration task.
      Parameters:
      partitionId - partition identifier
      Returns:
      the current task, or null if no active migration for this partition