• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java IndexMetaData类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.elasticsearch.cluster.metadata.IndexMetaData的典型用法代码示例。如果您正苦于以下问题:Java IndexMetaData类的具体用法?Java IndexMetaData怎么用?Java IndexMetaData使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



IndexMetaData类属于org.elasticsearch.cluster.metadata包,在下文中一共展示了IndexMetaData类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: checkIndexClosing

import org.elasticsearch.cluster.metadata.IndexMetaData; //导入依赖的package包/类
/**
 * Check if any of the indices to be closed are currently being restored from a snapshot and fail closing if such an index
 * is found as closing an index that is being restored makes the index unusable (it cannot be recovered).
 */
public static void checkIndexClosing(ClusterState currentState, Set<IndexMetaData> indices) {
    RestoreInProgress restore = currentState.custom(RestoreInProgress.TYPE);
    if (restore != null) {
        Set<Index> indicesToFail = null;
        for (RestoreInProgress.Entry entry : restore.entries()) {
            for (ObjectObjectCursor<ShardId, RestoreInProgress.ShardRestoreStatus> shard : entry.shards()) {
                if (!shard.value.state().completed()) {
                    IndexMetaData indexMetaData = currentState.metaData().index(shard.key.getIndex());
                    if (indexMetaData != null && indices.contains(indexMetaData)) {
                        if (indicesToFail == null) {
                            indicesToFail = new HashSet<>();
                        }
                        indicesToFail.add(shard.key.getIndex());
                    }
                }
            }
        }
        if (indicesToFail != null) {
            throw new IllegalArgumentException("Cannot close indices that are being restored: " + indicesToFail);
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:27,代码来源:RestoreService.java


示例2: testPatternCaptureTokenFilter

import org.elasticsearch.cluster.metadata.IndexMetaData; //导入依赖的package包/类
public void testPatternCaptureTokenFilter() throws Exception {
    String json = "/org/elasticsearch/index/analysis/pattern_capture.json";
    Settings settings = Settings.builder()
            .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir())
            .loadFromStream(json, getClass().getResourceAsStream(json))
            .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
            .build();

    IndexSettings idxSettings = IndexSettingsModule.newIndexSettings("index", settings);
    IndexAnalyzers indexAnalyzers = createTestAnalysis(idxSettings, settings).indexAnalyzers;
    NamedAnalyzer analyzer1 = indexAnalyzers.get("single");

    assertTokenStreamContents(analyzer1.tokenStream("test", "foobarbaz"), new String[]{"foobarbaz","foobar","foo"});

    NamedAnalyzer analyzer2 = indexAnalyzers.get("multi");

    assertTokenStreamContents(analyzer2.tokenStream("test", "abc123def"), new String[]{"abc123def","abc","123","def"});

    NamedAnalyzer analyzer3 = indexAnalyzers.get("preserve");

    assertTokenStreamContents(analyzer3.tokenStream("test", "foobarbaz"), new String[]{"foobar","foo"});
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:PatternCaptureTokenFilterTests.java


示例3: testIndexAndTombstoneWithSameNameOnStartup

import org.elasticsearch.cluster.metadata.IndexMetaData; //导入依赖的package包/类
/**
 * This test checks an edge case where, if a node had an index (lets call it A with UUID 1), then
 * deleted it (so a tombstone entry for A will exist in the cluster state), then created
 * a new index A with UUID 2, then shutdown, when the node comes back online, it will look at the
 * tombstones for deletions, and it should proceed with trying to delete A with UUID 1 and not
 * throw any errors that the index still exists in the cluster state.  This is a case of ensuring
 * that tombstones that have the same name as current valid indices don't cause confusion by
 * trying to delete an index that exists.
 * See https://github.com/elastic/elasticsearch/issues/18054
 */
public void testIndexAndTombstoneWithSameNameOnStartup() throws Exception {
    final String indexName = "test";
    final Index index = new Index(indexName, UUIDs.randomBase64UUID());
    final IndicesService indicesService = getIndicesService();
    final Settings idxSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
                                     .put(IndexMetaData.SETTING_INDEX_UUID, index.getUUID())
                                     .build();
    final IndexMetaData indexMetaData = new IndexMetaData.Builder(index.getName())
                                            .settings(idxSettings)
                                            .numberOfShards(1)
                                            .numberOfReplicas(0)
                                            .build();
    final Index tombstonedIndex = new Index(indexName, UUIDs.randomBase64UUID());
    final IndexGraveyard graveyard = IndexGraveyard.builder().addTombstone(tombstonedIndex).build();
    final MetaData metaData = MetaData.builder().put(indexMetaData, true).indexGraveyard(graveyard).build();
    final ClusterState clusterState = new ClusterState.Builder(new ClusterName("testCluster")).metaData(metaData).build();
    // if all goes well, this won't throw an exception, otherwise, it will throw an IllegalStateException
    indicesService.verifyIndexIsDeleted(tombstonedIndex, clusterState);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:30,代码来源:IndicesServiceTests.java


示例4: getExpectedShardSize

import org.elasticsearch.cluster.metadata.IndexMetaData; //导入依赖的package包/类
/**
 * Returns the expected shard size for the given shard or the default value provided if not enough information are available
 * to estimate the shards size.
 */
public static long getExpectedShardSize(ShardRouting shard, RoutingAllocation allocation, long defaultValue) {
    final IndexMetaData metaData = allocation.metaData().getIndexSafe(shard.index());
    final ClusterInfo info = allocation.clusterInfo();
    if (metaData.getMergeSourceIndex() != null && shard.active() == false &&
        shard.recoverySource().getType() == RecoverySource.Type.LOCAL_SHARDS) {
        // in the shrink index case we sum up the source index shards since we basically make a copy of the shard in
        // the worst case
        long targetShardSize = 0;
        final Index mergeSourceIndex = metaData.getMergeSourceIndex();
        final IndexMetaData sourceIndexMeta = allocation.metaData().getIndexSafe(mergeSourceIndex);
        final Set<ShardId> shardIds = IndexMetaData.selectShrinkShards(shard.id(), sourceIndexMeta, metaData.getNumberOfShards());
        for (IndexShardRoutingTable shardRoutingTable : allocation.routingTable().index(mergeSourceIndex.getName())) {
            if (shardIds.contains(shardRoutingTable.shardId())) {
                targetShardSize += info.getShardSize(shardRoutingTable.primaryShard(), 0);
            }
        }
        return targetShardSize == 0 ? defaultValue : targetShardSize;
    } else {
        return info.getShardSize(shard, defaultValue);
    }

}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:27,代码来源:DiskThresholdDecider.java


示例5: createTestAnalysis

import org.elasticsearch.cluster.metadata.IndexMetaData; //导入依赖的package包/类
private static TestAnalysis createTestAnalysis() throws IOException {
    InputStream empty_dict = KuromojiAnalysisTests.class.getResourceAsStream("empty_user_dict.txt");
    InputStream dict = KuromojiAnalysisTests.class.getResourceAsStream("user_dict.txt");
    Path home = createTempDir();
    Path config = home.resolve("config");
    Files.createDirectory(config);
    Files.copy(empty_dict, config.resolve("empty_user_dict.txt"));
    Files.copy(dict, config.resolve("user_dict.txt"));
    String json = "/org/elasticsearch/index/analysis/kuromoji_analysis.json";

    Settings settings = Settings.builder()
        .loadFromStream(json, KuromojiAnalysisTests.class.getResourceAsStream(json))
        .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
        .build();
    Settings nodeSettings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), home).build();
    return createTestAnalysis(new Index("test", "_na_"), nodeSettings, settings, new AnalysisKuromojiPlugin());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:KuromojiAnalysisTests.java


示例6: testRolloverWithNewIndexName

import org.elasticsearch.cluster.metadata.IndexMetaData; //导入依赖的package包/类
public void testRolloverWithNewIndexName() throws Exception {
    assertAcked(prepareCreate("test_index").addAlias(new Alias("test_alias")).get());
    index("test_index", "type1", "1", "field", "value");
    flush("test_index");
    final RolloverResponse response = client().admin().indices().prepareRolloverIndex("test_alias")
        .setNewIndexName("test_new_index").get();
    assertThat(response.getOldIndex(), equalTo("test_index"));
    assertThat(response.getNewIndex(), equalTo("test_new_index"));
    assertThat(response.isDryRun(), equalTo(false));
    assertThat(response.isRolledOver(), equalTo(true));
    assertThat(response.getConditionStatus().size(), equalTo(0));
    final ClusterState state = client().admin().cluster().prepareState().get().getState();
    final IndexMetaData oldIndex = state.metaData().index("test_index");
    assertFalse(oldIndex.getAliases().containsKey("test_alias"));
    final IndexMetaData newIndex = state.metaData().index("test_new_index");
    assertTrue(newIndex.getAliases().containsKey("test_alias"));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:RolloverIT.java


示例7: testDefaultsCompoundAnalysis

import org.elasticsearch.cluster.metadata.IndexMetaData; //导入依赖的package包/类
public void testDefaultsCompoundAnalysis() throws Exception {
    String json = "/org/elasticsearch/index/analysis/stop.json";
    Settings settings = Settings.builder()
        .loadFromStream(json, getClass().getResourceAsStream(json))
            .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString())
            .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
            .build();
    IndexSettings idxSettings = IndexSettingsModule.newIndexSettings("index", settings);
    IndexAnalyzers indexAnalyzers = createTestAnalysis(idxSettings, settings).indexAnalyzers;
    NamedAnalyzer analyzer1 = indexAnalyzers.get("analyzer1");

    assertTokenStreamContents(analyzer1.tokenStream("test", "to be or not to be"), new String[0]);

    NamedAnalyzer analyzer2 = indexAnalyzers.get("analyzer2");

    assertTokenStreamContents(analyzer2.tokenStream("test", "to be or not to be"), new String[0]);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:StopAnalyzerTests.java


示例8: testTypesExistsWithBlocks

import org.elasticsearch.cluster.metadata.IndexMetaData; //导入依赖的package包/类
public void testTypesExistsWithBlocks() throws IOException {
    assertAcked(prepareCreate("ro").addMapping("type1", jsonBuilder().startObject().startObject("type1").endObject().endObject()));
    ensureGreen("ro");

    // Request is not blocked
    for (String block : Arrays.asList(SETTING_BLOCKS_READ, SETTING_BLOCKS_WRITE, SETTING_READ_ONLY)) {
        try {
            enableIndexBlock("ro", block);
            assertThat(client().admin().indices().prepareTypesExists("ro").setTypes("type1").execute().actionGet().isExists(), equalTo(true));
        } finally {
            disableIndexBlock("ro", block);
        }
    }

    // Request is blocked
    try {
        enableIndexBlock("ro", IndexMetaData.SETTING_BLOCKS_METADATA);
        assertBlocked(client().admin().indices().prepareTypesExists("ro").setTypes("type1"));
    } finally {
        disableIndexBlock("ro", IndexMetaData.SETTING_BLOCKS_METADATA);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:TypesExistsIT.java


示例9: testThatAnalyzersAreUsedInMapping

import org.elasticsearch.cluster.metadata.IndexMetaData; //导入依赖的package包/类
public void testThatAnalyzersAreUsedInMapping() throws IOException {
    int randomInt = randomInt(PreBuiltAnalyzers.values().length-1);
    PreBuiltAnalyzers randomPreBuiltAnalyzer = PreBuiltAnalyzers.values()[randomInt];
    String analyzerName = randomPreBuiltAnalyzer.name().toLowerCase(Locale.ROOT);

    Version randomVersion = randomVersion(random());
    Settings indexSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, randomVersion).build();

    NamedAnalyzer namedAnalyzer = new PreBuiltAnalyzerProvider(analyzerName, AnalyzerScope.INDEX, randomPreBuiltAnalyzer.getAnalyzer(randomVersion)).get();

    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
            .startObject("properties").startObject("field").field("type", "text").field("analyzer", analyzerName).endObject().endObject()
            .endObject().endObject().string();
    DocumentMapper docMapper = createIndex("test", indexSettings).mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));

    FieldMapper fieldMapper = docMapper.mappers().getMapper("field");
    assertThat(fieldMapper.fieldType().searchAnalyzer(), instanceOf(NamedAnalyzer.class));
    NamedAnalyzer fieldMapperNamedAnalyzer = fieldMapper.fieldType().searchAnalyzer();

    assertThat(fieldMapperNamedAnalyzer.analyzer(), is(namedAnalyzer.analyzer()));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:PreBuiltAnalyzerTests.java


示例10: DocIndexMetaData

import org.elasticsearch.cluster.metadata.IndexMetaData; //导入依赖的package包/类
public DocIndexMetaData(Functions functions, IndexMetaData metaData, TableIdent ident) throws IOException {
    this.functions = functions;
    this.ident = ident;
    this.metaData = metaData;
    this.isAlias = !metaData.getIndex().equals(ident.indexName());
    this.numberOfShards = metaData.getNumberOfShards();
    Settings settings = metaData.getSettings();
    this.numberOfReplicas = NumberOfReplicas.fromSettings(settings);
    this.aliases = ImmutableSet.copyOf(metaData.getAliases().keys().toArray(String.class));
    this.defaultMappingMetaData = this.metaData.mappingOrDefault(Constants.DEFAULT_MAPPING_TYPE);
    if (defaultMappingMetaData == null) {
        this.defaultMappingMap = ImmutableMap.of();
    } else {
        this.defaultMappingMap = this.defaultMappingMetaData.sourceAsMap();
    }
    this.tableParameters = TableParameterInfo.tableParametersFromIndexMetaData(metaData);

    Map<String, Object> metaMap = getNested(defaultMappingMap, "_meta");
    indicesMap = getNested(metaMap, "indices", ImmutableMap.<String, Object>of());
    partitionedByList = getNested(metaMap, "partitioned_by", ImmutableList.<List<String>>of());
    generatedColumns = getNested(metaMap, "generated_columns", ImmutableMap.<String, String>of());
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:23,代码来源:DocIndexMetaData.java


示例11: testRandomRouting

import org.elasticsearch.cluster.metadata.IndexMetaData; //导入依赖的package包/类
public void testRandomRouting() {
    MetaData metaData = MetaData.builder()
            .put(IndexMetaData.builder("test1").settings(settings(Version.CURRENT)).numberOfShards(1).numberOfReplicas(1))
            .put(IndexMetaData.builder("test2").settings(settings(Version.CURRENT)).numberOfShards(1).numberOfReplicas(1))
            .build();

    RoutingTable routingTable = RoutingTable.builder()
            .addAsNew(metaData.index("test1"))
            .addAsNew(metaData.index("test2"))
            .build();

    ShardIterator shardIterator = routingTable.index("test1").shard(0).shardsRandomIt();
    ShardRouting shardRouting1 = shardIterator.nextOrNull();
    assertThat(shardRouting1, notNullValue());
    assertThat(shardIterator.nextOrNull(), notNullValue());
    assertThat(shardIterator.nextOrNull(), nullValue());

    shardIterator = routingTable.index("test1").shard(0).shardsRandomIt();
    ShardRouting shardRouting2 = shardIterator.nextOrNull();
    assertThat(shardRouting2, notNullValue());
    ShardRouting shardRouting3 = shardIterator.nextOrNull();
    assertThat(shardRouting3, notNullValue());
    assertThat(shardIterator.nextOrNull(), nullValue());
    assertThat(shardRouting1, not(sameInstance(shardRouting2)));
    assertThat(shardRouting1, sameInstance(shardRouting3));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:27,代码来源:RoutingIteratorTests.java


示例12: testIndexMetaDataChange

import org.elasticsearch.cluster.metadata.IndexMetaData; //导入依赖的package包/类
/**
 * Test the index metadata change check.
 */
public void testIndexMetaDataChange() {
    final int numNodesInCluster = 3;
    final ClusterState state = createState(numNodesInCluster, randomBoolean(), initialIndices);

    // test when its not the same IndexMetaData
    final Index index = initialIndices.get(0);
    final IndexMetaData originalIndexMeta = state.metaData().index(index);
    // make sure the metadata is actually on the cluster state
    assertNotNull("IndexMetaData for " + index + " should exist on the cluster state", originalIndexMeta);
    IndexMetaData newIndexMeta = createIndexMetadata(index, originalIndexMeta.getVersion() + 1);
    assertTrue("IndexMetaData with different version numbers must be considered changed",
        ClusterChangedEvent.indexMetaDataChanged(originalIndexMeta, newIndexMeta));

    // test when it doesn't exist
    newIndexMeta = createIndexMetadata(new Index("doesntexist", UUIDs.randomBase64UUID()));
    assertTrue("IndexMetaData that didn't previously exist should be considered changed",
        ClusterChangedEvent.indexMetaDataChanged(originalIndexMeta, newIndexMeta));

    // test when its the same IndexMetaData
    assertFalse("IndexMetaData should be the same", ClusterChangedEvent.indexMetaDataChanged(originalIndexMeta, originalIndexMeta));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:25,代码来源:ClusterChangedEventTests.java


示例13: testUpgradeCustomDataPath

import org.elasticsearch.cluster.metadata.IndexMetaData; //导入依赖的package包/类
/**
 * tests custom data paths are upgraded
 */
public void testUpgradeCustomDataPath() throws IOException {
    Path customPath = createTempDir();
    final Settings nodeSettings = Settings.builder()
        .put(NodeEnvironment.ADD_NODE_LOCK_ID_TO_CUSTOM_PATH.getKey(), randomBoolean())
        .put(Environment.PATH_SHARED_DATA_SETTING.getKey(), customPath.toAbsolutePath().toString()).build();
    try (NodeEnvironment nodeEnv = newNodeEnvironment(nodeSettings)) {
        final Index index = new Index(randomAsciiOfLength(10), UUIDs.randomBase64UUID());
        Settings settings = Settings.builder()
            .put(nodeSettings)
            .put(IndexMetaData.SETTING_INDEX_UUID, index.getUUID())
            .put(IndexMetaData.SETTING_VERSION_CREATED, Version.V_2_0_0)
            .put(IndexMetaData.SETTING_DATA_PATH, customPath.toAbsolutePath().toString())
            .put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, randomIntBetween(1, 5))
            .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
            .build();
        IndexMetaData indexState = IndexMetaData.builder(index.getName()).settings(settings).build();
        int numIdxFiles = randomIntBetween(1, 5);
        int numTranslogFiles = randomIntBetween(1, 5);
        IndexSettings indexSettings = new IndexSettings(indexState, nodeSettings);
        writeIndex(nodeEnv, indexSettings, numIdxFiles, numTranslogFiles);
        IndexFolderUpgrader helper = new IndexFolderUpgrader(settings, nodeEnv);
        helper.upgrade(indexSettings.getIndex().getName());
        checkIndex(nodeEnv, indexSettings, numIdxFiles, numTranslogFiles);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:29,代码来源:IndexFolderUpgraderTests.java


示例14: writeIndex

import org.elasticsearch.cluster.metadata.IndexMetaData; //导入依赖的package包/类
private void writeIndex(NodeEnvironment nodeEnv, IndexSettings indexSettings,
                        int numIdxFiles, int numTranslogFiles) throws IOException {
    NodeEnvironment.NodePath[] nodePaths = nodeEnv.nodePaths();
    Path[] oldIndexPaths = new Path[nodePaths.length];
    for (int i = 0; i < nodePaths.length; i++) {
        oldIndexPaths[i] = nodePaths[i].indicesPath.resolve(indexSettings.getIndex().getName());
    }
    IndexMetaData.FORMAT.write(indexSettings.getIndexMetaData(), oldIndexPaths);
    for (int id = 0; id < indexSettings.getNumberOfShards(); id++) {
        Path oldIndexPath = randomFrom(oldIndexPaths);
        ShardId shardId = new ShardId(indexSettings.getIndex(), id);
        if (indexSettings.hasCustomDataPath()) {
            Path customIndexPath = nodeEnv.resolveBaseCustomLocation(indexSettings).resolve(indexSettings.getIndex().getName());
            writeShard(shardId, customIndexPath, numIdxFiles, numTranslogFiles);
        } else {
            writeShard(shardId, oldIndexPath, numIdxFiles, numTranslogFiles);
        }
        ShardStateMetaData state = new ShardStateMetaData(true, indexSettings.getUUID(), AllocationId.newInitializing());
        ShardStateMetaData.FORMAT.write(state, oldIndexPath.resolve(String.valueOf(shardId.getId())));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:IndexFolderUpgraderTests.java


示例15: getRelevantIndicesOnDataOnlyNode

import org.elasticsearch.cluster.metadata.IndexMetaData; //导入依赖的package包/类
public static Set<Index> getRelevantIndicesOnDataOnlyNode(ClusterState state, ClusterState previousState, Set<Index> previouslyWrittenIndices) {
    RoutingNode newRoutingNode = state.getRoutingNodes().node(state.nodes().getLocalNodeId());
    if (newRoutingNode == null) {
        throw new IllegalStateException("cluster state does not contain this node - cannot write index meta state");
    }
    Set<Index> indices = new HashSet<>();
    for (ShardRouting routing : newRoutingNode) {
        indices.add(routing.index());
    }
    // we have to check the meta data also: closed indices will not appear in the routing table, but we must still write the state if we have it written on disk previously
    for (IndexMetaData indexMetaData : state.metaData()) {
        boolean isOrWasClosed = indexMetaData.getState().equals(IndexMetaData.State.CLOSE);
        // if the index is open we might still have to write the state if it just transitioned from closed to open
        // so we have to check for that as well.
        IndexMetaData previousMetaData = previousState.metaData().index(indexMetaData.getIndex());
        if (previousMetaData != null) {
            isOrWasClosed = isOrWasClosed || previousMetaData.getState().equals(IndexMetaData.State.CLOSE);
        }
        if (previouslyWrittenIndices.contains(indexMetaData.getIndex()) && isOrWasClosed) {
            indices.add(indexMetaData.getIndex());
        }
    }
    return indices;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:25,代码来源:GatewayMetaState.java


示例16: canDeleteShardContent

import org.elasticsearch.cluster.metadata.IndexMetaData; //导入依赖的package包/类
private boolean canDeleteShardContent(ShardId shardId, Settings indexSettings) {
    final IndexServiceInjectorPair indexServiceInjectorPair = this.indices.get(shardId.getIndex());
    if (IndexMetaData.isOnSharedFilesystem(indexSettings) == false) {
         if (nodeEnv.hasNodeFile()) {
            boolean isAllocated = indexServiceInjectorPair != null && indexServiceInjectorPair
                .getIndexService().hasShard(shardId.getId());
            if (isAllocated) {
                return false; // we are allocated - can't delete the shard
            }
            if (NodeEnvironment.hasCustomDataPath(indexSettings)) {
                // lets see if it's on a custom path (return false if the shared doesn't exist)
                // we don't need to delete anything that is not there
                return Files.exists(nodeEnv.resolveCustomLocation(indexSettings, shardId));
            } else {
                // lets see if it's path is available (return false if the shared doesn't exist)
                // we don't need to delete anything that is not there
                return FileSystemUtils.exists(nodeEnv.availableShardPaths(shardId));
            }
        }
    } else {
        logger.trace("{} skipping shard directory deletion due to shadow replicas", shardId);
    }
    return false;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:25,代码来源:IndicesService.java


示例17: getIndexMetaData

import org.elasticsearch.cluster.metadata.IndexMetaData; //导入依赖的package包/类
private IndexMetaData getIndexMetaData(String indexName) {
  AliasOrIndex aliasOrIndex = elasticsearchTemplate.getClient()
      .admin()
      .cluster()
      .state(Requests.clusterStateRequest())
      .actionGet()
      .getState()
      .getMetaData()
      .getAliasAndIndexLookup()
      .get(indexName);
  if (aliasOrIndex == null) {
    return null;
  }

  return aliasOrIndex.getIndices().get(0);
}
 
开发者ID:pukkaone,项目名称:odata-spring-boot-starter,代码行数:17,代码来源:ElasticsearchEdmProviderResolver.java


示例18: deleteShardStore

import org.elasticsearch.cluster.metadata.IndexMetaData; //导入依赖的package包/类
/**
 * This method deletes the shard contents on disk for the given shard ID. This method will fail if the shard deleting
 * is prevented by {@link #canDeleteShardContent(org.elasticsearch.index.shard.ShardId, org.elasticsearch.cluster.metadata.IndexMetaData)}
 * of if the shards lock can not be acquired.
 *
 * On data nodes, if the deleted shard is the last shard folder in its index, the method will attempt to remove the index folder as well.
 *
 * @param reason the reason for the shard deletion
 * @param shardId the shards ID to delete
 * @param clusterState . This is required to access the indexes settings etc.
 * @throws IOException if an IOException occurs
 */
public void deleteShardStore(String reason, ShardId shardId, ClusterState clusterState) throws IOException {
    final IndexMetaData metaData = clusterState.getMetaData().indices().get(shardId.getIndex());

    final Settings indexSettings = buildIndexSettings(metaData);
    if (canDeleteShardContent(shardId, indexSettings) == false) {
        throw new IllegalStateException("Can't delete shard " + shardId);
    }
    nodeEnv.deleteShardDirectorySafe(shardId, indexSettings);
    logger.debug("{} deleted shard reason [{}]", shardId, reason);

    if (clusterState.nodes().localNode().isMasterNode() == false && // master nodes keep the index meta data, even if having no shards..
            canDeleteIndexContents(shardId.index(), indexSettings, false)) {
        if (nodeEnv.findAllShardIds(shardId.index()).isEmpty()) {
            try {
                // note that deleteIndexStore have more safety checks and may throw an exception if index was concurrently created.
                deleteIndexStore("no longer used", metaData, clusterState, false);
            } catch (Exception e) {
                // wrap the exception to indicate we already deleted the shard
                throw new ElasticsearchException("failed to delete unused index after deleting its last shard (" + shardId + ")", e);
            }
        } else {
            logger.trace("[{}] still has shard stores, leaving as is", shardId.index());
        }
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:38,代码来源:IndicesService.java


示例19: updateActiveAllocations

import org.elasticsearch.cluster.metadata.IndexMetaData; //导入依赖的package包/类
/** reverse engineer the in sync aid based on the given indexRoutingTable **/
public static IndexMetaData updateActiveAllocations(IndexRoutingTable indexRoutingTable, IndexMetaData indexMetaData) {
    IndexMetaData.Builder imdBuilder = IndexMetaData.builder(indexMetaData);
    for (IndexShardRoutingTable shardTable : indexRoutingTable) {
        for (ShardRouting shardRouting : shardTable) {
            Set<String> insyncAids = shardTable.activeShards().stream().map(
                shr -> shr.allocationId().getId()).collect(Collectors.toSet());
            final ShardRouting primaryShard = shardTable.primaryShard();
            if (primaryShard.initializing() && primaryShard.relocating() == false &&
                RecoverySource.isInitialRecovery(primaryShard.recoverySource().getType()) == false ) {
                // simulate a primary was initialized based on aid
                insyncAids.add(primaryShard.allocationId().getId());
            }
            imdBuilder.putInSyncAllocationIds(shardRouting.id(), insyncAids);
        }
    }
    return imdBuilder.build();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:19,代码来源:RoutingTableTests.java


示例20: testIndicesStatsWithBlocks

import org.elasticsearch.cluster.metadata.IndexMetaData; //导入依赖的package包/类
public void testIndicesStatsWithBlocks() {
    createIndex("ro");
    ensureGreen("ro");

    // Request is not blocked
    for (String blockSetting : Arrays.asList(SETTING_BLOCKS_READ, SETTING_BLOCKS_WRITE, SETTING_READ_ONLY)) {
        try {
            enableIndexBlock("ro", blockSetting);
            IndicesStatsResponse indicesStatsResponse = client().admin().indices().prepareStats("ro").execute().actionGet();
            assertNotNull(indicesStatsResponse.getIndex("ro"));
        } finally {
            disableIndexBlock("ro", blockSetting);
        }
    }

    // Request is blocked
    try {
        enableIndexBlock("ro", IndexMetaData.SETTING_BLOCKS_METADATA);
        client().admin().indices().prepareStats("ro").execute().actionGet();
        fail("Exists should fail when " + IndexMetaData.SETTING_BLOCKS_METADATA + " is true");
    } catch (ClusterBlockException e) {
        // Ok, a ClusterBlockException is expected
    } finally {
        disableIndexBlock("ro", IndexMetaData.SETTING_BLOCKS_METADATA);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:27,代码来源:IndicesStatsBlocksIT.java



注:本文中的org.elasticsearch.cluster.metadata.IndexMetaData类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java RpcConfig类代码示例发布时间:2022-05-16
下一篇:
Java WindowInsetsCompat类代码示例发布时间:2022-05-20
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap