Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ public SearchHandler open(final Database db, final Subspace index, final Analyze
return new FDBDirectorySearchHandler(dir, writer, manager, analyzer);
}

@Override
public void delete(final Database db, final Subspace index) {
db.run(txn -> {
txn.clear(index.range());
return null;
});
}

/**
* The current holder of the lock will know they lost the lock on their next
* attempt at a destructive operation and will crash cleanly.
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/cloudant/search3/Search.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.tokenattributes.TermToBytesRefAttribute;
import org.apache.lucene.index.CorruptIndexException;
import org.apache.lucene.queryparser.classic.ParseException;
import org.apache.lucene.store.AlreadyClosedException;
import org.apache.lucene.util.BytesRef;
Expand Down Expand Up @@ -294,6 +295,10 @@ private <T> void execute(
try {
final SearchHandler handler = getOrOpen(index);
f.accept(handler);
} catch (final CorruptIndexException e) {
searchHandlerFactory.delete(db, toSubspace(index));
failedHandler(index, e);
responseObserver.onError(fromThrowable(e));
} catch (final IOException | AlreadyClosedException e) {
failedHandler(index, e);
responseObserver.onError(fromThrowable(e));
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/cloudant/search3/SearchHandlerFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ public interface SearchHandlerFactory {

SearchHandler open(final Database db, final Subspace index, final Analyzer analyzer) throws IOException;

void delete(final Database db, final Subspace index);

}