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

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

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

IndexMetaData.getRoutingFactor介绍

[英]Returns the routing factor for this index. The default is 1.
[中]返回此索引的路由因子。默认值为1。

代码示例

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

private static int calculateScaledShardId(IndexMetaData indexMetaData, String effectiveRouting, int partitionOffset) {
  final int hash = Murmur3HashFunction.hash(effectiveRouting) + partitionOffset;
  // we don't use IMD#getNumberOfShards since the index might have been shrunk such that we need to use the size
  // of original index to hash documents
  return Math.floorMod(hash, indexMetaData.getRoutingNumShards()) / indexMetaData.getRoutingFactor();
}

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

/**
 * Returns the source shard ID to split the given target shard off
 * @param shardId the id of the target shard to split into
 * @param sourceIndexMetadata the source index metadata
 * @param numTargetShards the total number of shards in the target index
 * @return a the source shard ID to split off from
 */
public static ShardId selectSplitShard(int shardId, IndexMetaData sourceIndexMetadata, int numTargetShards) {
  if (shardId >= numTargetShards) {
    throw new IllegalArgumentException("the number of target shards (" + numTargetShards + ") must be greater than the shard id: "
      + shardId);
  }
  int numSourceShards = sourceIndexMetadata.getNumberOfShards();
  if (numSourceShards > numTargetShards) {
    throw new IllegalArgumentException("the number of source shards [" + numSourceShards
       + "] must be less that the number of target shards [" + numTargetShards + "]");
  }
  int routingFactor = getRoutingFactor(numSourceShards, numTargetShards);
  // now we verify that the numRoutingShards is valid in the source index
  int routingNumShards = sourceIndexMetadata.getRoutingNumShards();
  if (routingNumShards % numTargetShards != 0) {
    throw new IllegalStateException("the number of routing shards ["
      + routingNumShards + "] must be a multiple of the target shards [" + numTargetShards + "]");
  }
  // this is just an additional assertion that ensures we are a factor of the routing num shards.
  assert getRoutingFactor(numTargetShards, sourceIndexMetadata.getRoutingNumShards()) >= 0;
  return new ShardId(sourceIndexMetadata.getIndex(), shardId/routingFactor);
}

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

/**
 * Returns the source shard ids to shrink into the given shard id.
 * @param shardId the id of the target shard to shrink to
 * @param sourceIndexMetadata the source index metadata
 * @param numTargetShards the total number of shards in the target index
 * @return a set of shard IDs to shrink into the given shard ID.
 */
public static Set<ShardId> selectShrinkShards(int shardId, IndexMetaData sourceIndexMetadata, int numTargetShards) {
  if (shardId >= numTargetShards) {
    throw new IllegalArgumentException("the number of target shards (" + numTargetShards + ") must be greater than the shard id: "
      + shardId);
  }
  if (sourceIndexMetadata.getNumberOfShards() < numTargetShards) {
    throw new IllegalArgumentException("the number of target shards [" + numTargetShards
      +"] must be less that the number of source shards [" + sourceIndexMetadata.getNumberOfShards() + "]");
  }
  int routingFactor = getRoutingFactor(sourceIndexMetadata.getNumberOfShards(), numTargetShards);
  Set<ShardId> shards = new HashSet<>(routingFactor);
  for (int i = shardId * routingFactor; i < routingFactor*shardId + routingFactor; i++) {
    shards.add(new ShardId(sourceIndexMetadata.getIndex(), i));
  }
  return shards;
}

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

static IndexMetaData validateResize(ClusterState state, String sourceIndex,
                    Set<String> targetIndexMappingsTypes, String targetIndexName,
                    Settings targetIndexSettings) {
  if (state.metaData().hasIndex(targetIndexName)) {
    throw new ResourceAlreadyExistsException(state.metaData().index(targetIndexName).getIndex());
  }
  final IndexMetaData sourceMetaData = state.metaData().index(sourceIndex);
  if (sourceMetaData == null) {
    throw new IndexNotFoundException(sourceIndex);
  }
  // ensure index is read-only
  if (state.blocks().indexBlocked(ClusterBlockLevel.WRITE, sourceIndex) == false) {
    throw new IllegalStateException("index " + sourceIndex + " must be read-only to resize index. use \"index.blocks.write=true\"");
  }
  if ((targetIndexMappingsTypes.size() > 1 ||
    (targetIndexMappingsTypes.isEmpty() || targetIndexMappingsTypes.contains(MapperService.DEFAULT_MAPPING)) == false)) {
    throw new IllegalArgumentException("mappings are not allowed when resizing indices" +
      ", all mappings are copied from the source index");
  }
  if (IndexMetaData.INDEX_NUMBER_OF_SHARDS_SETTING.exists(targetIndexSettings)) {
    // this method applies all necessary checks ie. if the target shards are less than the source shards
    // of if the source shards are divisible by the number of target shards
    IndexMetaData.getRoutingFactor(sourceMetaData.getNumberOfShards(),
      IndexMetaData.INDEX_NUMBER_OF_SHARDS_SETTING.get(targetIndexSettings));
  }
  return sourceMetaData;
}

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

