You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by si...@apache.org on 2018/04/25 14:58:39 UTC

[1/2] lucene-solr:master: LUCENE-8275: Push up #checkPendingDeletes to Directory

Repository: lucene-solr
Updated Branches:
  refs/heads/branch_7x 493e8fd31 -> 9f4e6c5da
  refs/heads/master fbeef2f72 -> aa341476f


LUCENE-8275: Push up #checkPendingDeletes to Directory

IndexWriter checks in it's ctor if the incoming directory is an
FSDirectory. If that is the case it ensures that the directory retries
deleting it's pending deletes and if there are pending deletes it will
fail creating the writer. Yet, this check didn't unwrap filter directories
or subclasses like FileSwitchDirectory such that in the case of MDW we
never checked for pending deletes.

There are also two places in FSDirectory that first removed the file
that was supposed to be created / renamed to from the pending deletes set
and then tried to clean up pending deletes which excluded the file. These
places now remove the file from the set after the pending deletes are checked.


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/aa341476
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/aa341476
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/aa341476

Branch: refs/heads/master
Commit: aa341476fdb6836bfc62b096219e268e52006103
Parents: fbeef2f
Author: Simon Willnauer <si...@apache.org>
Authored: Wed Apr 25 10:57:24 2018 +0200
Committer: Simon Willnauer <si...@apache.org>
Committed: Wed Apr 25 16:46:25 2018 +0200

----------------------------------------------------------------------
 lucene/CHANGES.txt                                  |  4 ++++
 .../java/org/apache/lucene/index/IndexWriter.java   |  3 +--
 .../src/java/org/apache/lucene/store/Directory.java |  7 +++++++
 .../java/org/apache/lucene/store/FSDirectory.java   | 16 +++++++++-------
 .../apache/lucene/store/FileSwitchDirectory.java    |  5 +++++
 .../org/apache/lucene/store/FilterDirectory.java    |  4 ++++
 .../apache/lucene/store/TestFilterDirectory.java    |  2 +-
 .../apache/lucene/replicator/nrt/ReplicaNode.java   |  5 ++---
 8 files changed, 33 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/aa341476/lucene/CHANGES.txt
----------------------------------------------------------------------
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index a440f95..b141e45 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -169,6 +169,10 @@ Bug Fixes
   shared with another reader with no CacheHelper (Alan Woodward, Simon Willnauer,
   Adrien Grand)
 
+* LUCENE-8275: Push up #checkPendingDeletes to Directory to ensure IW fails if 
+  the directory has pending deletes files even if the directory is filtered or 
+  a FileSwitchDirectory (Simon Willnauer, Robert Muir)
+
 Other
 
 * LUCENE-8228: removed obsolete IndexDeletionPolicy clone() requirements from

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/aa341476/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java b/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java
index d72d856..ccbfe5c 100644
--- a/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java
+++ b/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java
@@ -52,7 +52,6 @@ import org.apache.lucene.search.Query;
 import org.apache.lucene.search.Sort;
 import org.apache.lucene.store.AlreadyClosedException;
 import org.apache.lucene.store.Directory;
-import org.apache.lucene.store.FSDirectory;
 import org.apache.lucene.store.FlushInfo;
 import org.apache.lucene.store.IOContext;
 import org.apache.lucene.store.Lock;
@@ -704,7 +703,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit, Accountable {
    *           IO error
    */
   public IndexWriter(Directory d, IndexWriterConfig conf) throws IOException {
-    if (d instanceof FSDirectory && ((FSDirectory) d).checkPendingDeletions()) {
+    if (d.checkPendingDeletions()) {
       throw new IllegalArgumentException("Directory " + d + " still has pending deleted files; cannot initialize IndexWriter");
     }
     enableTestPoints = isEnableTestPoints();

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/aa341476/lucene/core/src/java/org/apache/lucene/store/Directory.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/store/Directory.java b/lucene/core/src/java/org/apache/lucene/store/Directory.java
index 3f9535b..7597803 100644
--- a/lucene/core/src/java/org/apache/lucene/store/Directory.java
+++ b/lucene/core/src/java/org/apache/lucene/store/Directory.java
@@ -171,4 +171,11 @@ public abstract class Directory implements Closeable {
    * @throws AlreadyClosedException if this Directory is closed
    */
   protected void ensureOpen() throws AlreadyClosedException {}
+
+  /** Tries to delete any pending deleted files, and returns true if
+   *  there are still files that could not be deleted.
+   *  This method is optional and returns <code>false</code> by default. */
+  public boolean checkPendingDeletions() throws IOException {
+    return false;
+  }
 }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/aa341476/lucene/core/src/java/org/apache/lucene/store/FSDirectory.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/store/FSDirectory.java b/lucene/core/src/java/org/apache/lucene/store/FSDirectory.java
index 158a2e2..7b465df 100644
--- a/lucene/core/src/java/org/apache/lucene/store/FSDirectory.java
+++ b/lucene/core/src/java/org/apache/lucene/store/FSDirectory.java
@@ -246,10 +246,11 @@ public abstract class FSDirectory extends BaseDirectory {
   @Override
   public IndexOutput createOutput(String name, IOContext context) throws IOException {
     ensureOpen();
-
-    // If this file was pending delete, we are now bringing it back to life:
-    pendingDeletes.remove(name);
     maybeDeletePendingFiles();
+    // If this file was pending delete, we are now bringing it back to life:
+    if (pendingDeletes.remove(name)) {
+      privateDeleteFile(name, true); // try again to delete it - this is best effort
+    }
     return new FSIndexOutput(name);
   }
 
@@ -293,9 +294,11 @@ public abstract class FSDirectory extends BaseDirectory {
     if (pendingDeletes.contains(source)) {
       throw new NoSuchFileException("file \"" + source + "\" is pending delete and cannot be moved");
     }
-    pendingDeletes.remove(dest);
-    Files.move(directory.resolve(source), directory.resolve(dest), StandardCopyOption.ATOMIC_MOVE);
     maybeDeletePendingFiles();
+    if (pendingDeletes.remove(dest)) {
+      privateDeleteFile(dest, true); // try again to delete it - this is best effort
+    }
+    Files.move(directory.resolve(source), directory.resolve(dest), StandardCopyOption.ATOMIC_MOVE);
   }
 
   @Override
@@ -336,8 +339,7 @@ public abstract class FSDirectory extends BaseDirectory {
     maybeDeletePendingFiles();
   }
 
-  /** Tries to delete any pending deleted files, and returns true if
-   *  there are still files that could not be deleted. */
+  @Override
   public boolean checkPendingDeletions() throws IOException {
     deletePendingFiles();
     return pendingDeletes.isEmpty() == false;

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/aa341476/lucene/core/src/java/org/apache/lucene/store/FileSwitchDirectory.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/store/FileSwitchDirectory.java b/lucene/core/src/java/org/apache/lucene/store/FileSwitchDirectory.java
index f0c46b1..b2d9452 100644
--- a/lucene/core/src/java/org/apache/lucene/store/FileSwitchDirectory.java
+++ b/lucene/core/src/java/org/apache/lucene/store/FileSwitchDirectory.java
@@ -202,4 +202,9 @@ public class FileSwitchDirectory extends Directory {
   public IndexInput openInput(String name, IOContext context) throws IOException {
     return getDirectory(name).openInput(name, context);
   }
+
+  @Override
+  public boolean checkPendingDeletions() throws IOException {
+    return primaryDir.checkPendingDeletions() && secondaryDir.checkPendingDeletions();
+  }
 }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/aa341476/lucene/core/src/java/org/apache/lucene/store/FilterDirectory.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/store/FilterDirectory.java b/lucene/core/src/java/org/apache/lucene/store/FilterDirectory.java
index 897ce76..cc91c9e 100644
--- a/lucene/core/src/java/org/apache/lucene/store/FilterDirectory.java
+++ b/lucene/core/src/java/org/apache/lucene/store/FilterDirectory.java
@@ -114,4 +114,8 @@ public abstract class FilterDirectory extends Directory {
     return getClass().getSimpleName() + "(" + in.toString() + ")";
   }
 
+  @Override
+  public boolean checkPendingDeletions() throws IOException {
+    return in.checkPendingDeletions();
+  }
 }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/aa341476/lucene/core/src/test/org/apache/lucene/store/TestFilterDirectory.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/store/TestFilterDirectory.java b/lucene/core/src/test/org/apache/lucene/store/TestFilterDirectory.java
index 6224140..81b8fad 100644
--- a/lucene/core/src/test/org/apache/lucene/store/TestFilterDirectory.java
+++ b/lucene/core/src/test/org/apache/lucene/store/TestFilterDirectory.java
@@ -28,7 +28,7 @@ import org.junit.Test;
 public class TestFilterDirectory extends BaseDirectoryTestCase {
 
   @Override
-  protected Directory getDirectory(Path path) throws IOException {
+  protected Directory getDirectory(Path path) {
     return new FilterDirectory(new RAMDirectory()) {};
   }
   

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/aa341476/lucene/replicator/src/java/org/apache/lucene/replicator/nrt/ReplicaNode.java
----------------------------------------------------------------------
diff --git a/lucene/replicator/src/java/org/apache/lucene/replicator/nrt/ReplicaNode.java b/lucene/replicator/src/java/org/apache/lucene/replicator/nrt/ReplicaNode.java
index 291284e..baed7d6 100644
--- a/lucene/replicator/src/java/org/apache/lucene/replicator/nrt/ReplicaNode.java
+++ b/lucene/replicator/src/java/org/apache/lucene/replicator/nrt/ReplicaNode.java
@@ -44,7 +44,6 @@ import org.apache.lucene.store.AlreadyClosedException;
 import org.apache.lucene.store.BufferedChecksumIndexInput;
 import org.apache.lucene.store.ByteArrayIndexInput;
 import org.apache.lucene.store.Directory;
-import org.apache.lucene.store.FSDirectory;
 import org.apache.lucene.store.IOContext;
 import org.apache.lucene.store.IndexOutput;
 import org.apache.lucene.store.Lock;
@@ -83,7 +82,7 @@ public abstract class ReplicaNode extends Node {
   public ReplicaNode(int id, Directory dir, SearcherFactory searcherFactory, PrintStream printStream) throws IOException {
     super(id, dir, searcherFactory, printStream);
 
-    if (dir instanceof FSDirectory && ((FSDirectory) dir).checkPendingDeletions()) {
+    if (dir.checkPendingDeletions()) {
       throw new IllegalArgumentException("Directory " + dir + " still has pending deleted files; cannot initialize IndexWriter");
     }
 
@@ -200,7 +199,7 @@ public abstract class ReplicaNode extends Node {
         assert deleter.getRefCount(segmentsFileName) == 1;
         deleter.decRef(Collections.singleton(segmentsFileName));
 
-        if (dir instanceof FSDirectory && ((FSDirectory) dir).checkPendingDeletions()) {
+        if (dir.checkPendingDeletions()) {
           // If e.g. virus checker blocks us from deleting, we absolutely cannot start this node else there is a definite window during
           // which if we carsh, we cause corruption:
           throw new RuntimeException("replica cannot start: existing segments file=" + segmentsFileName + " must be removed in order to start, but the file delete failed");


[2/2] lucene-solr:branch_7x: LUCENE-8275: Push up #checkPendingDeletes to Directory

Posted by si...@apache.org.
LUCENE-8275: Push up #checkPendingDeletes to Directory

IndexWriter checks in it's ctor if the incoming directory is an
FSDirectory. If that is the case it ensures that the directory retries
deleting it's pending deletes and if there are pending deletes it will
fail creating the writer. Yet, this check didn't unwrap filter directories
or subclasses like FileSwitchDirectory such that in the case of MDW we
never checked for pending deletes.

There are also two places in FSDirectory that first removed the file
that was supposed to be created / renamed to from the pending deletes set
and then tried to clean up pending deletes which excluded the file. These
places now remove the file from the set after the pending deletes are checked.


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/9f4e6c5d
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/9f4e6c5d
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/9f4e6c5d

Branch: refs/heads/branch_7x
Commit: 9f4e6c5da8d2af48f5947e15ccb2723e6d3cb4d5
Parents: 493e8fd
Author: Simon Willnauer <si...@apache.org>
Authored: Wed Apr 25 10:57:24 2018 +0200
Committer: Simon Willnauer <si...@apache.org>
Committed: Wed Apr 25 16:58:22 2018 +0200

----------------------------------------------------------------------
 lucene/CHANGES.txt                                  |  4 ++++
 .../java/org/apache/lucene/index/IndexWriter.java   |  3 +--
 .../src/java/org/apache/lucene/store/Directory.java |  7 +++++++
 .../java/org/apache/lucene/store/FSDirectory.java   | 16 +++++++++-------
 .../apache/lucene/store/FileSwitchDirectory.java    |  5 +++++
 .../org/apache/lucene/store/FilterDirectory.java    |  4 ++++
 .../apache/lucene/store/TestFilterDirectory.java    |  2 +-
 .../apache/lucene/replicator/nrt/ReplicaNode.java   |  5 ++---
 8 files changed, 33 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/9f4e6c5d/lucene/CHANGES.txt
----------------------------------------------------------------------
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 0ae4bc3..eb42a1a 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -76,6 +76,10 @@ Bug Fixes
   shared with another reader with no CacheHelper (Alan Woodward, Simon Willnauer,
   Adrien Grand)
 
+* LUCENE-8275: Push up #checkPendingDeletes to Directory to ensure IW fails if 
+  the directory has pending deletes files even if the directory is filtered or 
+  a FileSwitchDirectory (Simon Willnauer, Robert Muir)
+
 Other
 
 * LUCENE-8228: removed obsolete IndexDeletionPolicy clone() requirements from

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/9f4e6c5d/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java b/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java
index ca3c7b7..6c69dbf 100644
--- a/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java
+++ b/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java
@@ -52,7 +52,6 @@ import org.apache.lucene.search.Query;
 import org.apache.lucene.search.Sort;
 import org.apache.lucene.store.AlreadyClosedException;
 import org.apache.lucene.store.Directory;
-import org.apache.lucene.store.FSDirectory;
 import org.apache.lucene.store.FlushInfo;
 import org.apache.lucene.store.IOContext;
 import org.apache.lucene.store.Lock;
@@ -704,7 +703,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit, Accountable {
    *           IO error
    */
   public IndexWriter(Directory d, IndexWriterConfig conf) throws IOException {
-    if (d instanceof FSDirectory && ((FSDirectory) d).checkPendingDeletions()) {
+    if (d.checkPendingDeletions()) {
       throw new IllegalArgumentException("Directory " + d + " still has pending deleted files; cannot initialize IndexWriter");
     }
     enableTestPoints = isEnableTestPoints();

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/9f4e6c5d/lucene/core/src/java/org/apache/lucene/store/Directory.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/store/Directory.java b/lucene/core/src/java/org/apache/lucene/store/Directory.java
index 3f9535b..7597803 100644
--- a/lucene/core/src/java/org/apache/lucene/store/Directory.java
+++ b/lucene/core/src/java/org/apache/lucene/store/Directory.java
@@ -171,4 +171,11 @@ public abstract class Directory implements Closeable {
    * @throws AlreadyClosedException if this Directory is closed
    */
   protected void ensureOpen() throws AlreadyClosedException {}
+
+  /** Tries to delete any pending deleted files, and returns true if
+   *  there are still files that could not be deleted.
+   *  This method is optional and returns <code>false</code> by default. */
+  public boolean checkPendingDeletions() throws IOException {
+    return false;
+  }
 }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/9f4e6c5d/lucene/core/src/java/org/apache/lucene/store/FSDirectory.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/store/FSDirectory.java b/lucene/core/src/java/org/apache/lucene/store/FSDirectory.java
index 158a2e2..7b465df 100644
--- a/lucene/core/src/java/org/apache/lucene/store/FSDirectory.java
+++ b/lucene/core/src/java/org/apache/lucene/store/FSDirectory.java
@@ -246,10 +246,11 @@ public abstract class FSDirectory extends BaseDirectory {
   @Override
   public IndexOutput createOutput(String name, IOContext context) throws IOException {
     ensureOpen();
-
-    // If this file was pending delete, we are now bringing it back to life:
-    pendingDeletes.remove(name);
     maybeDeletePendingFiles();
+    // If this file was pending delete, we are now bringing it back to life:
+    if (pendingDeletes.remove(name)) {
+      privateDeleteFile(name, true); // try again to delete it - this is best effort
+    }
     return new FSIndexOutput(name);
   }
 
@@ -293,9 +294,11 @@ public abstract class FSDirectory extends BaseDirectory {
     if (pendingDeletes.contains(source)) {
       throw new NoSuchFileException("file \"" + source + "\" is pending delete and cannot be moved");
     }
-    pendingDeletes.remove(dest);
-    Files.move(directory.resolve(source), directory.resolve(dest), StandardCopyOption.ATOMIC_MOVE);
     maybeDeletePendingFiles();
+    if (pendingDeletes.remove(dest)) {
+      privateDeleteFile(dest, true); // try again to delete it - this is best effort
+    }
+    Files.move(directory.resolve(source), directory.resolve(dest), StandardCopyOption.ATOMIC_MOVE);
   }
 
   @Override
@@ -336,8 +339,7 @@ public abstract class FSDirectory extends BaseDirectory {
     maybeDeletePendingFiles();
   }
 
-  /** Tries to delete any pending deleted files, and returns true if
-   *  there are still files that could not be deleted. */
+  @Override
   public boolean checkPendingDeletions() throws IOException {
     deletePendingFiles();
     return pendingDeletes.isEmpty() == false;

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/9f4e6c5d/lucene/core/src/java/org/apache/lucene/store/FileSwitchDirectory.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/store/FileSwitchDirectory.java b/lucene/core/src/java/org/apache/lucene/store/FileSwitchDirectory.java
index f0c46b1..b2d9452 100644
--- a/lucene/core/src/java/org/apache/lucene/store/FileSwitchDirectory.java
+++ b/lucene/core/src/java/org/apache/lucene/store/FileSwitchDirectory.java
@@ -202,4 +202,9 @@ public class FileSwitchDirectory extends Directory {
   public IndexInput openInput(String name, IOContext context) throws IOException {
     return getDirectory(name).openInput(name, context);
   }
+
+  @Override
+  public boolean checkPendingDeletions() throws IOException {
+    return primaryDir.checkPendingDeletions() && secondaryDir.checkPendingDeletions();
+  }
 }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/9f4e6c5d/lucene/core/src/java/org/apache/lucene/store/FilterDirectory.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/store/FilterDirectory.java b/lucene/core/src/java/org/apache/lucene/store/FilterDirectory.java
index 897ce76..cc91c9e 100644
--- a/lucene/core/src/java/org/apache/lucene/store/FilterDirectory.java
+++ b/lucene/core/src/java/org/apache/lucene/store/FilterDirectory.java
@@ -114,4 +114,8 @@ public abstract class FilterDirectory extends Directory {
     return getClass().getSimpleName() + "(" + in.toString() + ")";
   }
 
+  @Override
+  public boolean checkPendingDeletions() throws IOException {
+    return in.checkPendingDeletions();
+  }
 }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/9f4e6c5d/lucene/core/src/test/org/apache/lucene/store/TestFilterDirectory.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/store/TestFilterDirectory.java b/lucene/core/src/test/org/apache/lucene/store/TestFilterDirectory.java
index 6224140..81b8fad 100644
--- a/lucene/core/src/test/org/apache/lucene/store/TestFilterDirectory.java
+++ b/lucene/core/src/test/org/apache/lucene/store/TestFilterDirectory.java
@@ -28,7 +28,7 @@ import org.junit.Test;
 public class TestFilterDirectory extends BaseDirectoryTestCase {
 
   @Override
-  protected Directory getDirectory(Path path) throws IOException {
+  protected Directory getDirectory(Path path) {
     return new FilterDirectory(new RAMDirectory()) {};
   }
   

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/9f4e6c5d/lucene/replicator/src/java/org/apache/lucene/replicator/nrt/ReplicaNode.java
----------------------------------------------------------------------
diff --git a/lucene/replicator/src/java/org/apache/lucene/replicator/nrt/ReplicaNode.java b/lucene/replicator/src/java/org/apache/lucene/replicator/nrt/ReplicaNode.java
index 291284e..baed7d6 100644
--- a/lucene/replicator/src/java/org/apache/lucene/replicator/nrt/ReplicaNode.java
+++ b/lucene/replicator/src/java/org/apache/lucene/replicator/nrt/ReplicaNode.java
@@ -44,7 +44,6 @@ import org.apache.lucene.store.AlreadyClosedException;
 import org.apache.lucene.store.BufferedChecksumIndexInput;
 import org.apache.lucene.store.ByteArrayIndexInput;
 import org.apache.lucene.store.Directory;
-import org.apache.lucene.store.FSDirectory;
 import org.apache.lucene.store.IOContext;
 import org.apache.lucene.store.IndexOutput;
 import org.apache.lucene.store.Lock;
@@ -83,7 +82,7 @@ public abstract class ReplicaNode extends Node {
   public ReplicaNode(int id, Directory dir, SearcherFactory searcherFactory, PrintStream printStream) throws IOException {
     super(id, dir, searcherFactory, printStream);
 
-    if (dir instanceof FSDirectory && ((FSDirectory) dir).checkPendingDeletions()) {
+    if (dir.checkPendingDeletions()) {
       throw new IllegalArgumentException("Directory " + dir + " still has pending deleted files; cannot initialize IndexWriter");
     }
 
@@ -200,7 +199,7 @@ public abstract class ReplicaNode extends Node {
         assert deleter.getRefCount(segmentsFileName) == 1;
         deleter.decRef(Collections.singleton(segmentsFileName));
 
-        if (dir instanceof FSDirectory && ((FSDirectory) dir).checkPendingDeletions()) {
+        if (dir.checkPendingDeletions()) {
           // If e.g. virus checker blocks us from deleting, we absolutely cannot start this node else there is a definite window during
           // which if we carsh, we cause corruption:
           throw new RuntimeException("replica cannot start: existing segments file=" + segmentsFileName + " must be removed in order to start, but the file delete failed");