Search in sources :

Example 16 with ShardPath

use of org.elasticsearch.index.shard.ShardPath in project elasticsearch by elastic.

the class IndicesServiceTests method testPendingTasks.

public void testPendingTasks() throws Exception {
    IndicesService indicesService = getIndicesService();
    IndexService test = createIndex("test");
    assertTrue(test.hasShard(0));
    ShardPath path = test.getShardOrNull(0).shardPath();
    assertTrue(test.getShardOrNull(0).routingEntry().started());
    ShardPath shardPath = ShardPath.loadShardPath(logger, getNodeEnvironment(), new ShardId(test.index(), 0), test.getIndexSettings());
    assertEquals(shardPath, path);
    try {
        indicesService.processPendingDeletes(test.index(), test.getIndexSettings(), new TimeValue(0, TimeUnit.MILLISECONDS));
        fail("can't get lock");
    } catch (ShardLockObtainFailedException ex) {
    }
    assertTrue(path.exists());
    int numPending = 1;
    if (randomBoolean()) {
        indicesService.addPendingDelete(new ShardId(test.index(), 0), test.getIndexSettings());
    } else {
        if (randomBoolean()) {
            numPending++;
            indicesService.addPendingDelete(new ShardId(test.index(), 0), test.getIndexSettings());
        }
        indicesService.addPendingDelete(test.index(), test.getIndexSettings());
    }
    assertAcked(client().admin().indices().prepareClose("test"));
    assertTrue(path.exists());
    assertEquals(indicesService.numPendingDeletes(test.index()), numPending);
    assertTrue(indicesService.hasUncompletedPendingDeletes());
    // shard lock released... we can now delete
    indicesService.processPendingDeletes(test.index(), test.getIndexSettings(), new TimeValue(0, TimeUnit.MILLISECONDS));
    assertEquals(indicesService.numPendingDeletes(test.index()), 0);
    assertFalse(indicesService.hasUncompletedPendingDeletes());
    assertFalse(path.exists());
    if (randomBoolean()) {
        indicesService.addPendingDelete(new ShardId(test.index(), 0), test.getIndexSettings());
        indicesService.addPendingDelete(new ShardId(test.index(), 1), test.getIndexSettings());
        indicesService.addPendingDelete(new ShardId("bogus", "_na_", 1), test.getIndexSettings());
        assertEquals(indicesService.numPendingDeletes(test.index()), 2);
        assertTrue(indicesService.hasUncompletedPendingDeletes());
        // shard lock released... we can now delete
        indicesService.processPendingDeletes(test.index(), test.getIndexSettings(), new TimeValue(0, TimeUnit.MILLISECONDS));
        assertEquals(indicesService.numPendingDeletes(test.index()), 0);
        // "bogus" index has not been removed
        assertTrue(indicesService.hasUncompletedPendingDeletes());
    }
    assertAcked(client().admin().indices().prepareOpen("test"));
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) IndexService(org.elasticsearch.index.IndexService) ShardPath(org.elasticsearch.index.shard.ShardPath) ShardLockObtainFailedException(org.elasticsearch.env.ShardLockObtainFailedException) TimeValue(org.elasticsearch.common.unit.TimeValue)

Example 17 with ShardPath

use of org.elasticsearch.index.shard.ShardPath in project elasticsearch by elastic.

the class IndicesServiceTests method testDeleteIndexStore.

public void testDeleteIndexStore() throws Exception {
    IndicesService indicesService = getIndicesService();
    IndexService test = createIndex("test");
    ClusterService clusterService = getInstanceFromNode(ClusterService.class);
    IndexMetaData firstMetaData = clusterService.state().metaData().index("test");
    assertTrue(test.hasShard(0));
    try {
        indicesService.deleteIndexStore("boom", firstMetaData, clusterService.state());
        fail();
    } catch (IllegalStateException ex) {
    // all good
    }
    GatewayMetaState gwMetaState = getInstanceFromNode(GatewayMetaState.class);
    MetaData meta = gwMetaState.loadMetaState();
    assertNotNull(meta);
    assertNotNull(meta.index("test"));
    assertAcked(client().admin().indices().prepareDelete("test"));
    meta = gwMetaState.loadMetaState();
    assertNotNull(meta);
    assertNull(meta.index("test"));
    test = createIndex("test");
    client().prepareIndex("test", "type", "1").setSource("field", "value").setRefreshPolicy(IMMEDIATE).get();
    client().admin().indices().prepareFlush("test").get();
    assertHitCount(client().prepareSearch("test").get(), 1);
    IndexMetaData secondMetaData = clusterService.state().metaData().index("test");
    assertAcked(client().admin().indices().prepareClose("test"));
    ShardPath path = ShardPath.loadShardPath(logger, getNodeEnvironment(), new ShardId(test.index(), 0), test.getIndexSettings());
    assertTrue(path.exists());
    try {
        indicesService.deleteIndexStore("boom", secondMetaData, clusterService.state());
        fail();
    } catch (IllegalStateException ex) {
    // all good
    }
    assertTrue(path.exists());
    // now delete the old one and make sure we resolve against the name
    try {
        indicesService.deleteIndexStore("boom", firstMetaData, clusterService.state());
        fail();
    } catch (IllegalStateException ex) {
    // all good
    }
    assertAcked(client().admin().indices().prepareOpen("test"));
    ensureGreen("test");
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) ClusterService(org.elasticsearch.cluster.service.ClusterService) IndexService(org.elasticsearch.index.IndexService) ShardPath(org.elasticsearch.index.shard.ShardPath) MetaData(org.elasticsearch.cluster.metadata.MetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) GatewayMetaState(org.elasticsearch.gateway.GatewayMetaState)

Aggregations

ShardPath (org.elasticsearch.index.shard.ShardPath)17 ShardId (org.elasticsearch.index.shard.ShardId)14 Path (java.nio.file.Path)12 IndexSettings (org.elasticsearch.index.IndexSettings)7 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)6 Settings (org.elasticsearch.common.settings.Settings)5 Index (org.elasticsearch.index.Index)5 Directory (org.apache.lucene.store.Directory)4 MMapDirectory (org.apache.lucene.store.MMapDirectory)4 SimpleFSDirectory (org.apache.lucene.store.SimpleFSDirectory)4 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)4 FileSwitchDirectory (org.apache.lucene.store.FileSwitchDirectory)3 SleepingLockWrapper (org.apache.lucene.store.SleepingLockWrapper)3 TimeValue (org.elasticsearch.common.unit.TimeValue)3 IndexService (org.elasticsearch.index.IndexService)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 ParameterizedMessage (org.apache.logging.log4j.message.ParameterizedMessage)2 Supplier (org.apache.logging.log4j.util.Supplier)2