Skip to content

Commit fbdf6d7

Browse files
author
Vladimir Dolzhenko
committed
enforce check for fake_allocation: for existing store it could be only FORCE_STALE_PRIMARY_INSTANCE
1 parent d3df30c commit fbdf6d7

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

server/src/main/java/org/elasticsearch/cluster/routing/allocation/IndexMetaDataUpdater.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public void shardStarted(ShardRouting initializingShard, ShardRouting startedSha
7171
addAllocationId(startedShard);
7272
if (startedShard.primary()
7373
// started shard has to have null recoverySource; have to pick up recoverySource from its initializing state
74-
&& (initializingShard.recoverySource() instanceof RecoverySource.ExistingStoreRecoverySource
74+
&& (initializingShard.recoverySource() == RecoverySource.ExistingStoreRecoverySource.FORCE_STALE_PRIMARY_INSTANCE
7575
|| initializingShard.recoverySource() instanceof RecoverySource.SnapshotRecoverySource)) {
7676
Updates updates = changes(startedShard.shardId());
7777
updates.removedAllocationIds.add(RecoverySource.ExistingStoreRecoverySource.FORCED_ALLOCATION_ID);
@@ -147,6 +147,7 @@ private IndexMetaData.Builder updateInSyncAllocations(RoutingTable newRoutingTab
147147
Set<String> oldInSyncAllocationIds = oldIndexMetaData.inSyncAllocationIds(shardId.id());
148148

149149
// check if we have been force-initializing an empty primary or a stale primary
150+
// the same is applicable for snapshot/restore as it can be considered as allocating a stale primary.
150151
if (updates.initializedPrimary != null && oldInSyncAllocationIds.isEmpty() == false &&
151152
oldInSyncAllocationIds.contains(updates.initializedPrimary.allocationId().getId()) == false) {
152153
// we're not reusing an existing in-sync allocation id to initialize a primary, which means that we're either force-allocating
@@ -164,7 +165,7 @@ private IndexMetaData.Builder updateInSyncAllocations(RoutingTable newRoutingTab
164165
// forcing an empty primary resets the in-sync allocations to the empty set (ShardRouting.allocatedPostIndexCreate)
165166
indexMetaDataBuilder.putInSyncAllocationIds(shardId.id(), Collections.emptySet());
166167
} else {
167-
assert recoverySource instanceof RecoverySource.ExistingStoreRecoverySource
168+
assert recoverySource == RecoverySource.ExistingStoreRecoverySource.FORCE_STALE_PRIMARY_INSTANCE
168169
|| recoverySource instanceof RecoverySource.SnapshotRecoverySource
169170
: recoverySource;
170171
// forcing a stale primary resets the in-sync allocations to the singleton set with the stale id

0 commit comments

Comments
 (0)