@@ -1140,6 +1140,33 @@ public void testGlobalCheckpointSync() throws IOException {
11401140 closeShards (replicaShard , primaryShard );
11411141 }
11421142
1143+ public void testClosedIndicesSkipSyncGlobalCheckpoint () throws Exception {
1144+ ShardId shardId = new ShardId ("index" , "_na_" , 0 );
1145+ IndexMetaData .Builder indexMetadata = IndexMetaData .builder ("index" )
1146+ .settings (Settings .builder ().put (IndexMetaData .SETTING_VERSION_CREATED , Version .CURRENT )
1147+ .put (IndexMetaData .SETTING_NUMBER_OF_SHARDS , 1 ).put (IndexMetaData .SETTING_NUMBER_OF_REPLICAS , 2 ))
1148+ .state (IndexMetaData .State .CLOSE ).primaryTerm (0 , 1 );
1149+ ShardRouting shardRouting = TestShardRouting .newShardRouting (shardId , randomAlphaOfLength (8 ), true ,
1150+ ShardRoutingState .INITIALIZING , RecoverySource .EmptyStoreRecoverySource .INSTANCE );
1151+ AtomicBoolean synced = new AtomicBoolean ();
1152+ IndexShard primaryShard = newShard (shardRouting , indexMetadata .build (), null , new InternalEngineFactory (),
1153+ () -> synced .set (true ), RetentionLeaseSyncer .EMPTY );
1154+ recoverShardFromStore (primaryShard );
1155+ IndexShard replicaShard = newShard (shardId , false );
1156+ recoverReplica (replicaShard , primaryShard , true );
1157+ int numDocs = between (1 , 10 );
1158+ for (int i = 0 ; i < numDocs ; i ++) {
1159+ indexDoc (primaryShard , "_doc" , Integer .toString (i ));
1160+ }
1161+ assertThat (primaryShard .getLocalCheckpoint (), equalTo (numDocs - 1L ));
1162+ primaryShard .updateLocalCheckpointForShard (replicaShard .shardRouting .allocationId ().getId (), primaryShard .getLocalCheckpoint ());
1163+ long globalCheckpointOnReplica = randomLongBetween (SequenceNumbers .NO_OPS_PERFORMED , primaryShard .getLocalCheckpoint ());
1164+ primaryShard .updateGlobalCheckpointForShard (replicaShard .shardRouting .allocationId ().getId (), globalCheckpointOnReplica );
1165+ primaryShard .maybeSyncGlobalCheckpoint ("test" );
1166+ assertFalse ("closed indices should skip global checkpoint sync" , synced .get ());
1167+ closeShards (primaryShard , replicaShard );
1168+ }
1169+
11431170 public void testRestoreLocalHistoryFromTranslogOnPromotion () throws IOException , InterruptedException {
11441171 final IndexShard indexShard = newStartedShard (false );
11451172 final int operations = 1024 - scaledRandomIntBetween (0 , 1024 );
0 commit comments