/** * Increase primary term for this shard id */ private void increasePrimaryTerm(ShardId shardId) { changes(shardId).increaseTerm = true; }
/** * Remove allocation id of this shard from the set of in-sync shard copies */ void removeAllocationId(ShardRouting shardRouting) { if (shardRouting.active()) { changes(shardRouting.shardId()).removedAllocationIds.add(shardRouting.allocationId().getId()); } }
@Override public void shardFailed(ShardRouting failedShard, UnassignedInfo unassignedInfo) { if (failedShard.active() && failedShard.primary()) { Updates updates = changes(failedShard.shardId()); if (updates.firstFailedPrimary == null) { // more than one primary can be failed (because of batching, primary can be failed, replica promoted and then failed...) updates.firstFailedPrimary = failedShard; } increasePrimaryTerm(failedShard.shardId()); } }
@Override public void shardInitialized(ShardRouting unassignedShard, ShardRouting initializedShard) { assert initializedShard.isRelocationTarget() == false : "shardInitialized is not called on relocation target: " + initializedShard; if (initializedShard.primary()) { increasePrimaryTerm(initializedShard.shardId()); Updates updates = changes(initializedShard.shardId()); assert updates.initializedPrimary == null : "Primary cannot be initialized more than once in same allocation round: " + "(previous: " + updates.initializedPrimary + ", next: " + initializedShard + ")"; updates.initializedPrimary = initializedShard; } }
@Override public void shardStarted(ShardRouting initializingShard, ShardRouting startedShard) { assert Objects.equals(initializingShard.allocationId().getId(), startedShard.allocationId().getId()) : "initializingShard.allocationId [" + initializingShard.allocationId().getId() + "] and startedShard.allocationId [" + startedShard.allocationId().getId() + "] have to have the same"; Updates updates = changes(startedShard.shardId()); updates.addedAllocationIds.add(startedShard.allocationId().getId()); if (startedShard.primary() // started shard has to have null recoverySource; have to pick up recoverySource from its initializing state && (initializingShard.recoverySource() == RecoverySource.ExistingStoreRecoverySource.FORCE_STALE_PRIMARY_INSTANCE)) { updates.removedAllocationIds.add(RecoverySource.ExistingStoreRecoverySource.FORCED_ALLOCATION_ID); } }
/** * Increase primary term for this shard id */ private void increasePrimaryTerm(ShardId shardId) { changes(shardId).increaseTerm = true; }
/** * Increase primary term for this shard id */ private void increasePrimaryTerm(ShardId shardId) { changes(shardId).increaseTerm = true; }
/** * Increase primary term for this shard id */ private void increasePrimaryTerm(ShardId shardId) { changes(shardId).increaseTerm = true; }
/** * Add allocation id of this shard to the set of in-sync shard copies */ private void addAllocationId(ShardRouting shardRouting) { changes(shardRouting.shardId()).addedAllocationIds.add(shardRouting.allocationId().getId()); }
/** * Remove allocation id of this shard from the set of in-sync shard copies */ private void removeAllocationId(ShardRouting shardRouting) { changes(shardRouting.shardId()).removedAllocationIds.add(shardRouting.allocationId().getId()); }
/** * Add allocation id of this shard to the set of in-sync shard copies */ private void addAllocationId(ShardRouting shardRouting) { changes(shardRouting.shardId()).addedAllocationIds.add(shardRouting.allocationId().getId()); }
/** * Add allocation id of this shard to the set of in-sync shard copies */ private void addAllocationId(ShardRouting shardRouting) { changes(shardRouting.shardId()).addedAllocationIds.add(shardRouting.allocationId().getId()); }
/** * Remove allocation id of this shard from the set of in-sync shard copies */ void removeAllocationId(ShardRouting shardRouting) { if (shardRouting.active()) { changes(shardRouting.shardId()).removedAllocationIds.add(shardRouting.allocationId().getId()); } }
/** * Remove allocation id of this shard from the set of in-sync shard copies */ void removeAllocationId(ShardRouting shardRouting) { if (shardRouting.active()) { changes(shardRouting.shardId()).removedAllocationIds.add(shardRouting.allocationId().getId()); } }
@Override public void shardFailed(ShardRouting failedShard, UnassignedInfo unassignedInfo) { if (failedShard.active() && failedShard.primary()) { Updates updates = changes(failedShard.shardId()); if (updates.firstFailedPrimary == null) { // more than one primary can be failed (because of batching, primary can be failed, replica promoted and then failed...) updates.firstFailedPrimary = failedShard; } increasePrimaryTerm(failedShard.shardId()); } }
@Override public void shardInitialized(ShardRouting unassignedShard, ShardRouting initializedShard) { assert initializedShard.isRelocationTarget() == false : "shardInitialized is not called on relocation target: " + initializedShard; if (initializedShard.primary()) { increasePrimaryTerm(initializedShard.shardId()); Updates updates = changes(initializedShard.shardId()); assert updates.initializedPrimary == null : "Primary cannot be initialized more than once in same allocation round: " + "(previous: " + updates.initializedPrimary + ", next: " + initializedShard + ")"; updates.initializedPrimary = initializedShard; } }
@Override public void shardInitialized(ShardRouting unassignedShard, ShardRouting initializedShard) { assert initializedShard.isRelocationTarget() == false : "shardInitialized is not called on relocation target: " + initializedShard; if (initializedShard.primary()) { increasePrimaryTerm(initializedShard.shardId()); Updates updates = changes(initializedShard.shardId()); assert updates.initializedPrimary == null : "Primary cannot be initialized more than once in same allocation round: " + "(previous: " + updates.initializedPrimary + ", next: " + initializedShard + ")"; updates.initializedPrimary = initializedShard; } }
@Override public void shardInitialized(ShardRouting unassignedShard, ShardRouting initializedShard) { assert initializedShard.isRelocationTarget() == false : "shardInitialized is not called on relocation target: " + initializedShard; if (initializedShard.primary()) { increasePrimaryTerm(initializedShard.shardId()); Updates updates = changes(initializedShard.shardId()); assert updates.initializedPrimary == null : "Primary cannot be initialized more than once in same allocation round: " + "(previous: " + updates.initializedPrimary + ", next: " + initializedShard + ")"; updates.initializedPrimary = initializedShard; } }
@Override public void shardFailed(ShardRouting failedShard, UnassignedInfo unassignedInfo) { if (failedShard.active() && failedShard.primary()) { Updates updates = changes(failedShard.shardId()); if (updates.firstFailedPrimary == null) { // more than one primary can be failed (because of batching, primary can be failed, replica promoted and then failed...) updates.firstFailedPrimary = failedShard; } increasePrimaryTerm(failedShard.shardId()); } }
@Override public void shardFailed(ShardRouting failedShard, UnassignedInfo unassignedInfo) { if (failedShard.active() && unassignedInfo.getReason() != UnassignedInfo.Reason.NODE_LEFT) { removeAllocationId(failedShard); if (failedShard.primary()) { Updates updates = changes(failedShard.shardId()); if (updates.firstFailedPrimary == null) { // more than one primary can be failed (because of batching, primary can be failed, replica promoted and then failed...) updates.firstFailedPrimary = failedShard; } } } if (failedShard.active() && failedShard.primary()) { increasePrimaryTerm(failedShard.shardId()); } }