mirror of
https://github.com/sismics/docs.git
synced 2024-11-22 14:07:55 +01:00
Closes #62: logs for index checking, explicit commit on close
This commit is contained in:
parent
a7a6adfa34
commit
59682b5ba6
@ -93,6 +93,12 @@
|
|||||||
<artifactId>lucene-queryparser</artifactId>
|
<artifactId>lucene-queryparser</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Only there to read old index and rebuild them -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.lucene</groupId>
|
||||||
|
<artifactId>lucene-backward-codecs</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.imgscalr</groupId>
|
<groupId>org.imgscalr</groupId>
|
||||||
<artifactId>imgscalr-lib</artifactId>
|
<artifactId>imgscalr-lib</artifactId>
|
||||||
|
@ -9,9 +9,9 @@ import org.apache.lucene.index.CheckIndex.Status;
|
|||||||
import org.apache.lucene.index.CheckIndex.Status.SegmentInfoStatus;
|
import org.apache.lucene.index.CheckIndex.Status.SegmentInfoStatus;
|
||||||
import org.apache.lucene.index.DirectoryReader;
|
import org.apache.lucene.index.DirectoryReader;
|
||||||
import org.apache.lucene.store.Directory;
|
import org.apache.lucene.store.Directory;
|
||||||
|
import org.apache.lucene.store.NoLockFactory;
|
||||||
import org.apache.lucene.store.RAMDirectory;
|
import org.apache.lucene.store.RAMDirectory;
|
||||||
import org.apache.lucene.store.SimpleFSDirectory;
|
import org.apache.lucene.store.SimpleFSDirectory;
|
||||||
import org.apache.lucene.store.SingleInstanceLockFactory;
|
|
||||||
import org.apache.lucene.util.Version;
|
import org.apache.lucene.util.Version;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@ -63,29 +63,35 @@ public class IndexingService extends AbstractScheduledService {
|
|||||||
Path luceneDirectory = DirectoryUtil.getLuceneDirectory();
|
Path luceneDirectory = DirectoryUtil.getLuceneDirectory();
|
||||||
log.info("Using file Lucene storage: {}", luceneDirectory);
|
log.info("Using file Lucene storage: {}", luceneDirectory);
|
||||||
try {
|
try {
|
||||||
directory = new SimpleFSDirectory(luceneDirectory, new SingleInstanceLockFactory());
|
directory = new SimpleFSDirectory(luceneDirectory, NoLockFactory.INSTANCE);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.error("Error initializing Lucene index", e);
|
log.error("Error initializing Lucene index", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check index version and rebuild it if necessary
|
// Check index version and rebuild it if necessary
|
||||||
log.info("Checking index health and version");
|
try {
|
||||||
try (CheckIndex checkIndex = new CheckIndex(directory)) {
|
if (DirectoryReader.indexExists(directory)) {
|
||||||
Status status = checkIndex.checkIndex();
|
log.info("Checking index health and version");
|
||||||
if (status.clean) {
|
try (CheckIndex checkIndex = new CheckIndex(directory)) {
|
||||||
for (SegmentInfoStatus segmentInfo : status.segmentInfos) {
|
Status status = checkIndex.checkIndex();
|
||||||
if (!segmentInfo.version.onOrAfter(Version.LATEST)) {
|
if (status.clean) {
|
||||||
|
for (SegmentInfoStatus segmentInfo : status.segmentInfos) {
|
||||||
|
if (!segmentInfo.version.onOrAfter(Version.LATEST)) {
|
||||||
|
log.info("Index is old (" + segmentInfo.version + "), rebuilding");
|
||||||
|
RebuildIndexAsyncEvent rebuildIndexAsyncEvent = new RebuildIndexAsyncEvent();
|
||||||
|
AppContext.getInstance().getAsyncEventBus().post(rebuildIndexAsyncEvent);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.info("Index is dirty, rebuilding");
|
||||||
RebuildIndexAsyncEvent rebuildIndexAsyncEvent = new RebuildIndexAsyncEvent();
|
RebuildIndexAsyncEvent rebuildIndexAsyncEvent = new RebuildIndexAsyncEvent();
|
||||||
AppContext.getInstance().getAsyncEventBus().post(rebuildIndexAsyncEvent);
|
AppContext.getInstance().getAsyncEventBus().post(rebuildIndexAsyncEvent);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
RebuildIndexAsyncEvent rebuildIndexAsyncEvent = new RebuildIndexAsyncEvent();
|
|
||||||
AppContext.getInstance().getAsyncEventBus().post(rebuildIndexAsyncEvent);
|
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (Exception e) {
|
||||||
log.error("Error checking index", e);
|
log.error("Error checking index", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,9 @@ public class LuceneUtil {
|
|||||||
// Standard analyzer
|
// Standard analyzer
|
||||||
IndexWriterConfig config = new IndexWriterConfig(new StandardAnalyzer());
|
IndexWriterConfig config = new IndexWriterConfig(new StandardAnalyzer());
|
||||||
|
|
||||||
|
// Automatically commit when closing this writer
|
||||||
|
config.setCommitOnClose(true);
|
||||||
|
|
||||||
// Merge sequentially, because Lucene writing is already done asynchronously
|
// Merge sequentially, because Lucene writing is already done asynchronously
|
||||||
config.setMergeScheduler(new SerialMergeScheduler());
|
config.setMergeScheduler(new SerialMergeScheduler());
|
||||||
|
|
||||||
@ -59,7 +62,7 @@ public class LuceneUtil {
|
|||||||
try {
|
try {
|
||||||
indexWriter.close();
|
indexWriter.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.error("Cannot close IndexWriter", e);
|
log.error("Cannot commit and close IndexWriter", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -339,6 +339,12 @@
|
|||||||
<version>${org.apache.lucene.version}</version>
|
<version>${org.apache.lucene.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.lucene</groupId>
|
||||||
|
<artifactId>lucene-backward-codecs</artifactId>
|
||||||
|
<version>${org.apache.lucene.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.imgscalr</groupId>
|
<groupId>org.imgscalr</groupId>
|
||||||
<artifactId>imgscalr-lib</artifactId>
|
<artifactId>imgscalr-lib</artifactId>
|
||||||
|
Loading…
Reference in New Issue
Block a user