clear listeners only if not null (can cause failure to properly close a shard), also, do the CLOSE check if to reschedule within the sync block
This commit is contained in:
parent
953a99c75c
commit
e0d8094f3d
|
@ -337,6 +337,7 @@ public class InternalIndexService extends AbstractIndexComponent implements Inde
|
|||
// now we can close the translog service, we need to close it before the we close the shard
|
||||
shardInjector.getInstance(TranslogService.class).close();
|
||||
} catch (Exception e) {
|
||||
logger.debug("failed to close translog service", e);
|
||||
// ignore
|
||||
}
|
||||
|
||||
|
@ -351,18 +352,21 @@ public class InternalIndexService extends AbstractIndexComponent implements Inde
|
|||
try {
|
||||
((InternalIndexShard) indexShard).close(reason);
|
||||
} catch (Exception e) {
|
||||
logger.debug("failed to close index shard", e);
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
try {
|
||||
shardInjector.getInstance(Engine.class).close();
|
||||
} catch (Exception e) {
|
||||
logger.debug("failed to close engine", e);
|
||||
// ignore
|
||||
}
|
||||
|
||||
try {
|
||||
shardInjector.getInstance(MergePolicyProvider.class).close(delete);
|
||||
} catch (Exception e) {
|
||||
logger.debug("failed to close merge policy provider", e);
|
||||
// ignore
|
||||
}
|
||||
|
||||
|
@ -372,17 +376,20 @@ public class InternalIndexService extends AbstractIndexComponent implements Inde
|
|||
shardInjector.getInstance(IndexShardGatewayService.class).snapshotOnClose();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.debug("failed to snapshot gateway on close", e);
|
||||
// ignore
|
||||
}
|
||||
try {
|
||||
shardInjector.getInstance(IndexShardGatewayService.class).close(deleteGateway);
|
||||
} catch (Exception e) {
|
||||
logger.debug("failed to close index shard gateway", e);
|
||||
// ignore
|
||||
}
|
||||
try {
|
||||
// now we can close the translog
|
||||
shardInjector.getInstance(Translog.class).close(delete);
|
||||
} catch (Exception e) {
|
||||
logger.debug("failed to close translog", e);
|
||||
// ignore
|
||||
}
|
||||
|
||||
|
|
|
@ -442,10 +442,12 @@ public class InternalIndexShard extends AbstractIndexShardComponent implements I
|
|||
}
|
||||
|
||||
public void close(String reason) {
|
||||
listeners.clear();
|
||||
listeners = null;
|
||||
indexSettingsService.removeListener(applyRefreshSettings);
|
||||
synchronized (mutex) {
|
||||
if (listeners != null) {
|
||||
listeners.clear();
|
||||
}
|
||||
listeners = null;
|
||||
indexSettingsService.removeListener(applyRefreshSettings);
|
||||
if (state != IndexShardState.CLOSED) {
|
||||
if (refreshScheduledFuture != null) {
|
||||
refreshScheduledFuture.cancel(true);
|
||||
|
@ -609,8 +611,8 @@ public class InternalIndexShard extends AbstractIndexShardComponent implements I
|
|||
@Override public void run() {
|
||||
// we check before if a refresh is needed, if not, we reschedule, otherwise, we fork, refresh, and then reschedule
|
||||
if (!engine().refreshNeeded()) {
|
||||
if (state != IndexShardState.CLOSED) {
|
||||
synchronized (mutex) {
|
||||
synchronized (mutex) {
|
||||
if (state != IndexShardState.CLOSED) {
|
||||
refreshScheduledFuture = threadPool.schedule(refreshInterval, ThreadPool.Names.SAME, this);
|
||||
}
|
||||
}
|
||||
|
@ -637,8 +639,8 @@ public class InternalIndexShard extends AbstractIndexShardComponent implements I
|
|||
} catch (Exception e) {
|
||||
logger.warn("Failed to perform scheduled engine refresh", e);
|
||||
}
|
||||
if (state != IndexShardState.CLOSED) {
|
||||
synchronized (mutex) {
|
||||
synchronized (mutex) {
|
||||
if (state != IndexShardState.CLOSED) {
|
||||
refreshScheduledFuture = threadPool.schedule(refreshInterval, ThreadPool.Names.SAME, EngineRefresher.this);
|
||||
}
|
||||
}
|
||||
|
@ -650,8 +652,8 @@ public class InternalIndexShard extends AbstractIndexShardComponent implements I
|
|||
private class EngineMerger implements Runnable {
|
||||
@Override public void run() {
|
||||
if (!engine().possibleMergeNeeded()) {
|
||||
if (state != IndexShardState.CLOSED) {
|
||||
synchronized (mutex) {
|
||||
synchronized (mutex) {
|
||||
if (state != IndexShardState.CLOSED) {
|
||||
mergeScheduleFuture = threadPool.schedule(mergeInterval, ThreadPool.Names.SAME, this);
|
||||
}
|
||||
}
|
||||
|
@ -678,8 +680,8 @@ public class InternalIndexShard extends AbstractIndexShardComponent implements I
|
|||
} catch (Exception e) {
|
||||
logger.warn("Failed to perform scheduled engine optimize/merge", e);
|
||||
}
|
||||
if (state != IndexShardState.CLOSED) {
|
||||
synchronized (mutex) {
|
||||
synchronized (mutex) {
|
||||
if (state != IndexShardState.CLOSED) {
|
||||
mergeScheduleFuture = threadPool.schedule(mergeInterval, ThreadPool.Names.SAME, EngineMerger.this);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue