Search in sources :

Example 61 with IndexMetadata

use of org.elasticsearch.cluster.metadata.IndexMetadata in project elasticsearch by elastic.

the class TransportShardBulkActionTests method testExecuteBulkIndexRequestWithRejection.

public void testExecuteBulkIndexRequestWithRejection() throws Exception {
    IndexMetaData metaData = indexMetaData();
    IndexShard shard = newStartedShard(true);
    BulkItemRequest[] items = new BulkItemRequest[1];
    DocWriteRequest writeRequest = new IndexRequest("index", "type", "id").source(Requests.INDEX_CONTENT_TYPE, "foo", "bar");
    items[0] = new BulkItemRequest(0, writeRequest);
    BulkShardRequest bulkShardRequest = new BulkShardRequest(shardId, RefreshPolicy.NONE, items);
    Translog.Location location = new Translog.Location(0, 0, 0);
    UpdateHelper updateHelper = null;
    // Pretend the mappings haven't made it to the node yet, and throw  a rejection
    Exception err = new ReplicationOperation.RetryOnPrimaryException(shardId, "rejection");
    try {
        TransportShardBulkAction.executeBulkItemRequest(metaData, shard, bulkShardRequest, location, 0, updateHelper, threadPool::absoluteTimeInMillis, new ThrowingMappingUpdatePerformer(err));
        fail("should have thrown a retry exception");
    } catch (ReplicationOperation.RetryOnPrimaryException e) {
        assertThat(e, equalTo(err));
    }
    closeShards(shard);
}
Also used : IndexShard(org.elasticsearch.index.shard.IndexShard) IndexRequest(org.elasticsearch.action.index.IndexRequest) ElasticsearchException(org.elasticsearch.ElasticsearchException) VersionConflictEngineException(org.elasticsearch.index.engine.VersionConflictEngineException) IOException(java.io.IOException) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) Translog(org.elasticsearch.index.translog.Translog) UpdateHelper(org.elasticsearch.action.update.UpdateHelper) DocWriteRequest(org.elasticsearch.action.DocWriteRequest) ReplicationOperation(org.elasticsearch.action.support.replication.ReplicationOperation)

Example 62 with IndexMetadata

use of org.elasticsearch.cluster.metadata.IndexMetadata in project elasticsearch by elastic.

the class RolloverIT method testRolloverWithIndexSettings.

public void testRolloverWithIndexSettings() throws Exception {
    assertAcked(prepareCreate("test_index-2").addAlias(new Alias("test_alias")).get());
    index("test_index-2", "type1", "1", "field", "value");
    flush("test_index-2");
    final Settings settings = Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1).put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0).build();
    final RolloverResponse response = client().admin().indices().prepareRolloverIndex("test_alias").settings(settings).alias(new Alias("extra_alias")).get();
    assertThat(response.getOldIndex(), equalTo("test_index-2"));
    assertThat(response.getNewIndex(), equalTo("test_index-000003"));
    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-2");
    assertFalse(oldIndex.getAliases().containsKey("test_alias"));
    final IndexMetaData newIndex = state.metaData().index("test_index-000003");
    assertThat(newIndex.getNumberOfShards(), equalTo(1));
    assertThat(newIndex.getNumberOfReplicas(), equalTo(0));
    assertTrue(newIndex.getAliases().containsKey("test_alias"));
    assertTrue(newIndex.getAliases().containsKey("extra_alias"));
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) Alias(org.elasticsearch.action.admin.indices.alias.Alias) Settings(org.elasticsearch.common.settings.Settings) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Example 63 with IndexMetadata

use of org.elasticsearch.cluster.metadata.IndexMetadata in project elasticsearch by elastic.

the class TransportRolloverActionTests method testEvaluateConditions.

public void testEvaluateConditions() throws Exception {
    MaxDocsCondition maxDocsCondition = new MaxDocsCondition(100L);
    MaxAgeCondition maxAgeCondition = new MaxAgeCondition(TimeValue.timeValueHours(2));
    long matchMaxDocs = randomIntBetween(100, 1000);
    long notMatchMaxDocs = randomIntBetween(0, 99);
    final Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).put(IndexMetaData.SETTING_INDEX_UUID, UUIDs.randomBase64UUID()).put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1).put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0).build();
    final IndexMetaData metaData = IndexMetaData.builder(randomAsciiOfLength(10)).creationDate(System.currentTimeMillis() - TimeValue.timeValueHours(3).getMillis()).settings(settings).build();
    final HashSet<Condition> conditions = Sets.newHashSet(maxDocsCondition, maxAgeCondition);
    Set<Condition.Result> results = evaluateConditions(conditions, new DocsStats(matchMaxDocs, 0L), metaData);
    assertThat(results.size(), equalTo(2));
    for (Condition.Result result : results) {
        assertThat(result.matched, equalTo(true));
    }
    results = evaluateConditions(conditions, new DocsStats(notMatchMaxDocs, 0), metaData);
    assertThat(results.size(), equalTo(2));
    for (Condition.Result result : results) {
        if (result.condition instanceof MaxAgeCondition) {
            assertThat(result.matched, equalTo(true));
        } else if (result.condition instanceof MaxDocsCondition) {
            assertThat(result.matched, equalTo(false));
        } else {
            fail("unknown condition result found " + result.condition);
        }
    }
    results = evaluateConditions(conditions, null, metaData);
    assertThat(results.size(), equalTo(2));
    for (Condition.Result result : results) {
        if (result.condition instanceof MaxAgeCondition) {
            assertThat(result.matched, equalTo(true));
        } else if (result.condition instanceof MaxDocsCondition) {
            assertThat(result.matched, equalTo(false));
        } else {
            fail("unknown condition result found " + result.condition);
        }
    }
}
Also used : DocsStats(org.elasticsearch.index.shard.DocsStats) Settings(org.elasticsearch.common.settings.Settings) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Example 64 with IndexMetadata

