Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete shard content under lock #9083

Merged
merged 1 commit into from Jan 6, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -115,7 +115,7 @@ protected ClusterStatsNodeResponse nodeOperation(ClusterStatsNodeRequest nodeReq
NodeInfo nodeInfo = nodeService.info(false, true, false, true, false, false, true, false, true);
NodeStats nodeStats = nodeService.stats(CommonStatsFlags.NONE, false, true, true, false, false, true, false, false, false);
List<ShardStats> shardsStats = new ArrayList<>();
for (IndexService indexService : indicesService.indices().values()) {
for (IndexService indexService : indicesService) {
for (IndexShard indexShard : indexService) {
if (indexShard.routingEntry() != null && indexShard.routingEntry().active()) {
// only report on fully started shards
Expand Down
Expand Up @@ -153,7 +153,7 @@ protected ShardRecoveryResponse shardOperation(ShardRecoveryRequest request) thr

if (state == null) {
IndexShardGatewayService gatewayService =
indexService.shardInjector(request.shardId().id()).getInstance(IndexShardGatewayService.class);
indexService.shardInjectorSafe(request.shardId().id()).getInstance(IndexShardGatewayService.class);
state = gatewayService.recoveryState();
}

Expand Down

This file was deleted.

Expand Up @@ -20,11 +20,14 @@
package org.elasticsearch.common.component;

import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.lease.Releasable;

import java.io.Closeable;

/**
*
*/
public interface LifecycleComponent<T> extends CloseableComponent {
public interface LifecycleComponent<T> extends Releasable {

Lifecycle.State lifecycleState();

Expand Down
5 changes: 0 additions & 5 deletions src/main/java/org/elasticsearch/common/inject/Injectors.java
Expand Up @@ -230,11 +230,6 @@ public static <T> Class<?> getKeyType(Key<?> key) {
return keyType;
}


public static void close(Injector injector) {

}

public static void cleanCaches(Injector injector) {
((InjectorImpl) injector).clearCache();
if (injector.getParent() != null) {
Expand Down
41 changes: 32 additions & 9 deletions src/main/java/org/elasticsearch/env/NodeEnvironment.java
Expand Up @@ -182,15 +182,38 @@ public void deleteShardDirectorySafe(ShardId shardId, @IndexSettings Settings in
assert indexSettings != ImmutableSettings.EMPTY;
final Path[] paths = shardPaths(shardId);
logger.trace("deleting shard {} directory, paths: [{}]", shardId, paths);
try (Closeable lock = shardLock(shardId)) {
IOUtils.rm(paths);
if (hasCustomDataPath(indexSettings)) {
Path customLocation = resolveCustomLocation(indexSettings, shardId);
logger.trace("deleting custom shard {} directory [{}]", shardId, customLocation);
IOUtils.rm(customLocation);
}
logger.trace("deleted shard {} directory, paths: [{}]", shardId, paths);
assert FileSystemUtils.exists(paths) == false;
try (ShardLock lock = shardLock(shardId)) {
deleteShardDirectoryUnderLock(lock, indexSettings);
}
}

/**
* Deletes a shard data directory. Note: this method assumes that the shard lock is acquired
*
* @param lock the shards lock
* @throws IOException if an IOException occurs
*/
public void deleteShardDirectoryUnderLock(ShardLock lock, @IndexSettings Settings indexSettings) throws IOException {
assert indexSettings != ImmutableSettings.EMPTY;
final ShardId shardId = lock.getShardId();
assert isShardLocked(shardId) : "shard " + shardId + " is not locked";
final Path[] paths = shardPaths(shardId);
IOUtils.rm(paths);
if (hasCustomDataPath(indexSettings)) {
Path customLocation = resolveCustomLocation(indexSettings, shardId);
logger.trace("deleting custom shard {} directory [{}]", shardId, customLocation);
IOUtils.rm(customLocation);
}
logger.trace("deleted shard {} directory, paths: [{}]", shardId, paths);
assert FileSystemUtils.exists(paths) == false;
}

private boolean isShardLocked(ShardId id) {
try {
shardLock(id, 0).close();
return false;
} catch (IOException ex) {
return true;
}
}

Expand Down
4 changes: 0 additions & 4 deletions src/main/java/org/elasticsearch/gateway/GatewayMetaState.java
Expand Up @@ -192,10 +192,6 @@ public MetaData loadMetaState() throws Exception {
return loadState();
}

public boolean isDangling(String index) {
return danglingIndices.containsKey(index);
}

@Override
public void clusterChanged(ClusterChangedEvent event) {
if (event.state().blocks().disableStatePersistence()) {
Expand Down