@@ -827,10 +827,7 @@ private boolean invariant() {
827
827
assert checkpoints .get (aId ) != null : "aId [" + aId + "] is pending in sync but isn't tracked" ;
828
828
}
829
829
830
- if (primaryMode
831
- && indexSettings .isSoftDeleteEnabled ()
832
- && indexSettings .getIndexMetaData ().getState () == IndexMetaData .State .OPEN
833
- && hasAllPeerRecoveryRetentionLeases ) {
830
+ if (primaryMode && indexSettings .isSoftDeleteEnabled () && hasAllPeerRecoveryRetentionLeases ) {
834
831
// all tracked shard copies have a corresponding peer-recovery retention lease
835
832
for (final ShardRouting shardRouting : routingTable .assignedShards ()) {
836
833
if (checkpoints .get (shardRouting .allocationId ().getId ()).tracked ) {
@@ -898,7 +895,9 @@ public ReplicationTracker(
898
895
this .pendingInSync = new HashSet <>();
899
896
this .routingTable = null ;
900
897
this .replicationGroup = null ;
901
- this .hasAllPeerRecoveryRetentionLeases = indexSettings .getIndexVersionCreated ().onOrAfter (Version .V_7_4_0 );
898
+ this .hasAllPeerRecoveryRetentionLeases = indexSettings .getIndexVersionCreated ().onOrAfter (Version .V_8_0_0 ) ||
899
+ (indexSettings .getIndexVersionCreated ().onOrAfter (Version .V_7_4_0 ) &&
900
+ indexSettings .getIndexMetaData ().getState () == IndexMetaData .State .OPEN );
902
901
this .fileBasedRecoveryThreshold = IndexSettings .FILE_BASED_RECOVERY_THRESHOLD_SETTING .get (indexSettings .getSettings ());
903
902
this .safeCommitInfoSupplier = safeCommitInfoSupplier ;
904
903
assert Version .V_EMPTY .equals (indexSettings .getIndexVersionCreated ()) == false ;
@@ -1011,34 +1010,32 @@ private void addPeerRecoveryRetentionLeaseForSolePrimary() {
1011
1010
assert primaryMode ;
1012
1011
assert Thread .holdsLock (this );
1013
1012
1014
- if (indexSettings ().getIndexMetaData ().getState () == IndexMetaData .State .OPEN ) {
1015
- final ShardRouting primaryShard = routingTable .primaryShard ();
1016
- final String leaseId = getPeerRecoveryRetentionLeaseId (primaryShard );
1017
- if (retentionLeases .get (leaseId ) == null ) {
1018
- if (replicationGroup .getReplicationTargets ().equals (Collections .singletonList (primaryShard ))) {
1019
- assert primaryShard .allocationId ().getId ().equals (shardAllocationId )
1020
- : routingTable .assignedShards () + " vs " + shardAllocationId ;
1021
- // Safe to call innerAddRetentionLease() without a subsequent sync since there are no other members of this replication
1022
- // group.
1023
- logger .trace ("addPeerRecoveryRetentionLeaseForSolePrimary: adding lease [{}]" , leaseId );
1024
- innerAddRetentionLease (leaseId , Math .max (0L , checkpoints .get (shardAllocationId ).globalCheckpoint + 1 ),
1025
- PEER_RECOVERY_RETENTION_LEASE_SOURCE );
1026
- hasAllPeerRecoveryRetentionLeases = true ;
1027
- } else {
1028
- /*
1029
- * We got here here via a rolling upgrade from an older version that doesn't create peer recovery retention
1030
- * leases for every shard copy, but in this case we do not expect any leases to exist.
1031
- */
1032
- assert hasAllPeerRecoveryRetentionLeases == false : routingTable + " vs " + retentionLeases ;
1033
- logger .debug ("{} becoming primary of {} with missing lease: {}" , primaryShard , routingTable , retentionLeases );
1034
- }
1035
- } else if (hasAllPeerRecoveryRetentionLeases == false && routingTable .assignedShards ().stream ().allMatch (shardRouting ->
1036
- retentionLeases .contains (getPeerRecoveryRetentionLeaseId (shardRouting ))
1037
- || checkpoints .get (shardRouting .allocationId ().getId ()).tracked == false )) {
1038
- // Although this index is old enough not to have all the expected peer recovery retention leases, in fact it does, so we
1039
- // don't need to do any more work.
1013
+ final ShardRouting primaryShard = routingTable .primaryShard ();
1014
+ final String leaseId = getPeerRecoveryRetentionLeaseId (primaryShard );
1015
+ if (retentionLeases .get (leaseId ) == null ) {
1016
+ if (replicationGroup .getReplicationTargets ().equals (Collections .singletonList (primaryShard ))) {
1017
+ assert primaryShard .allocationId ().getId ().equals (shardAllocationId )
1018
+ : routingTable .assignedShards () + " vs " + shardAllocationId ;
1019
+ // Safe to call innerAddRetentionLease() without a subsequent sync since there are no other members of this replication
1020
+ // group.
1021
+ logger .trace ("addPeerRecoveryRetentionLeaseForSolePrimary: adding lease [{}]" , leaseId );
1022
+ innerAddRetentionLease (leaseId , Math .max (0L , checkpoints .get (shardAllocationId ).globalCheckpoint + 1 ),
1023
+ PEER_RECOVERY_RETENTION_LEASE_SOURCE );
1040
1024
hasAllPeerRecoveryRetentionLeases = true ;
1025
+ } else {
1026
+ /*
1027
+ * We got here here via a rolling upgrade from an older version that doesn't create peer recovery retention
1028
+ * leases for every shard copy, but in this case we do not expect any leases to exist.
1029
+ */
1030
+ assert hasAllPeerRecoveryRetentionLeases == false : routingTable + " vs " + retentionLeases ;
1031
+ logger .debug ("{} becoming primary of {} with missing lease: {}" , primaryShard , routingTable , retentionLeases );
1041
1032
}
1033
+ } else if (hasAllPeerRecoveryRetentionLeases == false && routingTable .assignedShards ().stream ().allMatch (shardRouting ->
1034
+ retentionLeases .contains (getPeerRecoveryRetentionLeaseId (shardRouting ))
1035
+ || checkpoints .get (shardRouting .allocationId ().getId ()).tracked == false )) {
1036
+ // Although this index is old enough not to have all the expected peer recovery retention leases, in fact it does, so we
1037
+ // don't need to do any more work.
1038
+ hasAllPeerRecoveryRetentionLeases = true ;
1042
1039
}
1043
1040
}
1044
1041
@@ -1356,10 +1353,7 @@ private synchronized void setHasAllPeerRecoveryRetentionLeases() {
1356
1353
* prior to {@link Version#V_7_4_0} that does not create peer-recovery retention leases.
1357
1354
*/
1358
1355
public synchronized void createMissingPeerRecoveryRetentionLeases (ActionListener <Void > listener ) {
1359
- if (indexSettings ().isSoftDeleteEnabled ()
1360
- && indexSettings ().getIndexMetaData ().getState () == IndexMetaData .State .OPEN
1361
- && hasAllPeerRecoveryRetentionLeases == false ) {
1362
-
1356
+ if (indexSettings ().isSoftDeleteEnabled () && hasAllPeerRecoveryRetentionLeases == false ) {
1363
1357
final List <ShardRouting > shardRoutings = routingTable .assignedShards ();
1364
1358
final GroupedActionListener <ReplicationResponse > groupedActionListener = new GroupedActionListener <>(ActionListener .wrap (vs -> {
1365
1359
setHasAllPeerRecoveryRetentionLeases ();
0 commit comments