Java Code Examples for org.elasticsearch.cluster.metadata.IndexMetaData#getIndexUUID()

The following examples show how to use org.elasticsearch.cluster.metadata.IndexMetaData#getIndexUUID() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IndicesService.java    From crate with Apache License 2.0 6 votes vote down vote up
/**
 * Deletes an index that is not assigned to this node. This method cleans up all disk folders relating to the index
 * but does not deal with in-memory structures. For those call {@link #removeIndex(Index, IndexRemovalReason, String)}
 */
@Override
public void deleteUnassignedIndex(String reason, IndexMetaData metaData, ClusterState clusterState) {
    if (nodeEnv.hasNodeFile()) {
        String indexName = metaData.getIndex().getName();
        try {
            if (clusterState.metaData().hasIndex(indexName)) {
                final IndexMetaData index = clusterState.metaData().index(indexName);
                throw new IllegalStateException("Can't delete unassigned index store for [" + indexName + "] - it's still part of " +
                                                "the cluster state [" + index.getIndexUUID() + "] [" + metaData.getIndexUUID() + "]");
            }
            deleteIndexStore(reason, metaData, clusterState);
        } catch (Exception e) {
            LOGGER.warn(() -> new ParameterizedMessage("[{}] failed to delete unassigned index (reason [{}])", metaData.getIndex(), reason), e);
        }
    }
}
 
Example 2
Source File: IndicesService.java    From crate with Apache License 2.0 6 votes vote down vote up
/**
 * Deletes the index store trying to acquire all shards locks for this index.
 * This method will delete the metadata for the index even if the actual shards can't be locked.
 *
 * Package private for testing
 */
void deleteIndexStore(String reason, IndexMetaData metaData, ClusterState clusterState) throws IOException {
    if (nodeEnv.hasNodeFile()) {
        synchronized (this) {
            Index index = metaData.getIndex();
            if (hasIndex(index)) {
                String localUUid = indexService(index).indexUUID();
                throw new IllegalStateException("Can't delete index store for [" + index.getName() + "] - it's still part of the indices service [" + localUUid + "] [" + metaData.getIndexUUID() + "]");
            }

            if (clusterState.metaData().hasIndex(index.getName()) && (clusterState.nodes().getLocalNode().isMasterNode() == true)) {
                // we do not delete the store if it is a master eligible node and the index is still in the cluster state
                // because we want to keep the meta data for indices around even if no shards are left here
                final IndexMetaData idxMeta = clusterState.metaData().index(index.getName());
                throw new IllegalStateException("Can't delete index store for [" + index.getName() + "] - it's still part of the " +
                                                "cluster state [" + idxMeta.getIndexUUID() + "] [" + metaData.getIndexUUID() + "], " +
                                                "we are master eligible, so will keep the index metadata even if no shards are left.");
            }
        }
        final IndexSettings indexSettings = buildIndexSettings(metaData);
        deleteIndexStore(reason, indexSettings.getIndex(), indexSettings);
    }
}
 
Example 3
Source File: IndicesService.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public void deleteClosedIndex(String reason, IndexMetaData metaData, ClusterState clusterState) {
    if (nodeEnv.hasNodeFile()) {
        String indexName = metaData.getIndex();
        try {
            if (clusterState.metaData().hasIndex(indexName)) {
                final IndexMetaData index = clusterState.metaData().index(indexName);
                throw new IllegalStateException("Can't delete closed index store for [" + indexName + "] - it's still part of the cluster state [" + index.getIndexUUID() + "] [" + metaData.getIndexUUID() + "]");
            }
            deleteIndexStore(reason, metaData, clusterState, true);
        } catch (IOException e) {
            logger.warn("[{}] failed to delete closed index", e, metaData.getIndex());
        }
    }
}
 
Example 4
Source File: IndicesService.java    From crate with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new {@link IndexService} for the given metadata.
 *
 * @param indexMetaData          the index metadata to create the index for
 * @param builtInListeners       a list of built-in lifecycle {@link IndexEventListener} that should should be used along side with the
 *                               per-index listeners
 * @throws ResourceAlreadyExistsException if the index already exists.
 */
@Override
public synchronized IndexService createIndex(
        final IndexMetaData indexMetaData, final List<IndexEventListener> builtInListeners) throws IOException {
    ensureChangesAllowed();
    if (indexMetaData.getIndexUUID().equals(IndexMetaData.INDEX_UUID_NA_VALUE)) {
        throw new IllegalArgumentException("index must have a real UUID found value: [" + indexMetaData.getIndexUUID() + "]");
    }
    final Index index = indexMetaData.getIndex();
    if (hasIndex(index)) {
        throw new ResourceAlreadyExistsException(index);
    }
    List<IndexEventListener> finalListeners = new ArrayList<>(builtInListeners);
    final IndexEventListener onStoreClose = new IndexEventListener() {
        @Override
        public void onStoreClosed(ShardId shardId) {
            indicesQueryCache.onClose(shardId);
        }
    };
    finalListeners.add(onStoreClose);
    final IndexService indexService = createIndexService(
        "create index",
        indexMetaData,
        indicesQueryCache,
        finalListeners,
        indexingMemoryController
    );
    boolean success = false;
    try {
        indexService.getIndexEventListener().afterIndexCreated(indexService);
        indices = newMapBuilder(indices).put(index.getUUID(), indexService).immutableMap();
        success = true;
        return indexService;
    } finally {
        if (success == false) {
            indexService.close("plugins_failed", true);
        }
    }
}
 
Example 5
Source File: SysShardsTest.java    From crate with Apache License 2.0 5 votes vote down vote up
@Test
public void testPathAndBlobPath() throws Exception {
    Path blobs = createTempDir("blobs");
    execute("create table t1 (x int) clustered into 1 shards with (number_of_replicas = 0)");
    execute("create blob table b1 clustered into 1 shards with (number_of_replicas = 0)");
    execute("create blob table b2 " +
            "clustered into 1 shards with (number_of_replicas = 0, blobs_path = '" + blobs.toString() + "')");
    ensureYellow();

    execute("select path, blob_path from sys.shards where table_name in ('t1', 'b1', 'b2') " +
            "order by table_name asc");
    // b1
    // path + /blobs == blob_path without custom blob path
    assertThat(response.rows()[0][0] + resolveCanonicalString("/blobs"), is(response.rows()[0][1]));

    ClusterService clusterService = internalCluster().getInstance(ClusterService.class);
    MetaData metaData = clusterService.state().getMetaData();
    IndexMetaData index = metaData.index(".blob_b2");
    String indexUUID = index.getIndexUUID();

    // b2
    String b2Path = (String) response.rows()[1][0];
    assertThat(b2Path, containsString(resolveCanonicalString("/nodes/")));
    assertThat(b2Path, endsWith(resolveCanonicalString("/indices/" + indexUUID + "/0")));

    String b2BlobPath = (String) response.rows()[1][1];
    assertThat(b2BlobPath, containsString(resolveCanonicalString("/nodes/")));
    assertThat(b2BlobPath, endsWith(resolveCanonicalString("/indices/" + indexUUID + "/0/blobs")));
    // t1
    assertThat(response.rows()[2][1], nullValue());
}