diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/search/FullTextIndexUpdater.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/search/FullTextIndexUpdater.java index e91ff1d8085991b756996fa513a11f9e55971605..7670a4914a91ef897354b6ef7e2647fd25181000 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/search/FullTextIndexUpdater.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/search/FullTextIndexUpdater.java @@ -25,6 +25,7 @@ import org.hibernate.SessionFactory; import org.springframework.orm.hibernate3.support.HibernateDaoSupport; import ch.systemsx.cisd.common.collections.ExtendedBlockingQueueFactory; +import ch.systemsx.cisd.common.collections.ExtendedLinkedBlockingQueue; import ch.systemsx.cisd.common.collections.IExtendedBlockingQueue; import ch.systemsx.cisd.common.logging.LogCategory; import ch.systemsx.cisd.common.logging.LogFactory; @@ -59,18 +60,48 @@ public final class FullTextIndexUpdater extends HibernateDaoSupport implements this.context = context; operationLog.debug(String.format("Hibernate search context: %s.", context)); fullTextIndexer = new DefaultFullTextIndexer(context.getBatchSize()); - File queueFile = getUpdaterQueueFile(context); + + final IndexMode indexMode = context.getIndexMode(); + if (indexMode == IndexMode.NO_INDEX) + { + // don't use persistent queue e.g. in tests to avoid problems (see SE-286) + operationLog.info(String.format( + "'%s' mode was configured. Updater tasks will not be persisted", indexMode)); + updaterQueue = new ExtendedLinkedBlockingQueue<IndexUpdateOperation>(); + return; + } + + final File indexBase = new File(context.getIndexBase()); + final File queueFile = getUpdaterQueueFile(indexBase); operationLog.debug(String.format("Updater queue file: %s.", queueFile)); - updaterQueue = - ExtendedBlockingQueueFactory - .<IndexUpdateOperation> createPersistRecordBased(queueFile); + updaterQueue = createUpdaterQueue(indexBase, queueFile); } - private static File getUpdaterQueueFile(HibernateSearchContext context) + private static IExtendedBlockingQueue<IndexUpdateOperation> createUpdaterQueue( + final File indexBase, final File queueFile) { - final File indexBase = new File(context.getIndexBase()); - final File queueFile = new File(indexBase, FULL_TEXT_INDEX_UPDATER_QUEUE_FILENAME); - return queueFile; + try + { + return ExtendedBlockingQueueFactory + .<IndexUpdateOperation> createPersistRecordBased(queueFile); + } catch (RuntimeException e) + { + // don't fail if e.g. deserialization of the queue fails (see SE-286) + String newFileName = + FULL_TEXT_INDEX_UPDATER_QUEUE_FILENAME + "_" + System.currentTimeMillis(); + notificationLog.error(String.format("%s.\n " + + "Renaming '%s' to '%s' and using an empty queue file. " + + "Restart server with the queue that caused the problem " + + "or force reindex of all entities.", e.getMessage(), queueFile, newFileName)); + queueFile.renameTo(new File(indexBase, newFileName)); + return ExtendedBlockingQueueFactory + .<IndexUpdateOperation> createPersistRecordBased(queueFile); + } + } + + private static File getUpdaterQueueFile(File indexBase) + { + return new File(indexBase, FULL_TEXT_INDEX_UPDATER_QUEUE_FILENAME); } public void start() @@ -133,16 +164,17 @@ public final class FullTextIndexUpdater extends HibernateDaoSupport implements Session session = null; try { + final Class<?> clazz = Class.forName(operation.getClassName()); session = getSession(); switch (operation.getOperationKind()) { case REINDEX: - fullTextIndexer.doFullTextIndexUpdate(getSession(), operation - .getClazz(), operation.getIds()); + fullTextIndexer.doFullTextIndexUpdate(getSession(), clazz, + operation.getIds()); break; case REMOVE: - fullTextIndexer.removeFromIndex(getSession(), operation.getClazz(), - operation.getIds()); + fullTextIndexer.removeFromIndex(getSession(), clazz, operation + .getIds()); } stopWatch.stop(); } catch (RuntimeException e) @@ -154,12 +186,12 @@ public final class FullTextIndexUpdater extends HibernateDaoSupport implements { releaseSession(session); } - } - if (operationLog.isInfoEnabled()) - { - operationLog.info(operation.getOperationKind() + " of " - + operation.getIds().size() + " " - + operation.getClazz().getSimpleName() + "s took " + stopWatch); + if (operationLog.isInfoEnabled()) + { + operationLog.info(operation.getOperationKind() + " of " + + operation.getIds().size() + " " + operation.getClassName() + + "s took " + stopWatch); + } } updaterQueue.take(); } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/search/IndexUpdateOperation.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/search/IndexUpdateOperation.java index d2f52663004b001aa19bf15ac0bc9bc868bd2324..178710761385bcc8892d5eb61230554c9690734e 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/search/IndexUpdateOperation.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/search/IndexUpdateOperation.java @@ -37,9 +37,10 @@ public class IndexUpdateOperation implements Serializable REMOVE } - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 2L; - private final Class<?> clazz; + // we don't store Class<?> not to cause problems with deserialization + private final String className; private final List<Long> ids; @@ -58,14 +59,14 @@ public class IndexUpdateOperation implements Serializable private IndexUpdateOperation(IndexUpdateOperationKind operationKind, Class<?> clazz, List<Long> ids) { - this.clazz = clazz; + this.className = clazz.getName(); this.ids = ids; this.operationKind = operationKind; } - public Class<?> getClazz() + public String getClassName() { - return clazz; + return className; } public List<Long> getIds() @@ -81,7 +82,7 @@ public class IndexUpdateOperation implements Serializable @Override public String toString() { - return operationKind + " " + clazz.getName() + ": " + CollectionUtils.abbreviate(ids, 10); + return operationKind + " " + className + ": " + CollectionUtils.abbreviate(ids, 10); } } diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/SampleDAOTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/SampleDAOTest.java index 4a9014245f897f3336d79ce3dc69c2d595844040..44a8accda2da19ee888efbc2740e318295a590d4 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/SampleDAOTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/SampleDAOTest.java @@ -56,7 +56,6 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.EventPE.EntityType; import ch.systemsx.cisd.openbis.generic.shared.dto.properties.EntityKind; import ch.systemsx.cisd.openbis.generic.shared.util.HibernateUtils; -// FIXME 2010-07-24, Piotr Buczek: fix broken tests /** * Test cases for corresponding {@link SampleDAO} class. * @@ -287,7 +286,6 @@ public final class SampleDAOTest extends AbstractDAOTest return sample; } - @Test(groups = "broken") public final void testDeleteWithParentAndExperimentPreserved() { final ISampleDAO sampleDAO = daoFactory.getSampleDAO(); @@ -343,7 +341,6 @@ public final class SampleDAOTest extends AbstractDAOTest return eventDAO.tryFind(sample.getPermId(), EntityType.SAMPLE, EventType.DELETION); } - @Test(groups = "broken") public final void testDeleteWithProperties() { final ISampleDAO sampleDAO = daoFactory.getSampleDAO();