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

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

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

IndexMetaData.getSettings介绍

暂无

代码示例

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

private IndexScopedSettings(Settings settings, IndexScopedSettings other, IndexMetaData metaData) {
  super(settings, metaData.getSettings(), other);
}

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

@Override
  public ClusterState execute(ClusterState currentState) {
    MetaData.Builder metaDataBuilder = MetaData.builder(currentState.metaData());
    for (Map.Entry<String, Tuple<Version, String>> entry : request.versions().entrySet()) {
      String index = entry.getKey();
      IndexMetaData indexMetaData = metaDataBuilder.get(index);
      if (indexMetaData != null) {
        if (Version.CURRENT.equals(indexMetaData.getCreationVersion()) == false) {
          // no reason to pollute the settings, we didn't really upgrade anything
          metaDataBuilder.put(
              IndexMetaData
                  .builder(indexMetaData)
                  .settings(
                      Settings
                          .builder()
                          .put(indexMetaData.getSettings())
                          .put(IndexMetaData.SETTING_VERSION_UPGRADED, entry.getValue().v1()))
                  .settingsVersion(1 + indexMetaData.getSettingsVersion()));
        }
      }
    }
    return ClusterState.builder(currentState).metaData(metaDataBuilder).build();
  }
});

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

@Override
  protected Settings getIndexSettings(Index index) {
    IndexMetaData indexMetaData = allocation.metaData().getIndexSafe(index);
    return indexMetaData.getSettings();
  }
};

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

private static boolean addIndex(IndexMetaData metaData, Context context) {
  return (context.options.ignoreThrottled() && IndexSettings.INDEX_SEARCH_THROTTLED.get(metaData.getSettings())) == false;
}

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

/**
 * Marks index as upgraded so we don't have to test it again
 */
private IndexMetaData markAsUpgraded(IndexMetaData indexMetaData) {
  Settings settings = Settings.builder().put(indexMetaData.getSettings())
    .put(IndexMetaData.SETTING_VERSION_UPGRADED, Version.CURRENT).build();
  return IndexMetaData.builder(indexMetaData).settings(settings).build();
}

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

IndexMetaData archiveBrokenIndexSettings(IndexMetaData indexMetaData) {
    final Settings settings = indexMetaData.getSettings();
    final Settings upgrade = indexScopedSettings.archiveUnknownOrInvalidSettings(
      settings,
      e -> logger.warn("{} ignoring unknown index setting: [{}] with value [{}]; archiving",
        indexMetaData.getIndex(), e.getKey(), e.getValue()),
      (e, ex) -> logger.warn(() -> new ParameterizedMessage("{} ignoring invalid index setting: [{}] with value [{}]; archiving",
        indexMetaData.getIndex(), e.getKey(), e.getValue()), ex));
    if (upgrade != settings) {
      return IndexMetaData.builder(indexMetaData).settings(upgrade).build();
    } else {
      return indexMetaData;
    }
  }
}

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

public Builder addBlocks(IndexMetaData indexMetaData) {
  String indexName = indexMetaData.getIndex().getName();
  if (indexMetaData.getState() == IndexMetaData.State.CLOSE) {
    addIndexBlock(indexName, MetaDataIndexStateService.INDEX_CLOSED_BLOCK);
  }
  if (IndexMetaData.INDEX_READ_ONLY_SETTING.get(indexMetaData.getSettings())) {
    addIndexBlock(indexName, IndexMetaData.INDEX_READ_ONLY_BLOCK);
  }
  if (IndexMetaData.INDEX_BLOCKS_READ_SETTING.get(indexMetaData.getSettings())) {
    addIndexBlock(indexName, IndexMetaData.INDEX_READ_BLOCK);
  }
  if (IndexMetaData.INDEX_BLOCKS_WRITE_SETTING.get(indexMetaData.getSettings())) {
    addIndexBlock(indexName, IndexMetaData.INDEX_WRITE_BLOCK);
  }
  if (IndexMetaData.INDEX_BLOCKS_METADATA_SETTING.get(indexMetaData.getSettings())) {
    addIndexBlock(indexName, IndexMetaData.INDEX_METADATA_BLOCK);
  }
  if (IndexMetaData.INDEX_BLOCKS_READ_ONLY_ALLOW_DELETE_SETTING.get(indexMetaData.getSettings())) {
    addIndexBlock(indexName, IndexMetaData.INDEX_READ_ONLY_ALLOW_DELETE_BLOCK);
  }
  return this;
}

代码示例来源: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

public Builder updateSettings(Settings settings, String... indices) {
  if (indices == null || indices.length == 0) {
    indices = this.indices.keys().toArray(String.class);
  }
  for (String index : indices) {
    IndexMetaData indexMetaData = this.indices.get(index);
    if (indexMetaData == null) {
      throw new IndexNotFoundException(index);
    }
    put(IndexMetaData.builder(indexMetaData)
        .settings(Settings.builder().put(indexMetaData.getSettings()).put(settings)));
  }
  return this;
}

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

/**
 * Updates the settings and index metadata and notifies all registered settings consumers with the new settings iff at least one
 * setting has changed.
 *
 * @return <code>true</code> iff any setting has been updated otherwise <code>false</code>.
 */
public synchronized boolean updateIndexMetaData(IndexMetaData indexMetaData) {
  final Settings newSettings = indexMetaData.getSettings();
  if (version.equals(Version.indexCreated(newSettings)) == false) {
    throw new IllegalArgumentException("version mismatch on settings update expected: " + version + " but was: " +
      Version.indexCreated(newSettings));
  }
  final String newUUID = newSettings.get(IndexMetaData.SETTING_INDEX_UUID, IndexMetaData.INDEX_UUID_NA_VALUE);
  if (newUUID.equals(getUUID()) == false) {
    throw new IllegalArgumentException("uuid mismatch on settings update expected: " + getUUID() + " but was: " + newUUID);
  }
  this.indexMetaData = indexMetaData;
  final Settings newIndexSettings = Settings.builder().put(nodeSettings).put(newSettings).build();
  if (same(this.settings, newIndexSettings)) {
    // nothing to update, same settings
    return false;
  }
  scopedSettings.applySettings(newSettings);
  this.settings = newIndexSettings;
  return true;
}

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

public Builder(IndexMetaData indexMetaData) {
  this.index = indexMetaData.getIndex().getName();
  this.state = indexMetaData.state;
  this.version = indexMetaData.version;
  this.mappingVersion = indexMetaData.mappingVersion;
  this.settingsVersion = indexMetaData.settingsVersion;
  this.settings = indexMetaData.getSettings();
  this.primaryTerms = indexMetaData.primaryTerms.clone();
  this.mappings = ImmutableOpenMap.builder(indexMetaData.mappings);
  this.aliases = ImmutableOpenMap.builder(indexMetaData.aliases);
  this.customMetaData = ImmutableOpenMap.builder(indexMetaData.customData);
  this.routingNumShards = indexMetaData.routingNumShards;
  this.inSyncAllocationIds = ImmutableOpenIntMap.builder(indexMetaData.inSyncAllocationIds);
  this.rolloverInfos = ImmutableOpenMap.builder(indexMetaData.rolloverInfos);
}

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

private void deassociateDeadNodes(RoutingAllocation allocation) {
  for (Iterator<RoutingNode> it = allocation.routingNodes().mutableIterator(); it.hasNext(); ) {
    RoutingNode node = it.next();
    if (allocation.nodes().getDataNodes().containsKey(node.nodeId())) {
      // its a live node, continue
      continue;
    }
    // now, go over all the shards routing on the node, and fail them
    for (ShardRouting shardRouting : node.copyShards()) {
      final IndexMetaData indexMetaData = allocation.metaData().getIndexSafe(shardRouting.index());
      boolean delayed = INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING.get(indexMetaData.getSettings()).nanos() > 0;
      UnassignedInfo unassignedInfo = new UnassignedInfo(UnassignedInfo.Reason.NODE_LEFT, "node_left[" + node.nodeId() + "]",
        null, 0, allocation.getCurrentNanoTime(), System.currentTimeMillis(), delayed, AllocationStatus.NO_ATTEMPT);
      allocation.routingNodes().failShard(logger, shardRouting, unassignedInfo, indexMetaData, allocation.changes());
    }
    // its a dead node, remove it, note, its important to remove it *after* we apply failed shard
    // since it relies on the fact that the RoutingNode exists in the list of nodes
    it.remove();
  }
}

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

/**
 * Finds the next (closest) delay expiration of an delayed shard in nanoseconds based on current time.
 * Returns 0 if delay is negative.
 * Returns -1 if no delayed shard is found.
 */