/**
 * Returns the source shard ids to shrink into the given shard id.
 * @param shardId the id of the target shard to shrink to
 * @param sourceIndexMetadata the source index metadata
 * @param numTargetShards the total number of shards in the target index
 * @return a set of shard IDs to shrink into the given shard ID.
 */
public static Set<ShardId> selectShrinkShards(int shardId, IndexMetaData sourceIndexMetadata, int numTargetShards) {
  if (shardId >= numTargetShards) {
    throw new IllegalArgumentException("the number of target shards (" + numTargetShards + ") must be greater than the shard id: "
      + shardId);
  }
  int routingFactor = getRoutingFactor(sourceIndexMetadata, numTargetShards);
  Set<ShardId> shards = new HashSet<>(routingFactor);
  for (int i = shardId * routingFactor; i < routingFactor*shardId + routingFactor; i++) {
    shards.add(new ShardId(sourceIndexMetadata.getIndex(), i));
  }
  return shards;
}

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

private static int calculateScaledShardId(IndexMetaData indexMetaData, String effectiveRouting, int partitionOffset) {
  final int hash = Murmur3HashFunction.hash(effectiveRouting) + partitionOffset;
  // we don't use IMD#getNumberOfShards since the index might have been shrunk such that we need to use the size
  // of original index to hash documents
  return Math.floorMod(hash, indexMetaData.getRoutingNumShards()) / indexMetaData.getRoutingFactor();
}

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

private static int calculateScaledShardId(IndexMetaData indexMetaData, String effectiveRouting, int partitionOffset) {
  final int hash = Murmur3HashFunction.hash(effectiveRouting) + partitionOffset;
  // we don't use IMD#getNumberOfShards since the index might have been shrunk such that we need to use the size
  // of original index to hash documents
  return Math.floorMod(hash, indexMetaData.getRoutingNumShards()) / indexMetaData.getRoutingFactor();
}

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

/**
 * Returns the source shard ID to split the given target shard off
 * @param shardId the id of the target shard to split into
 * @param sourceIndexMetadata the source index metadata
 * @param numTargetShards the total number of shards in the target index
 * @return a the source shard ID to split off from
 */
public static ShardId selectSplitShard(int shardId, IndexMetaData sourceIndexMetadata, int numTargetShards) {
  if (shardId >= numTargetShards) {
    throw new IllegalArgumentException("the number of target shards (" + numTargetShards + ") must be greater than the shard id: "
      + shardId);
  }
  int numSourceShards = sourceIndexMetadata.getNumberOfShards();
  if (numSourceShards > numTargetShards) {
    throw new IllegalArgumentException("the number of source shards [" + numSourceShards
       + "] must be less that the number of target shards [" + numTargetShards + "]");
  }
  int routingFactor = getRoutingFactor(numSourceShards, numTargetShards);
  // now we verify that the numRoutingShards is valid in the source index
  int routingNumShards = sourceIndexMetadata.getRoutingNumShards();
  if (routingNumShards % numTargetShards != 0) {
    throw new IllegalStateException("the number of routing shards ["
      + routingNumShards + "] must be a multiple of the target shards [" + numTargetShards + "]");
  }
  // this is just an additional assertion that ensures we are a factor of the routing num shards.
  assert getRoutingFactor(numTargetShards, sourceIndexMetadata.getRoutingNumShards()) >= 0;
  return new ShardId(sourceIndexMetadata.getIndex(), shardId/routingFactor);
}

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

private static int calculateScaledShardId(IndexMetaData indexMetaData, String effectiveRouting, int partitionOffset) {
  final int hash = Murmur3HashFunction.hash(effectiveRouting) + partitionOffset;
  // we don't use IMD#getNumberOfShards since the index might have been shrunk such that we need to use the size
  // of original index to hash documents
  return Math.floorMod(hash, indexMetaData.getRoutingNumShards()) / indexMetaData.getRoutingFactor();
}

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

static IndexMetaData validateResize(ClusterState state, String sourceIndex,
                    Set<String> targetIndexMappingsTypes, String targetIndexName,
                    Settings targetIndexSettings) {
  if (state.metaData().hasIndex(targetIndexName)) {
    throw new ResourceAlreadyExistsException(state.metaData().index(targetIndexName).getIndex());
  }
  final IndexMetaData sourceMetaData = state.metaData().index(sourceIndex);
  if (sourceMetaData == null) {
    throw new IndexNotFoundException(sourceIndex);
  }
  // ensure index is read-only
  if (state.blocks().indexBlocked(ClusterBlockLevel.WRITE, sourceIndex) == false) {
    throw new IllegalStateException("index " + sourceIndex + " must be read-only to resize index. use \"index.blocks.write=true\"");
  }
  if ((targetIndexMappingsTypes.size() > 1 ||
    (targetIndexMappingsTypes.isEmpty() || targetIndexMappingsTypes.contains(MapperService.DEFAULT_MAPPING)) == false)) {
    throw new IllegalArgumentException("mappings are not allowed when resizing indices" +
      ", all mappings are copied from the source index");
  }
  if (IndexMetaData.INDEX_NUMBER_OF_SHARDS_SETTING.exists(targetIndexSettings)) {
    // this method applies all necessary checks ie. if the target shards are less than the source shards
    // of if the source shards are divisible by the number of target shards
    IndexMetaData.getRoutingFactor(sourceMetaData.getNumberOfShards(),
      IndexMetaData.INDEX_NUMBER_OF_SHARDS_SETTING.get(targetIndexSettings));
  }
  return sourceMetaData;
}

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

/**
 * Returns the source shard ids to shrink into the given shard id.
 * @param shardId the id of the target shard to shrink to
 * @param sourceIndexMetadata the source index metadata
 * @param numTargetShards the total number of shards in the target index
 * @return a set of shard IDs to shrink into the given shard ID.
 */
public static Set<ShardId> selectShrinkShards(int shardId, IndexMetaData sourceIndexMetadata, int numTargetShards) {
  if (shardId >= numTargetShards) {
    throw new IllegalArgumentException("the number of target shards (" + numTargetShards + ") must be greater than the shard id: "
      + shardId);
  }
  if (sourceIndexMetadata.getNumberOfShards() < numTargetShards) {
    throw new IllegalArgumentException("the number of target shards [" + numTargetShards
      +"] must be less that the number of source shards [" + sourceIndexMetadata.getNumberOfShards() + "]");
  }
  int routingFactor = getRoutingFactor(sourceIndexMetadata.getNumberOfShards(), numTargetShards);
  Set<ShardId> shards = new HashSet<>(routingFactor);
  for (int i = shardId * routingFactor; i < routingFactor*shardId + routingFactor; i++) {
    shards.add(new ShardId(sourceIndexMetadata.getIndex(), i));
  }
  return shards;
}

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

/**
 * Returns the source shard ids to shrink into the given shard id.
 * @param shardId the id of the target shard to shrink to
 * @param sourceIndexMetadata the source index metadata
 * @param numTargetShards the total number of shards in the target index
 * @return a set of shard IDs to shrink into the given shard ID.
 */
public static Set<ShardId> selectShrinkShards(int shardId, IndexMetaData sourceIndexMetadata, int numTargetShards) {
  if (shardId >= numTargetShards) {
    throw new IllegalArgumentException("the number of target shards (" + numTargetShards + ") must be greater than the shard id: "
      + shardId);
  }
  if (sourceIndexMetadata.getNumberOfShards() < numTargetShards) {
    throw new IllegalArgumentException("the number of target shards [" + numTargetShards
      +"] must be less that the number of source shards [" + sourceIndexMetadata.getNumberOfShards() + "]");
  }
  int routingFactor = getRoutingFactor(sourceIndexMetadata.getNumberOfShards(), numTargetShards);
  Set<ShardId> shards = new HashSet<>(routingFactor);
  for (int i = shardId * routingFactor; i < routingFactor*shardId + routingFactor; i++) {
    shards.add(new ShardId(sourceIndexMetadata.getIndex(), i));
  }
  return shards;
}

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

IndexMetaData.getRoutingFactor(sourceMetaData, IndexMetaData.INDEX_NUMBER_OF_SHARDS_SETTING.get(targetIndexSettings));

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

static IndexMetaData validateResize(ClusterState state, String sourceIndex,
                    Set<String> targetIndexMappingsTypes, String targetIndexName,
                    Settings targetIndexSettings) {
  if (state.metaData().hasIndex(targetIndexName)) {
    throw new ResourceAlreadyExistsException(state.metaData().index(targetIndexName).getIndex());
  }
  final IndexMetaData sourceMetaData = state.metaData().index(sourceIndex);
  if (sourceMetaData == null) {
    throw new IndexNotFoundException(sourceIndex);
  }
  // ensure index is read-only
  if (state.blocks().indexBlocked(ClusterBlockLevel.WRITE, sourceIndex) == false) {
    throw new IllegalStateException("index " + sourceIndex + " must be read-only to resize index. use \"index.blocks.write=true\"");
  }
  if ((targetIndexMappingsTypes.size() > 1 ||
    (targetIndexMappingsTypes.isEmpty() || targetIndexMappingsTypes.contains(MapperService.DEFAULT_MAPPING)) == false)) {
    throw new IllegalArgumentException("mappings are not allowed when resizing indices" +
      ", all mappings are copied from the source index");
  }
  if (IndexMetaData.INDEX_NUMBER_OF_SHARDS_SETTING.exists(targetIndexSettings)) {
    // this method applies all necessary checks ie. if the target shards are less than the source shards
    // of if the source shards are divisible by the number of target shards
    IndexMetaData.getRoutingFactor(sourceMetaData.getNumberOfShards(),
      IndexMetaData.INDEX_NUMBER_OF_SHARDS_SETTING.get(targetIndexSettings));
  }
  return sourceMetaData;
}

相关文章

微信公众号

最新文章

更多

IndexMetaData类方法