Skip to content

Commit 0a046bb

Browse files
committed
Checking Lucene Index status before upload
1 parent e8be80c commit 0a046bb

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

astra/src/main/java/com/slack/astra/chunk/ReadWriteChunk.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@
3232
import java.util.concurrent.ConcurrentHashMap;
3333
import java.util.concurrent.TimeUnit;
3434
import java.util.stream.Collectors;
35+
import org.apache.lucene.index.CheckIndex;
3536
import org.apache.lucene.index.IndexCommit;
37+
import org.apache.lucene.store.FSDirectory;
3638
import org.slf4j.Logger;
3739

3840
/**
@@ -249,6 +251,17 @@ public boolean snapshotToS3(BlobStore blobStore) {
249251
totalBytes += sizeOfFile;
250252
logger.debug("File name is {} ({} bytes)", fileName, sizeOfFile);
251253
}
254+
255+
// check if lucene index is valid and not corrupted
256+
try (FSDirectory directory = FSDirectory.open(dirPath)) {
257+
CheckIndex checker = new CheckIndex(directory);
258+
CheckIndex.Status status = checker.checkIndex();
259+
260+
if (!status.clean) {
261+
logger.error("Lucene index is not clean. Found issues: {}.", status);
262+
throw new IllegalStateException("Lucene index is not clean. Found issues: " + status);
263+
}
264+
}
252265
this.fileUploadAttempts.increment(filesToUpload.size());
253266
Timer.Sample snapshotTimer = Timer.start(meterRegistry);
254267

0 commit comments

Comments
 (0)