public static long findNextDelayedAllocation(long currentNanoTime, ClusterState state) {
  MetaData metaData = state.metaData();
  RoutingTable routingTable = state.routingTable();
  long nextDelayNanos = Long.MAX_VALUE;
  for (ShardRouting shard : routingTable.shardsWithState(ShardRoutingState.UNASSIGNED)) {
    UnassignedInfo unassignedInfo = shard.unassignedInfo();
    if (unassignedInfo.isDelayed()) {
      Settings indexSettings = metaData.index(shard.index()).getSettings();
      // calculate next time to schedule
      final long newComputedLeftDelayNanos = unassignedInfo.getRemainingDelay(currentNanoTime, indexSettings);
      if (newComputedLeftDelayNanos < nextDelayNanos) {
        nextDelayNanos = newComputedLeftDelayNanos;
      }
    }
  }
  return nextDelayNanos == Long.MAX_VALUE ? -1L : nextDelayNanos;
}

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

final IndexSettings idxSettings = new IndexSettings(indexMetaData, settings, indexScopedSettings);
indexScopedSettings.validate(indexMetaData.getSettings(), true, true, true);
logger.debug("creating Index [{}], shards [{}]/[{}] - reason [{}]",
  indexMetaData.getIndex(),

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

private Decision doDecide(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation,
             BiPredicate<Integer, Integer> decider) {
  IndexMetaData indexMd = allocation.metaData().getIndexSafe(shardRouting.index());
  final int indexShardLimit = INDEX_TOTAL_SHARDS_PER_NODE_SETTING.get(indexMd.getSettings(), settings);

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

final Allocation enable;
final boolean usedIndexSetting;
if (INDEX_ROUTING_ALLOCATION_ENABLE_SETTING.exists(indexMetaData.getSettings())) {
  enable = INDEX_ROUTING_ALLOCATION_ENABLE_SETTING.get(indexMetaData.getSettings());
  usedIndexSetting = true;
} else {

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

@Override
public Decision canAllocate(ShardRouting shardRouting, RoutingAllocation allocation) {
  final UnassignedInfo unassignedInfo = shardRouting.unassignedInfo();
  final Decision decision;
  if (unassignedInfo != null && unassignedInfo.getNumFailedAllocations() > 0) {
    final IndexMetaData indexMetaData = allocation.metaData().getIndexSafe(shardRouting.index());
    final int maxRetry = SETTING_ALLOCATION_MAX_RETRY.get(indexMetaData.getSettings());
    if (unassignedInfo.getNumFailedAllocations() >= maxRetry) {
      decision = allocation.decision(Decision.NO, NAME, "shard has exceeded the maximum number of retries [%d] on " +
        "failed allocation attempts - manually call [/_cluster/reroute?retry_failed=true] to retry, [%s]",
        maxRetry, unassignedInfo.toString());
    } else {
      decision = allocation.decision(Decision.YES, NAME, "shard has failed allocating [%d] times but [%d] retries are allowed",
        unassignedInfo.getNumFailedAllocations(), maxRetry);
    }
  } else {
    decision = allocation.decision(Decision.YES, NAME, "shard has no previous failures");
  }
  return decision;
}

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

Settings indexSettings = allocation.metaData().getIndexSafe(shardRouting.index()).getSettings();
final Rebalance enable;
final boolean usedIndexSetting;

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

/**
 * Removes delay markers from unassigned shards based on current time stamp.
 */
private void removeDelayMarkers(RoutingAllocation allocation) {
  final RoutingNodes.UnassignedShards.UnassignedIterator unassignedIterator = allocation.routingNodes().unassigned().iterator();
  final MetaData metaData = allocation.metaData();
  while (unassignedIterator.hasNext()) {
    ShardRouting shardRouting = unassignedIterator.next();
    UnassignedInfo unassignedInfo = shardRouting.unassignedInfo();
    if (unassignedInfo.isDelayed()) {
      final long newComputedLeftDelayNanos = unassignedInfo.getRemainingDelay(allocation.getCurrentNanoTime(),
        metaData.getIndexSafe(shardRouting.index()).getSettings());
      if (newComputedLeftDelayNanos == 0) {
        unassignedIterator.updateUnassigned(new UnassignedInfo(unassignedInfo.getReason(), unassignedInfo.getMessage(),
          unassignedInfo.getFailure(), unassignedInfo.getNumFailedAllocations(), unassignedInfo.getUnassignedTimeInNanos(),
          unassignedInfo.getUnassignedTimeInMillis(), false, unassignedInfo.getLastAllocationStatus()),
          shardRouting.recoverySource(), allocation.changes());
      }
    }
  }
}

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

Settings indexSettings = settingsFilter.filter(indexMetaData.getSettings());
if (request.humanReadable()) {
  indexSettings = IndexMetaData.addHumanReadableSettings(indexSettings);

相关文章

微信公众号

最新文章

更多

IndexMetaData类方法