Skip to content

Commit

Permalink
Local Gateway: Move shard state to be stored under each shard, and no…
Browse files Browse the repository at this point in the history
…t globally under _state, closes #1618.
  • Loading branch information
kimchy committed Jan 17, 2012
1 parent 801c709 commit 534f487
Show file tree
Hide file tree
Showing 9 changed files with 568 additions and 435 deletions.
32 changes: 32 additions & 0 deletions src/main/java/org/elasticsearch/env/NodeEnvironment.java
Expand Up @@ -19,6 +19,7 @@

package org.elasticsearch.env;

import com.google.common.collect.Sets;
import org.apache.lucene.store.Lock;
import org.apache.lucene.store.NativeFSLockFactory;
import org.elasticsearch.ElasticSearchIllegalStateException;
Expand All @@ -34,6 +35,7 @@
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.Set;

/**
*
Expand Down Expand Up @@ -175,6 +177,36 @@ public File[] shardLocations(ShardId shardId) {
return shardLocations;
}

public Set<ShardId> findAllShardIds() throws Exception {
if (nodeFiles == null || locks == null) {
throw new ElasticSearchIllegalStateException("node is not configured to store local location");
}
Set<ShardId> shardIds = Sets.newHashSet();
for (File indicesLocation : nodeIndicesLocations) {
File[] indicesList = indicesLocation.listFiles();
if (indicesList == null) {
continue;
}
for (File indexLocation : indicesList) {
if (!indexLocation.isDirectory()) {
continue;
}
String indexName = indexLocation.getName();
File[] shardsList = indexLocation.listFiles();
if (shardsList == null) {
continue;
}
for (File shardLocation : shardsList) {
if (!shardLocation.isDirectory()) {
continue;
}
shardIds.add(new ShardId(indexName, Integer.parseInt(shardLocation.getName())));
}
}
}
return shardIds;
}

public void close() {
if (locks != null) {
for (Lock lock : locks) {
Expand Down

0 comments on commit 534f487

Please sign in to comment.