handle index rebuilding

This commit is contained in:
Benjamin Gamard 2018-03-31 11:01:27 +02:00
parent 95ce4f0dc0
commit b54debe2e5
2 changed files with 13 additions and 11 deletions

View File

@ -4,6 +4,7 @@ import com.google.common.eventbus.AsyncEventBus;
import com.google.common.eventbus.EventBus; import com.google.common.eventbus.EventBus;
import com.sismics.docs.core.constant.Constants; import com.sismics.docs.core.constant.Constants;
import com.sismics.docs.core.dao.UserDao; 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.listener.async.*;
import com.sismics.docs.core.model.jpa.User; import com.sismics.docs.core.model.jpa.User;
import com.sismics.docs.core.service.InboxService; 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.IndexingHandler;
import com.sismics.docs.core.util.indexing.LuceneIndexingHandler; import com.sismics.docs.core.util.indexing.LuceneIndexingHandler;
import com.sismics.util.EnvironmentUtil; import com.sismics.util.EnvironmentUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -25,6 +28,11 @@ import java.util.concurrent.TimeUnit;
* @author jtremeaux * @author jtremeaux
*/ */
public class AppContext { public class AppContext {
/**
* Logger.
*/
private static final Logger log = LoggerFactory.getLogger(AppContext.class);
/** /**
* Singleton instance. * Singleton instance.
*/ */
@ -66,8 +74,9 @@ public class AppContext {
try { try {
indexingHandler.startUp(); indexingHandler.startUp();
} catch (Exception e) { } catch (Exception e) {
// Blocking error, the app will not start log.error("Error starting the indexing handler, rebuilding the index", e);
throw new RuntimeException(e); RebuildIndexAsyncEvent rebuildIndexAsyncEvent = new RebuildIndexAsyncEvent();
asyncEventBus.post(rebuildIndexAsyncEvent);
} }
// Start inbox service // Start inbox service

View File

@ -7,8 +7,6 @@ import com.sismics.docs.core.constant.ConfigType;
import com.sismics.docs.core.dao.ConfigDao; import com.sismics.docs.core.dao.ConfigDao;
import com.sismics.docs.core.dao.criteria.DocumentCriteria; import com.sismics.docs.core.dao.criteria.DocumentCriteria;
import com.sismics.docs.core.dao.dto.DocumentDto; 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.Config;
import com.sismics.docs.core.model.jpa.Document; import com.sismics.docs.core.model.jpa.Document;
import com.sismics.docs.core.model.jpa.File; import com.sismics.docs.core.model.jpa.File;
@ -85,16 +83,11 @@ public class LuceneIndexingHandler implements IndexingHandler {
if (status.clean) { if (status.clean) {
for (CheckIndex.Status.SegmentInfoStatus segmentInfo : status.segmentInfos) { for (CheckIndex.Status.SegmentInfoStatus segmentInfo : status.segmentInfos) {
if (!segmentInfo.version.onOrAfter(Version.LATEST)) { if (!segmentInfo.version.onOrAfter(Version.LATEST)) {
log.info("Index is old (" + segmentInfo.version + "), rebuilding"); throw new Exception("Index is old (" + segmentInfo.version + ")");
RebuildIndexAsyncEvent rebuildIndexAsyncEvent = new RebuildIndexAsyncEvent();
AppContext.getInstance().getAsyncEventBus().post(rebuildIndexAsyncEvent);
break;
} }
} }
} else { } else {
log.info("Index is dirty, rebuilding"); throw new Exception("Index is dirty");
RebuildIndexAsyncEvent rebuildIndexAsyncEvent = new RebuildIndexAsyncEvent();
AppContext.getInstance().getAsyncEventBus().post(rebuildIndexAsyncEvent);
} }
} }
} }