Skip to content

Commit 6369012

Browse files
committed
fix a few nocommits
1 parent bd6804b commit 6369012

8 files changed

Lines changed: 47 additions & 18 deletions

File tree

lucene/core/src/java/org/apache/lucene/index/IndexFileDeleter.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,32 @@ private void deleteFiles(Collection<String> names) throws IOException {
699699
infoStream.message("IFD", "delete \"" + names + "\"");
700700
}
701701

702+
// We make two passes, first deleting any segments_N files, second deleting all the rest. We do this so that if we throw exc or JVM
703+
// crashes during deletions, we don't leave the index in an "apparently corrupt" state:
702704
for(String name : names) {
705+
if (name.startsWith(IndexFileNames.SEGMENTS) == false) {
706+
continue;
707+
}
708+
try {
709+
directory.deleteFile(name);
710+
} catch (NoSuchFileException | FileNotFoundException e) {
711+
// IndexWriter should only ask us to delete files it knows it wrote, so if we hit this, something is wrong!
712+
713+
if (Constants.WINDOWS) {
714+
// TODO: can we remove this OS-specific hacky logic? If windows deleteFile is buggy, we should instead contain this workaround in
715+
// a WindowsFSDirectory ...
716+
// LUCENE-6684: we suppress this assert for Windows, since a file could be in a confusing "pending delete" state, and falsely
717+
// return NSFE/FNFE
718+
} else {
719+
throw e;
720+
}
721+
}
722+
}
723+
724+
for(String name : names) {
725+
if (name.startsWith(IndexFileNames.SEGMENTS) == true) {
726+
continue;
727+
}
703728
try {
704729
directory.deleteFile(name);
705730
} catch (NoSuchFileException | FileNotFoundException e) {

lucene/replicator/src/java/org/apache/lucene/replicator/nrt/ReplicaFileDeleter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ private synchronized boolean delete(String fileName) {
122122
node.message("file " + fileName + ": delete failed: " + missing);
123123
throw new IllegalStateException("file " + fileName + ": we attempted delete but the file does not exist?", missing);
124124
} catch (IOException ioe) {
125+
// nocommit remove this retry logic! it's Directory's job now...
125126
if (Node.VERBOSE_FILES) {
126127
node.message("file " + fileName + ": delete failed: " + ioe + "; will retry later");
127128
}

lucene/replicator/src/java/org/apache/lucene/replicator/nrt/ReplicaNode.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,6 @@ public ReplicaNode(int id, Directory dir, SearcherFactory searcherFactory) throw
9292
// Obtain a write lock on this index since we "act like" an IndexWriter, to prevent any other IndexWriter or ReplicaNode from using it:
9393
writeFileLock = dir.obtainLock(IndexWriter.WRITE_LOCK_NAME);
9494

95-
// nocommit must check for no pending deletes here, like IW does
96-
9795
state = "init";
9896
deleter = new ReplicaFileDeleter(this, dir);
9997
} catch (Throwable t) {

lucene/replicator/src/test/org/apache/lucene/replicator/nrt/Jobs.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ public void run() {
8484
topJob.onceDone.run(topJob);
8585
} catch (Throwable t2) {
8686
node.message("ignore exception calling OnceDone: " + t2);
87+
t2.printStackTrace(System.out);
8788
}
8889
continue;
8990
}

lucene/replicator/src/test/org/apache/lucene/replicator/nrt/SimpleReplicaNode.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,9 @@ static Directory getDirectory(Random random, int id, Path path, boolean doCheckI
135135
MockDirectoryWrapper dir = LuceneTestCase.newMockFSDirectory(path);
136136

137137
dir.setAssertNoUnrefencedFilesOnClose(true);
138-
if (doCheckIndexOnClose) {
139-
dir.setCheckIndexOnClose(false);
140-
}
138+
// nocommit
139+
//dir.setCheckIndexOnClose(doCheckIndexOnClose);
140+
dir.setCheckIndexOnClose(true);
141141

142142
// Corrupt any index files not referenced by current commit point; this is important (increases test evilness) because we may have done
143143
// a hard crash of the previous JVM writing to this directory and so MDW's corrupt-unknown-files-on-close never ran:

lucene/replicator/src/test/org/apache/lucene/replicator/nrt/TestNRTReplication.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@
3939

4040
import com.carrotsearch.randomizedtesting.SeedUtils;
4141

42-
// nocommit make some explicit failure tests
43-
4442
// MockRandom's .sd file has no index header/footer:
4543
@SuppressCodecs({"MockRandom", "Memory", "Direct", "SimpleText"})
4644
@SuppressSysoutChecks(bugUrl = "Stuff gets printed, important stuff for debugging a failure")

lucene/replicator/src/test/org/apache/lucene/replicator/nrt/TestStressNRTReplication.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@ public class TestStressNRTReplication extends LuceneTestCase {
161161
static final boolean DO_BIT_FLIPS_DURING_COPY = true;
162162

163163
/** Set to a non-null value to force exactly that many nodes; else, it's random. */
164-
static final Integer NUM_NODES = null;
164+
// nocommit
165+
static final Integer NUM_NODES = 2;
165166

166167
final AtomicBoolean failed = new AtomicBoolean();
167168

@@ -980,10 +981,10 @@ public void run() {
980981
continue;
981982
}
982983

983-
// nocommit not anymore?
984-
// This can be null if we got the new primary after crash and that primary is still catching up (replaying xlog):
984+
// This can be null if primary is flushing, has already refreshed its searcher, but is e.g. still notifying replicas and hasn't
985+
// yet returned the version to us, in which case this searcher thread can see the version before the main thread has added it to
986+
// versionToMarker:
985987
Integer expectedAtLeastHitCount = versionToMarker.get(version);
986-
assertNotNull("version=" + version, expectedAtLeastHitCount);
987988

988989
if (expectedAtLeastHitCount != null && expectedAtLeastHitCount > 0 && random().nextInt(10) == 7) {
989990
try {

lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,6 @@ public synchronized void renameFile(String source, String dest) throws IOExcepti
230230
throw (AssertionError) fillOpenTrace(new AssertionError("MockDirectoryWrapper: dest file \"" + dest + "\" is still open: cannot rename"), dest, true);
231231
}
232232

233-
if (createdFiles.contains(dest)) {
234-
throw new IOException("MockDirectoryWrapper: dest file \"" + dest + "\" already exists: cannot rename");
235-
}
236-
237233
boolean success = false;
238234
try {
239235
in.renameFile(source, dest);
@@ -275,7 +271,14 @@ public synchronized void corruptUnknownFiles() throws IOException {
275271
for(String fileName : listAll()) {
276272
if (fileName.startsWith(IndexFileNames.SEGMENTS)) {
277273
System.out.println("MDW: read " + fileName + " to gather files it references");
278-
knownFiles.addAll(SegmentInfos.readCommit(this, fileName).files(true));
274+
SegmentInfos infos;
275+
try {
276+
infos = SegmentInfos.readCommit(this, fileName);
277+
} catch (IOException ioe) {
278+
System.out.println("MDW: exception reading segment infos " + fileName + "; files: " + Arrays.toString(listAll()));
279+
throw ioe;
280+
}
281+
knownFiles.addAll(infos.files(true));
279282
}
280283
}
281284

@@ -438,7 +441,6 @@ public synchronized void corruptFiles(Collection<String> files) throws IOExcepti
438441
/** Simulates a crash of OS or machine by overwriting
439442
* unsynced files. */
440443
public synchronized void crash() throws IOException {
441-
crashed = true;
442444
openFiles = new HashMap<>();
443445
openFilesForWrite = new HashSet<>();
444446
openFilesDeleted = new HashSet<>();
@@ -451,6 +453,7 @@ public synchronized void crash() throws IOException {
451453
} catch (Exception ignored) {}
452454
}
453455
corruptFiles(unSyncedFiles);
456+
crashed = true;
454457
unSyncedFiles = new HashSet<>();
455458
}
456459

@@ -569,6 +572,7 @@ public synchronized void deleteFile(String name) throws IOException {
569572

570573
unSyncedFiles.remove(name);
571574
in.deleteFile(name);
575+
createdFiles.remove(name);
572576
}
573577

574578
// sets the cause of the incoming ioe to be the stack
@@ -829,7 +833,7 @@ public synchronized void close() throws IOException {
829833
}
830834
throw new RuntimeException("MockDirectoryWrapper: cannot close: there are still open locks: " + openLocks, cause);
831835
}
832-
836+
833837
if (getCheckIndexOnClose()) {
834838
randomIOExceptionRate = 0.0;
835839
randomIOExceptionRateOnOpen = 0.0;
@@ -846,6 +850,7 @@ public synchronized void close() throws IOException {
846850
TestUtil.checkIndex(this, getCrossCheckTermVectorsOnClose(), true);
847851

848852
// TODO: factor this out / share w/ TestIW.assertNoUnreferencedFiles
853+
// nocommit pull this outside of "getCheckIndexOnClose"
849854
if (assertNoUnreferencedFilesOnClose) {
850855

851856
// now look for unreferenced files: discount ones that we tried to delete but could not

0 commit comments

Comments
 (0)