don't ignore recovery on throttling unless the shard is closed
This commit is contained in:
parent
4e74001bde
commit
b609162be3
|
@ -43,7 +43,7 @@ public class Directories {
|
||||||
/**
|
/**
|
||||||
* Deletes all the files from a directory.
|
* Deletes all the files from a directory.
|
||||||
*
|
*
|
||||||
* @param directory The directoy to delete all the files from
|
* @param directory The directory to delete all the files from
|
||||||
* @throws IOException if an exception occurs during the delete process
|
* @throws IOException if an exception occurs during the delete process
|
||||||
*/
|
*/
|
||||||
public static void deleteFiles(Directory directory) throws IOException {
|
public static void deleteFiles(Directory directory) throws IOException {
|
||||||
|
@ -52,6 +52,8 @@ public class Directories {
|
||||||
for (String file : files) {
|
for (String file : files) {
|
||||||
try {
|
try {
|
||||||
directory.deleteFile(file);
|
directory.deleteFile(file);
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
// ignore
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
lastException = e;
|
lastException = e;
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,6 @@ import org.elasticsearch.indices.recovery.throttler.RecoveryThrottler;
|
||||||
import org.elasticsearch.threadpool.ThreadPool;
|
import org.elasticsearch.threadpool.ThreadPool;
|
||||||
|
|
||||||
import java.util.concurrent.ScheduledFuture;
|
import java.util.concurrent.ScheduledFuture;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
|
||||||
|
|
||||||
import static org.elasticsearch.common.unit.TimeValue.*;
|
import static org.elasticsearch.common.unit.TimeValue.*;
|
||||||
|
|
||||||
|
@ -68,8 +67,6 @@ public class IndexShardGatewayService extends AbstractIndexShardComponent implem
|
||||||
|
|
||||||
private volatile long lastTranslogLength;
|
private volatile long lastTranslogLength;
|
||||||
|
|
||||||
private final AtomicBoolean recovered = new AtomicBoolean();
|
|
||||||
|
|
||||||
private final TimeValue snapshotInterval;
|
private final TimeValue snapshotInterval;
|
||||||
|
|
||||||
private volatile ScheduledFuture snapshotScheduleFuture;
|
private volatile ScheduledFuture snapshotScheduleFuture;
|
||||||
|
@ -127,10 +124,6 @@ public class IndexShardGatewayService extends AbstractIndexShardComponent implem
|
||||||
* Recovers the state of the shard from the gateway.
|
* Recovers the state of the shard from the gateway.
|
||||||
*/
|
*/
|
||||||
public void recover(final RecoveryListener listener) throws IndexShardGatewayRecoveryException, IgnoreGatewayRecoveryException {
|
public void recover(final RecoveryListener listener) throws IndexShardGatewayRecoveryException, IgnoreGatewayRecoveryException {
|
||||||
if (!recovered.compareAndSet(false, true)) {
|
|
||||||
listener.onIgnoreRecovery("already recovered");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (indexShard.state() == IndexShardState.CLOSED) {
|
if (indexShard.state() == IndexShardState.CLOSED) {
|
||||||
// got closed on us, just ignore this recovery
|
// got closed on us, just ignore this recovery
|
||||||
listener.onIgnoreRecovery("shard closed");
|
listener.onIgnoreRecovery("shard closed");
|
||||||
|
@ -140,18 +133,23 @@ public class IndexShardGatewayService extends AbstractIndexShardComponent implem
|
||||||
listener.onRecoveryFailed(new IndexShardGatewayRecoveryException(shardId, "Trying to recover when the shard is in backup state", null));
|
listener.onRecoveryFailed(new IndexShardGatewayRecoveryException(shardId, "Trying to recover when the shard is in backup state", null));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
indexShard.recovering();
|
||||||
|
} catch (IllegalIndexShardStateException e) {
|
||||||
|
// that's fine, since we might be called concurrently, just ignore this, we are already recovering
|
||||||
|
listener.onIgnoreRecovery("already in recovering process, " + e.getMessage());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
threadPool.cached().execute(new Runnable() {
|
threadPool.cached().execute(new Runnable() {
|
||||||
@Override public void run() {
|
@Override public void run() {
|
||||||
indexShard.recovering();
|
|
||||||
|
|
||||||
recoveryStatus = new RecoveryStatus();
|
recoveryStatus = new RecoveryStatus();
|
||||||
recoveryStatus.updateStage(RecoveryStatus.Stage.INIT);
|
recoveryStatus.updateStage(RecoveryStatus.Stage.INIT);
|
||||||
|
|
||||||
// we know we are on a thread, we can spin till we can engage in recovery
|
// we know we are on a thread, we can spin till we can engage in recovery
|
||||||
while (!recoveryThrottler.tryRecovery(shardId, "gateway")) {
|
while (!recoveryThrottler.tryRecovery(shardId, "gateway")) {
|
||||||
if (indexShard.ignoreRecoveryAttempt()) {
|
if (indexShard.state() == IndexShardState.CLOSED) {
|
||||||
listener.onIgnoreRecovery("ignoring recovery while waiting on retry");
|
listener.onIgnoreRecovery("ignoring recovery while waiting on retry, closed");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
recoveryStatus.updateStage(RecoveryStatus.Stage.RETRY);
|
recoveryStatus.updateStage(RecoveryStatus.Stage.RETRY);
|
||||||
|
@ -159,8 +157,9 @@ public class IndexShardGatewayService extends AbstractIndexShardComponent implem
|
||||||
Thread.sleep(recoveryThrottler.throttleInterval().millis());
|
Thread.sleep(recoveryThrottler.throttleInterval().millis());
|
||||||
recoveryStatus.retryTime(System.currentTimeMillis() - recoveryStatus.startTime());
|
recoveryStatus.retryTime(System.currentTimeMillis() - recoveryStatus.startTime());
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
if (indexShard.ignoreRecoveryAttempt()) {
|
recoveryStatus = null;
|
||||||
listener.onIgnoreRecovery("Interrupted while waiting for recovery, but we should ignore ...");
|
if (indexShard.state() == IndexShardState.CLOSED) {
|
||||||
|
listener.onIgnoreRecovery("Interrupted while waiting for recovery, but we should ignore since closed");
|
||||||
} else {
|
} else {
|
||||||
listener.onRecoveryFailed(new IndexShardGatewayRecoveryException(shardId, "Interrupted while waiting to recovery", e));
|
listener.onRecoveryFailed(new IndexShardGatewayRecoveryException(shardId, "Interrupted while waiting to recovery", e));
|
||||||
}
|
}
|
||||||
|
@ -233,6 +232,10 @@ public class IndexShardGatewayService extends AbstractIndexShardComponent implem
|
||||||
// shard has just been created, ignore it and return
|
// shard has just been created, ignore it and return
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (indexShard.state() == IndexShardState.RECOVERING) {
|
||||||
|
// shard is recovering, don't snapshot
|
||||||
|
return;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
SnapshotStatus snapshotStatus = indexShard.snapshot(new Engine.SnapshotHandler<SnapshotStatus>() {
|
SnapshotStatus snapshotStatus = indexShard.snapshot(new Engine.SnapshotHandler<SnapshotStatus>() {
|
||||||
@Override public SnapshotStatus snapshot(SnapshotIndexCommit snapshotIndexCommit, Translog.Snapshot translogSnapshot) throws EngineException {
|
@Override public SnapshotStatus snapshot(SnapshotIndexCommit snapshotIndexCommit, Translog.Snapshot translogSnapshot) throws EngineException {
|
||||||
|
|
|
@ -129,6 +129,9 @@ public class InternalIndexShard extends AbstractIndexShardComponent implements I
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Marks the shard as recovering, fails with exception is recovering is not allowed to be set.
|
||||||
|
*/
|
||||||
public IndexShardState recovering() throws IndexShardStartedException,
|
public IndexShardState recovering() throws IndexShardStartedException,
|
||||||
IndexShardRelocatedException, IndexShardRecoveringException, IndexShardClosedException {
|
IndexShardRelocatedException, IndexShardRecoveringException, IndexShardClosedException {
|
||||||
synchronized (mutex) {
|
synchronized (mutex) {
|
||||||
|
|
Loading…
Reference in New Issue