Skip to content

Commit

Permalink
enforce check for fake_allocation: for existing store it could be onl…
Browse files Browse the repository at this point in the history
…y FORCE_STALE_PRIMARY_INSTANCE
  • Loading branch information
Vladimir Dolzhenko committed Oct 3, 2018
1 parent d3df30c commit fbdf6d7
Showing 1 changed file with 3 additions and 2 deletions.
Expand Up @@ -71,7 +71,7 @@ public void shardStarted(ShardRouting initializingShard, ShardRouting startedSha
addAllocationId(startedShard);
if (startedShard.primary()
// started shard has to have null recoverySource; have to pick up recoverySource from its initializing state
&& (initializingShard.recoverySource() instanceof RecoverySource.ExistingStoreRecoverySource
&& (initializingShard.recoverySource() == RecoverySource.ExistingStoreRecoverySource.FORCE_STALE_PRIMARY_INSTANCE
|| initializingShard.recoverySource() instanceof RecoverySource.SnapshotRecoverySource)) {
Updates updates = changes(startedShard.shardId());
updates.removedAllocationIds.add(RecoverySource.ExistingStoreRecoverySource.FORCED_ALLOCATION_ID);
Expand Down Expand Up @@ -147,6 +147,7 @@ private IndexMetaData.Builder updateInSyncAllocations(RoutingTable newRoutingTab
Set<String> oldInSyncAllocationIds = oldIndexMetaData.inSyncAllocationIds(shardId.id());

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

0 comments on commit fbdf6d7

Please sign in to comment.