@Override public void onFailure(Exception e) { logger.debug("{} unexpected error while executing synced flush", shardId); final int totalShards = indexMetaData.getNumberOfReplicas() + 1; results.get(index).add(new ShardsSyncedFlushResult(shardId, totalShards, e.getMessage())); if (countDown.countDown()) { listener.onResponse(new SyncedFlushResponse(results)); } } });
private int getTotalNewShards(Index index, ClusterState currentState, int updatedNumberOfReplicas) { IndexMetaData indexMetaData = currentState.metaData().index(index); int shardsInIndex = indexMetaData.getNumberOfShards(); int oldNumberOfReplicas = indexMetaData.getNumberOfReplicas(); int replicaIncrease = updatedNumberOfReplicas - oldNumberOfReplicas; return replicaIncrease * shardsInIndex; }
/** * Returns <code>true</code> iff all replicas are active for the given shard routing. Otherwise <code>false</code> */ public boolean allReplicasActive(ShardId shardId, MetaData metaData) { final List<ShardRouting> shards = assignedShards(shardId); if (shards.isEmpty() || shards.size() < metaData.getIndexSafe(shardId.getIndex()).getNumberOfReplicas() + 1) { return false; // if we are empty nothing is active if we have less than total at least one is unassigned } for (ShardRouting shard : shards) { if (!shard.active()) { return false; } } return true; }
private static int getTotalShardCount(ClusterState state, Index index) { IndexMetaData indexMetaData = state.metaData().index(index); return indexMetaData.getNumberOfShards() * (1 + indexMetaData.getNumberOfReplicas()); }
/** * Checks if the are replicas with the auto-expand feature that need to be adapted. * Returns a map of updates, which maps the indices to be updated to the desired number of replicas. * The map has the desired number of replicas as key and the indices to update as value, as this allows the result * of this method to be directly applied to RoutingTable.Builder#updateNumberOfReplicas. */ public static Map<Integer, List<String>> getAutoExpandReplicaChanges(MetaData metaData, DiscoveryNodes discoveryNodes) { // used for translating "all" to a number final int dataNodeCount = discoveryNodes.getDataNodes().size(); Map<Integer, List<String>> nrReplicasChanged = new HashMap<>(); for (final IndexMetaData indexMetaData : metaData) { if (indexMetaData.getState() != IndexMetaData.State.CLOSE) { AutoExpandReplicas autoExpandReplicas = SETTING.get(indexMetaData.getSettings()); autoExpandReplicas.getDesiredNumberOfReplicas(dataNodeCount).ifPresent(numberOfReplicas -> { if (numberOfReplicas != indexMetaData.getNumberOfReplicas()) { nrReplicasChanged.computeIfAbsent(numberOfReplicas, ArrayList::new).add(indexMetaData.getIndex().getName()); } }); } } return nrReplicasChanged; } }
int maxActiveShards = oldIndexMetaData.getNumberOfReplicas() + 1; // +1 for the primary IndexShardRoutingTable newShardRoutingTable = newRoutingTable.shardRoutingTable(shardId); if (inSyncAllocationIds.size() > oldInSyncAllocationIds.size() && inSyncAllocationIds.size() > maxActiveShards) {
@Override public void onFailure(Exception e) { logger.trace("{}: got failure from {}", actionName, shardId); int totalNumCopies = clusterState.getMetaData().getIndexSafe(shardId.getIndex()).getNumberOfReplicas() + 1; ShardResponse shardResponse = newShardResponse(); ReplicationResponse.ShardInfo.Failure[] failures; if (TransportActions.isShardNotAvailableException(e)) { failures = new ReplicationResponse.ShardInfo.Failure[0]; } else { ReplicationResponse.ShardInfo.Failure failure = new ReplicationResponse.ShardInfo.Failure(shardId, null, e, ExceptionsHelper.status(e), true); failures = new ReplicationResponse.ShardInfo.Failure[totalNumCopies]; Arrays.fill(failures, failure); } shardResponse.setShardInfo(new ReplicationResponse.ShardInfo(totalNumCopies, 0, failures)); shardsResponses.add(shardResponse); if (responsesCountDown.countDown()) { finishAndNotifyListener(listener, shardsResponses); } } };
if (routingNumberOfReplicas != indexMetaData.getNumberOfReplicas()) { throw new IllegalStateException("Shard [" + indexShardRoutingTable.shardId().id() + "] routing table has wrong number of replicas, expected [" + indexMetaData.getNumberOfReplicas() + "], got [" + routingNumberOfReplicas + "]");
public ClusterIndexHealth(final IndexMetaData indexMetaData, final IndexRoutingTable indexRoutingTable) { this.index = indexMetaData.getIndex().getName(); this.numberOfShards = indexMetaData.getNumberOfShards(); this.numberOfReplicas = indexMetaData.getNumberOfReplicas();
for (int i = 0; i <= indexMetaData.getNumberOfReplicas(); i++) { boolean primary = i == 0; indexShardRoutingBuilder.addShard(ShardRouting.newUnassigned(shardId, primary,
/** * Initializes an index, to be restored from snapshot */ private Builder initializeAsRestore(IndexMetaData indexMetaData, SnapshotRecoverySource recoverySource, IntSet ignoreShards, boolean asNew, UnassignedInfo unassignedInfo) { assert indexMetaData.getIndex().equals(index); if (!shards.isEmpty()) { throw new IllegalStateException("trying to initialize an index with fresh shards, but already has shards created"); } for (int shardNumber = 0; shardNumber < indexMetaData.getNumberOfShards(); shardNumber++) { ShardId shardId = new ShardId(index, shardNumber); IndexShardRoutingTable.Builder indexShardRoutingBuilder = new IndexShardRoutingTable.Builder(shardId); for (int i = 0; i <= indexMetaData.getNumberOfReplicas(); i++) { boolean primary = i == 0; if (asNew && ignoreShards.contains(shardNumber)) { // This shards wasn't completely snapshotted - restore it as new shard indexShardRoutingBuilder.addShard(ShardRouting.newUnassigned(shardId, primary, primary ? EmptyStoreRecoverySource.INSTANCE : PeerRecoverySource.INSTANCE, unassignedInfo)); } else { indexShardRoutingBuilder.addShard(ShardRouting.newUnassigned(shardId, primary, primary ? recoverySource : PeerRecoverySource.INSTANCE, unassignedInfo)); } } shards.put(shardNumber, indexShardRoutingBuilder.build()); } return this; }
waitForActiveShards = tmpImd.getWaitForActiveShards(); if (waitForActiveShards.validate(tmpImd.getNumberOfReplicas()) == false) { throw new IllegalArgumentException("invalid wait_for_active_shards[" + request.waitForActiveShards() + "]: cannot be greater than number of shard copies [" + (tmpImd.getNumberOfReplicas() + 1) + "]"); indexMetaData.getNumberOfReplicas(), mappings.keySet());
int shardCount = indexMetaData.getNumberOfReplicas() + 1; // 1 for primary for (String awarenessAttribute : awarenessAttributes) {
@Override public void onFailure(Exception e) { logger.debug("{} unexpected error while executing synced flush", shardId); final int totalShards = indexMetaData.getNumberOfReplicas() + 1; results.get(index).add(new ShardsSyncedFlushResult(shardId, totalShards, e.getMessage())); if (countDown.countDown()) { listener.onResponse(new SyncedFlushResponse(results)); } } });
@Override public void onFailure(Exception e) { logger.debug("{} unexpected error while executing synced flush", shardId); final int totalShards = indexMetaData.getNumberOfReplicas() + 1; results.get(index).add(new ShardsSyncedFlushResult(shardId, totalShards, e.getMessage())); if (countDown.countDown()) { listener.onResponse(new SyncedFlushResponse(results)); } } });
@Override public void onFailure(Exception e) { logger.debug("{} unexpected error while executing synced flush", shardId); final int totalShards = indexMetaData.getNumberOfReplicas() + 1; results.get(index).add(new ShardsSyncedFlushResult(shardId, totalShards, e.getMessage())); if (countDown.countDown()) { listener.onResponse(new SyncedFlushResponse(results)); } } });
@Override public void onFailure(Throwable e) { logger.debug("{} unexpected error while executing synced flush", shardId); final int totalShards = indexMetaData.getNumberOfReplicas() + 1; results.get(index).add(new ShardsSyncedFlushResult(shardId, totalShards, e.getMessage())); if (countDown.countDown()) { listener.onResponse(new SyncedFlushResponse(results)); } } });
/** * Returns <code>true</code> iff all replicas are active for the given shard routing. Otherwise <code>false</code> */ public boolean allReplicasActive(ShardId shardId, MetaData metaData) { final List<ShardRouting> shards = assignedShards(shardId); if (shards.isEmpty() || shards.size() < metaData.getIndexSafe(shardId.getIndex()).getNumberOfReplicas() + 1) { return false; // if we are empty nothing is active if we have less than total at least one is unassigned } for (ShardRouting shard : shards) { if (!shard.active()) { return false; } } return true; }
private int getTotalNewShards(Index index, ClusterState currentState, int updatedNumberOfReplicas) { IndexMetaData indexMetaData = currentState.metaData().index(index); int shardsInIndex = indexMetaData.getNumberOfShards(); int oldNumberOfReplicas = indexMetaData.getNumberOfReplicas(); int replicaIncrease = updatedNumberOfReplicas - oldNumberOfReplicas; return replicaIncrease * shardsInIndex; }
private static int getTotalShardCount(ClusterState state, Index index) { IndexMetaData indexMetaData = state.metaData().index(index); return indexMetaData.getNumberOfShards() * (1 + indexMetaData.getNumberOfReplicas()); }