automatically clean indices that no longer exists in the metadata, this can happen if we delete a closed index, or when a node joins a cluster, that no longer has those indices
This commit is contained in:
parent
897587f981
commit
bba7179eeb
|
@ -105,8 +105,12 @@ public class NodeEnvironment extends AbstractComponent {
|
|||
return nodeFile;
|
||||
}
|
||||
|
||||
public File indicesLocation() {
|
||||
return new File(nodeDataLocation(), "indices");
|
||||
}
|
||||
|
||||
public File indexLocation(Index index) {
|
||||
return new File(new File(nodeDataLocation(), "indices"), index.name());
|
||||
return new File(indicesLocation(), index.name());
|
||||
}
|
||||
|
||||
public File shardLocation(ShardId shardId) {
|
||||
|
|
|
@ -28,21 +28,28 @@ import org.elasticsearch.cluster.routing.RoutingTable;
|
|||
import org.elasticsearch.cluster.routing.ShardRoutingState;
|
||||
import org.elasticsearch.common.component.AbstractComponent;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.io.FileSystemUtils;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.env.NodeEnvironment;
|
||||
import org.elasticsearch.index.service.IndexService;
|
||||
import org.elasticsearch.indices.IndicesService;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* @author kimchy (shay.banon)
|
||||
*/
|
||||
public class IndicesStore extends AbstractComponent implements ClusterStateListener {
|
||||
|
||||
private final NodeEnvironment nodeEnv;
|
||||
|
||||
private final IndicesService indicesService;
|
||||
|
||||
private final ClusterService clusterService;
|
||||
|
||||
@Inject public IndicesStore(Settings settings, IndicesService indicesService, ClusterService clusterService) {
|
||||
@Inject public IndicesStore(Settings settings, NodeEnvironment nodeEnv, IndicesService indicesService, ClusterService clusterService) {
|
||||
super(settings);
|
||||
this.nodeEnv = nodeEnv;
|
||||
this.indicesService = indicesService;
|
||||
this.clusterService = clusterService;
|
||||
clusterService.add(this);
|
||||
|
@ -94,5 +101,21 @@ public class IndicesStore extends AbstractComponent implements ClusterStateListe
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// do the reverse, and delete dangling indices that might remain on that node
|
||||
// this can happen when deleting a closed index, or when a node joins and it has deleted indices
|
||||
if (nodeEnv.hasNodeFile()) {
|
||||
File[] files = nodeEnv.indicesLocation().listFiles();
|
||||
if (files != null) {
|
||||
for (File file : files) {
|
||||
// if we have the index on the metadata, don't delete it
|
||||
if (event.state().metaData().hasIndex(file.getName())) {
|
||||
continue;
|
||||
}
|
||||
logger.debug("[{}] deleting index that is no longer in the cluster meta_date", file.getName());
|
||||
FileSystemUtils.deleteRecursively(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue