org.elasticsearch.cluster.metadata.IndexMetaData.getNumberOfReplicas()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(10.0k)|赞(0)|评价(0)|浏览(114)

本文整理了Java中org.elasticsearch.cluster.metadata.IndexMetaData.getNumberOfReplicas()方法的一些代码示例,展示了IndexMetaData.getNumberOfReplicas()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IndexMetaData.getNumberOfReplicas()方法的具体详情如下:
包路径:org.elasticsearch.cluster.metadata.IndexMetaData
类名称:IndexMetaData
方法名:getNumberOfReplicas

IndexMetaData.getNumberOfReplicas介绍

暂无

代码示例

代码示例来源:origin: org.elasticsearch/elasticsearch

@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));
    }
  }
});

代码示例来源:origin: org.elasticsearch/elasticsearch

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;
}

代码示例来源:origin: org.elasticsearch/elasticsearch

/**
 * 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;
}

代码示例来源:origin: org.elasticsearch/elasticsearch

private static int getTotalShardCount(ClusterState state, Index index) {
  IndexMetaData indexMetaData = state.metaData().index(index);
  return indexMetaData.getNumberOfShards() * (1 + indexMetaData.getNumberOfReplicas());
}

代码示例来源:origin: org.elasticsearch/elasticsearch

/**
   * 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;
  }
}

代码示例来源:origin: org.elasticsearch/elasticsearch

int maxActiveShards = oldIndexMetaData.getNumberOfReplicas() + 1; // +1 for the primary
IndexShardRoutingTable newShardRoutingTable = newRoutingTable.shardRoutingTable(shardId);
if (inSyncAllocationIds.size() > oldInSyncAllocationIds.size() && inSyncAllocationIds.size() > maxActiveShards) {

代码示例来源:origin: org.elasticsearch/elasticsearch

@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);
    }
  }
};

代码示例来源:origin: org.elasticsearch/elasticsearch

if (routingNumberOfReplicas != indexMetaData.getNumberOfReplicas()) {
  throw new IllegalStateException("Shard [" + indexShardRoutingTable.shardId().id() +
           "] routing table has wrong number of replicas, expected [" + indexMetaData.getNumberOfReplicas() +
           "], got [" + routingNumberOfReplicas + "]");

代码示例来源:origin: org.elasticsearch/elasticsearch

public ClusterIndexHealth(final IndexMetaData indexMetaData, final IndexRoutingTable indexRoutingTable) {
  this.index = indexMetaData.getIndex().getName();
  this.numberOfShards = indexMetaData.getNumberOfShards();
  this.numberOfReplicas = indexMetaData.getNumberOfReplicas();

代码示例来源:origin: org.elasticsearch/elasticsearch

for (int i = 0; i <= indexMetaData.getNumberOfReplicas(); i++) {
  boolean primary = i == 0;
  indexShardRoutingBuilder.addShard(ShardRouting.newUnassigned(shardId, primary,

代码示例来源:origin: org.elasticsearch/elasticsearch

/**
 * 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;
}

代码示例来源:origin: org.elasticsearch/elasticsearch

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());

代码示例来源:origin: org.elasticsearch/elasticsearch

int shardCount = indexMetaData.getNumberOfReplicas() + 1; // 1 for primary
for (String awarenessAttribute : awarenessAttributes) {

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.elasticsearch

@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));
    }
  }
});

代码示例来源:origin: apache/servicemix-bundles

@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));
    }
  }
});

代码示例来源:origin: com.strapdata.elasticsearch/elasticsearch

@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));
    }
  }
});

代码示例来源:origin: harbby/presto-connectors

@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));
    }
  }
});

代码示例来源:origin: com.strapdata.elasticsearch/elasticsearch

/**
 * 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;
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.elasticsearch

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;
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.elasticsearch

private static int getTotalShardCount(ClusterState state, Index index) {
  IndexMetaData indexMetaData = state.metaData().index(index);
  return indexMetaData.getNumberOfShards() * (1 + indexMetaData.getNumberOfReplicas());
}

相关文章

微信公众号

最新文章

更多

IndexMetaData类方法