@@ -1907,6 +1907,86 @@ public void testSegmentReplicationCheckpointTracking() {
1907
1907
}
1908
1908
}
1909
1909
1910
+ public void testSegmentReplicationCheckpointForRelocatingPrimary () {
1911
+ Settings settings = Settings .builder ().put (SETTING_REPLICATION_TYPE , ReplicationType .SEGMENT ).build ();
1912
+ final long initialClusterStateVersion = randomNonNegativeLong ();
1913
+ final int numberOfActiveAllocationsIds = randomIntBetween (2 , 2 );
1914
+ final int numberOfInitializingIds = randomIntBetween (2 , 2 );
1915
+ final Tuple <Set <AllocationId >, Set <AllocationId >> activeAndInitializingAllocationIds = randomActiveAndInitializingAllocationIds (
1916
+ numberOfActiveAllocationsIds ,
1917
+ numberOfInitializingIds
1918
+ );
1919
+ final Set <AllocationId > activeAllocationIds = activeAndInitializingAllocationIds .v1 ();
1920
+ final Set <AllocationId > initializingIds = activeAndInitializingAllocationIds .v2 ();
1921
+
1922
+ AllocationId targetAllocationId = initializingIds .iterator ().next ();
1923
+ AllocationId primaryId = activeAllocationIds .iterator ().next ();
1924
+ String relocatingToNodeId = nodeIdFromAllocationId (targetAllocationId );
1925
+
1926
+ logger .info ("--> activeAllocationIds {} Primary {}" , activeAllocationIds , primaryId .getId ());
1927
+ logger .info ("--> initializingIds {} Target {}" , initializingIds , targetAllocationId );
1928
+
1929
+ final ShardId shardId = new ShardId ("test" , "_na_" , 0 );
1930
+ final IndexShardRoutingTable .Builder builder = new IndexShardRoutingTable .Builder (shardId );
1931
+ for (final AllocationId initializingId : initializingIds ) {
1932
+ boolean primaryRelocationTarget = initializingId .equals (targetAllocationId );
1933
+ builder .addShard (
1934
+ TestShardRouting .newShardRouting (
1935
+ shardId ,
1936
+ nodeIdFromAllocationId (initializingId ),
1937
+ null ,
1938
+ primaryRelocationTarget ,
1939
+ ShardRoutingState .INITIALIZING ,
1940
+ initializingId
1941
+ )
1942
+ );
1943
+ }
1944
+ builder .addShard (
1945
+ TestShardRouting .newShardRouting (
1946
+ shardId ,
1947
+ nodeIdFromAllocationId (primaryId ),
1948
+ relocatingToNodeId ,
1949
+ true ,
1950
+ ShardRoutingState .STARTED ,
1951
+ primaryId
1952
+ )
1953
+ );
1954
+ IndexShardRoutingTable routingTable = builder .build ();
1955
+ final ReplicationTracker tracker = newTracker (primaryId , settings );
1956
+ tracker .updateFromClusterManager (initialClusterStateVersion , ids (activeAllocationIds ), routingTable );
1957
+ tracker .activatePrimaryMode (NO_OPS_PERFORMED );
1958
+ assertThat (tracker .getReplicationGroup ().getInSyncAllocationIds (), equalTo (ids (activeAllocationIds )));
1959
+ assertThat (tracker .getReplicationGroup ().getRoutingTable (), equalTo (routingTable ));
1960
+ assertTrue (activeAllocationIds .stream ().allMatch (a -> tracker .getTrackedLocalCheckpointForShard (a .getId ()).inSync ));
1961
+ initializingIds .forEach (aId -> markAsTrackingAndInSyncQuietly (tracker , aId .getId (), NO_OPS_PERFORMED ));
1962
+
1963
+ final StoreFileMetadata segment_1 = new StoreFileMetadata ("segment_1" , 5L , "abcd" , Version .LATEST );
1964
+ final ReplicationCheckpoint initialCheckpoint = new ReplicationCheckpoint (
1965
+ tracker .shardId (),
1966
+ 0L ,
1967
+ 1 ,
1968
+ 1 ,
1969
+ 5L ,
1970
+ Codec .getDefault ().getName (),
1971
+ Map .of ("segment_1" , segment_1 )
1972
+ );
1973
+ tracker .setLatestReplicationCheckpoint (initialCheckpoint );
1974
+ tracker .startReplicationLagTimers (initialCheckpoint );
1975
+
1976
+ final Set <String > expectedIds = initializingIds .stream ()
1977
+ .filter (id -> id .equals (targetAllocationId ))
1978
+ .map (AllocationId ::getId )
1979
+ .collect (Collectors .toSet ());
1980
+
1981
+ Set <SegmentReplicationShardStats > groupStats = tracker .getSegmentReplicationStats ();
1982
+ assertEquals (expectedIds .size (), groupStats .size ());
1983
+ for (SegmentReplicationShardStats shardStat : groupStats ) {
1984
+ assertEquals (1 , shardStat .getCheckpointsBehindCount ());
1985
+ assertEquals (5L , shardStat .getBytesBehindCount ());
1986
+ assertTrue (shardStat .getCurrentReplicationLagMillis () >= shardStat .getCurrentReplicationTimeMillis ());
1987
+ }
1988
+ }
1989
+
1910
1990
public void testSegmentReplicationCheckpointTrackingInvalidAllocationIDs () {
1911
1991
Settings settings = Settings .builder ().put (SETTING_REPLICATION_TYPE , ReplicationType .SEGMENT ).build ();
1912
1992
final long initialClusterStateVersion = randomNonNegativeLong ();
0 commit comments