|
@@ -33,7 +33,9 @@ import org.apache.lucene.util.SetOnce;
|
|
|
import org.elasticsearch.ExceptionsHelper;
|
|
|
import org.elasticsearch.Version;
|
|
|
import org.elasticsearch.action.ActionListener;
|
|
|
+import org.elasticsearch.action.ActionRunnable;
|
|
|
import org.elasticsearch.action.StepListener;
|
|
|
+import org.elasticsearch.action.support.PlainActionFuture;
|
|
|
import org.elasticsearch.action.support.ThreadedActionListener;
|
|
|
import org.elasticsearch.action.support.replication.ReplicationResponse;
|
|
|
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
|
@@ -230,8 +232,7 @@ public class RecoverySourceHandler {
|
|
|
|
|
|
try {
|
|
|
final int estimateNumOps = shard.estimateNumberOfHistoryOperations("peer-recovery", startingSeqNo);
|
|
|
- shard.store().incRef();
|
|
|
- final Releasable releaseStore = Releasables.releaseOnce(shard.store()::decRef);
|
|
|
+ final Releasable releaseStore = acquireStore(shard.store());
|
|
|
resources.add(releaseStore);
|
|
|
sendFileStep.whenComplete(r -> IOUtils.close(safeCommitRef, releaseStore), e -> {
|
|
|
try {
|
|
@@ -393,6 +394,25 @@ public class RecoverySourceHandler {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Increases the store reference and returns a {@link Releasable} that will decrease the store reference using the generic thread pool.
|
|
|
+ * We must never release the store using an interruptible thread as we can risk invalidating the node lock.
|
|
|
+ */
|
|
|
+ private Releasable acquireStore(Store store) {
|
|
|
+ store.incRef();
|
|
|
+ return Releasables.releaseOnce(() -> {
|
|
|
+ final PlainActionFuture<Void> future = new PlainActionFuture<>();
|
|
|
+ threadPool.generic().execute(new ActionRunnable<>(future) {
|
|
|
+ @Override
|
|
|
+ protected void doRun() {
|
|
|
+ store.decRef();
|
|
|
+ listener.onResponse(null);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ FutureUtils.get(future);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
static final class SendFileResult {
|
|
|
final List<String> phase1FileNames;
|
|
|
final List<Long> phase1FileSizes;
|