From b54debe2e5edcad2e889d5553e87515509eb73cf Mon Sep 17 00:00:00 2001 From: Benjamin Gamard Date: Sat, 31 Mar 2018 11:01:27 +0200 Subject: [PATCH] handle index rebuilding --- .../sismics/docs/core/model/context/AppContext.java | 13 +++++++++++-- .../core/util/indexing/LuceneIndexingHandler.java | 11 ++--------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/docs-core/src/main/java/com/sismics/docs/core/model/context/AppContext.java b/docs-core/src/main/java/com/sismics/docs/core/model/context/AppContext.java index 0cb4a024..be42ed39 100644 --- a/docs-core/src/main/java/com/sismics/docs/core/model/context/AppContext.java +++ b/docs-core/src/main/java/com/sismics/docs/core/model/context/AppContext.java @@ -4,6 +4,7 @@ import com.google.common.eventbus.AsyncEventBus; import com.google.common.eventbus.EventBus; import com.sismics.docs.core.constant.Constants; import com.sismics.docs.core.dao.UserDao; +import com.sismics.docs.core.event.RebuildIndexAsyncEvent; import com.sismics.docs.core.listener.async.*; import com.sismics.docs.core.model.jpa.User; import com.sismics.docs.core.service.InboxService; @@ -11,6 +12,8 @@ import com.sismics.docs.core.util.PdfUtil; import com.sismics.docs.core.util.indexing.IndexingHandler; import com.sismics.docs.core.util.indexing.LuceneIndexingHandler; import com.sismics.util.EnvironmentUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.ArrayList; import java.util.List; @@ -25,6 +28,11 @@ import java.util.concurrent.TimeUnit; * @author jtremeaux */ public class AppContext { + /** + * Logger. + */ + private static final Logger log = LoggerFactory.getLogger(AppContext.class); + /** * Singleton instance. */ @@ -66,8 +74,9 @@ public class AppContext { try { indexingHandler.startUp(); } catch (Exception e) { - // Blocking error, the app will not start - throw new RuntimeException(e); + log.error("Error starting the indexing handler, rebuilding the index", e); + RebuildIndexAsyncEvent rebuildIndexAsyncEvent = new RebuildIndexAsyncEvent(); + asyncEventBus.post(rebuildIndexAsyncEvent); } // Start inbox service diff --git a/docs-core/src/main/java/com/sismics/docs/core/util/indexing/LuceneIndexingHandler.java b/docs-core/src/main/java/com/sismics/docs/core/util/indexing/LuceneIndexingHandler.java index ffdc255f..1c3e8770 100644 --- a/docs-core/src/main/java/com/sismics/docs/core/util/indexing/LuceneIndexingHandler.java +++ b/docs-core/src/main/java/com/sismics/docs/core/util/indexing/LuceneIndexingHandler.java @@ -7,8 +7,6 @@ import com.sismics.docs.core.constant.ConfigType; import com.sismics.docs.core.dao.ConfigDao; import com.sismics.docs.core.dao.criteria.DocumentCriteria; import com.sismics.docs.core.dao.dto.DocumentDto; -import com.sismics.docs.core.event.RebuildIndexAsyncEvent; -import com.sismics.docs.core.model.context.AppContext; import com.sismics.docs.core.model.jpa.Config; import com.sismics.docs.core.model.jpa.Document; import com.sismics.docs.core.model.jpa.File; @@ -85,16 +83,11 @@ public class LuceneIndexingHandler implements IndexingHandler { if (status.clean) { for (CheckIndex.Status.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; + throw new Exception("Index is old (" + segmentInfo.version + ")"); } } } else { - log.info("Index is dirty, rebuilding"); - RebuildIndexAsyncEvent rebuildIndexAsyncEvent = new RebuildIndexAsyncEvent(); - AppContext.getInstance().getAsyncEventBus().post(rebuildIndexAsyncEvent); + throw new Exception("Index is dirty"); } } }