use of org.elasticsearch.cluster.metadata.IndexMetadata in project elasticsearch by elastic.

the class RolloverIT method testRolloverDryRun.

public void testRolloverDryRun() throws Exception {
    assertAcked(prepareCreate("test_index-1").addAlias(new Alias("test_alias")).get());
    index("test_index-1", "type1", "1", "field", "value");
    flush("test_index-1");
    final RolloverResponse response = client().admin().indices().prepareRolloverIndex("test_alias").dryRun(true).get();
    assertThat(response.getOldIndex(), equalTo("test_index-1"));
    assertThat(response.getNewIndex(), equalTo("test_index-000002"));
    assertThat(response.isDryRun(), equalTo(true));
    assertThat(response.isRolledOver(), equalTo(false));
    assertThat(response.getConditionStatus().size(), equalTo(0));
    final ClusterState state = client().admin().cluster().prepareState().get().getState();
    final IndexMetaData oldIndex = state.metaData().index("test_index-1");
    assertTrue(oldIndex.getAliases().containsKey("test_alias"));
    final IndexMetaData newIndex = state.metaData().index("test_index-000002");
    assertNull(newIndex);
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) Alias(org.elasticsearch.action.admin.indices.alias.Alias) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Example 65 with IndexMetadata

use of org.elasticsearch.cluster.metadata.IndexMetadata in project elasticsearch by elastic.

the class RolloverIT method testRolloverConditionsNotMet.

public void testRolloverConditionsNotMet() throws Exception {
    assertAcked(prepareCreate("test_index-0").addAlias(new Alias("test_alias")).get());
    index("test_index-0", "type1", "1", "field", "value");
    flush("test_index-0");
    final RolloverResponse response = client().admin().indices().prepareRolloverIndex("test_alias").addMaxIndexAgeCondition(TimeValue.timeValueHours(4)).get();
    assertThat(response.getOldIndex(), equalTo("test_index-0"));
    assertThat(response.getNewIndex(), equalTo("test_index-000001"));
    assertThat(response.isDryRun(), equalTo(false));
    assertThat(response.isRolledOver(), equalTo(false));
    assertThat(response.getConditionStatus().size(), equalTo(1));
    final Map.Entry<String, Boolean> conditionEntry = response.getConditionStatus().iterator().next();
    assertThat(conditionEntry.getKey(), equalTo(new MaxAgeCondition(TimeValue.timeValueHours(4)).toString()));
    assertThat(conditionEntry.getValue(), equalTo(false));
    final ClusterState state = client().admin().cluster().prepareState().get().getState();
    final IndexMetaData oldIndex = state.metaData().index("test_index-0");
    assertTrue(oldIndex.getAliases().containsKey("test_alias"));
    final IndexMetaData newIndex = state.metaData().index("test_index-000001");
    assertNull(newIndex);
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) Alias(org.elasticsearch.action.admin.indices.alias.Alias) Map(java.util.Map) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Aggregations

IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)253 IndexMetadata (org.elasticsearch.cluster.metadata.IndexMetadata)194 ClusterState (org.elasticsearch.cluster.ClusterState)124 Settings (org.elasticsearch.common.settings.Settings)104 Index (org.elasticsearch.index.Index)100 Test (org.junit.Test)90 ShardId (org.elasticsearch.index.shard.ShardId)71 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)68 IOException (java.io.IOException)65 Metadata (org.elasticsearch.cluster.metadata.Metadata)62 IndexSettings (org.elasticsearch.index.IndexSettings)62 RoutingTable (org.elasticsearch.cluster.routing.RoutingTable)60 MetaData (org.elasticsearch.cluster.metadata.MetaData)58 HashSet (java.util.HashSet)56 HashMap (java.util.HashMap)54 IndexShardRoutingTable (org.elasticsearch.cluster.routing.IndexShardRoutingTable)54 Map (java.util.Map)50 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)49 ArrayList (java.util.ArrayList)47 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)44