diff --git a/lucene/src/main/java/com/orientechnologies/lucene/engine/OLuceneIndexEngineAbstract.java b/lucene/src/main/java/com/orientechnologies/lucene/engine/OLuceneIndexEngineAbstract.java index 4629cdc019f..7338fe99c14 100644 --- a/lucene/src/main/java/com/orientechnologies/lucene/engine/OLuceneIndexEngineAbstract.java +++ b/lucene/src/main/java/com/orientechnologies/lucene/engine/OLuceneIndexEngineAbstract.java @@ -249,6 +249,9 @@ protected ODatabaseDocumentInternal getDatabase() { private synchronized void open() throws IOException { + if (!closed.get()) + return; + OLuceneDirectoryFactory directoryFactory = new OLuceneDirectoryFactory(); directory = directoryFactory.createDirectory(getDatabase(), name, metadata); @@ -296,6 +299,7 @@ private void closeSearchManager() throws IOException { private void commitAndCloseWriter() throws IOException { if (mgrWriter != null && mgrWriter.getIndexWriter().isOpen()) { + OLogManager.instance().info(this, "commiting ad closing"); mgrWriter.getIndexWriter().commit(); mgrWriter.getIndexWriter().close(); closed.set(true); @@ -519,15 +523,17 @@ public synchronized void close() { return; try { - OLogManager.instance().debug(this, "Closing Lucene index '" + this.name + "'..."); +// OLogManager.instance().info(this, "Closing Lucene index '" + this.name + "'..."); closeNRT(); - cancelCommitTask(); - closeSearchManager(); commitAndCloseWriter(); + +// OLogManager.instance().info(this, "Closed Lucene index '" + this.name); + cancelCommitTask(); + } catch (Throwable e) { OLogManager.instance().error(this, "Error on closing Lucene index", e); } diff --git a/lucene/src/test/java/com/orientechnologies/lucene/integration/OLuceneIndexCrashRestoreIT.java b/lucene/src/test/java/com/orientechnologies/lucene/integration/OLuceneIndexCrashRestoreIT.java index e945898822a..a07a42c7a0f 100755 --- a/lucene/src/test/java/com/orientechnologies/lucene/integration/OLuceneIndexCrashRestoreIT.java +++ b/lucene/src/test/java/com/orientechnologies/lucene/integration/OLuceneIndexCrashRestoreIT.java @@ -11,7 +11,10 @@ import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery; import com.orientechnologies.orient.server.OServer; import com.orientechnologies.orient.server.OServerMain; -import org.junit.*; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; import java.io.File; import java.io.InputStream; @@ -77,16 +80,18 @@ public void spawnServer() throws Exception { "-classpath", System.getProperty("java.class.path"), "-DmutexFile=" + mutexFile.getAbsolutePath(), +// "-Djava.util.logging.config.file=" + new File("../server/config/orientdb-server-log.properties").getAbsolutePath(), "-DORIENTDB_HOME=" + buildDirectory, RemoteDBRunner.class.getName()); // processBuilder.inheritIO(); + processBuilder.inheritIO(); serverProcess = processBuilder.start(); - System.out.println(": Wait for server start"); boolean started = false; do { + System.out.println(": Wait for server start"); TimeUnit.SECONDS.sleep(5); mutex.seek(0); started = mutex.read() == 1; @@ -105,19 +110,41 @@ public void tearDown() { } @Test - @Ignore +// @Ignore public void testEntriesAddition() throws Exception { createSchema(testDocumentTx); - System.out.println("Start data propagation"); + //first round + System.out.println("Start data propagation 1"); - List futures = new ArrayList(); - for (int i = 0; i < 4; i++) { - futures.add(executorService.submit(new DataPropagationTask(testDocumentTx))); - } + List futures = startLoaders(); + + System.out.println("Wait for 1 minutes"); + TimeUnit.MINUTES.sleep(1); + + System.out.println("stop loaders"); + stopLoaders(futures); + + System.out.println("Wait for 1 minutes"); + TimeUnit.MINUTES.sleep(1); + +//second round + System.out.println("Start data propagation 2"); + + futures = startLoaders(); + + System.out.println("Wait for 1 minutes"); + TimeUnit.MINUTES.sleep(1); - System.out.println("Wait for 5 minutes"); - TimeUnit.SECONDS.sleep(5); + System.out.println("stop loaders"); + stopLoaders(futures); + + System.out.println("Wait for 1 minutes"); + TimeUnit.MINUTES.sleep(1); + + System.out.println("Start data propagation 3"); + + futures = startLoaders(); //test query // verify that the keyword analyzer is doing is job @@ -144,13 +171,7 @@ public void testEntriesAddition() throws Exception { System.out.println("Process was CRASHED"); //stop data pumpers - for (Future future : futures) { - try { - future.get(); - } catch (Exception e) { - future.cancel(true); - } - } + stopLoaders(futures); System.out.println("All loaders done"); @@ -201,6 +222,25 @@ public void testEntriesAddition() throws Exception { } + private void stopLoaders(List futures) { + for (Future future : futures) { + try { + future.cancel(true); + } catch (Exception e) { + future.cancel(true); + } + } + } + + private List startLoaders() { + List futures = new ArrayList(); + for (int i = 0; i < 4; i++) { + final DataPropagationTask loader = new DataPropagationTask(testDocumentTx); + futures.add(executorService.submit(loader)); + } + return futures; + } + private void createSchema(ODatabaseDocumentTx db) { db.activateOnCurrentThread(); @@ -260,6 +300,11 @@ public Void call() throws Exception { System.out.println(Thread.currentThread().getName() + " inserted:: " + id); testDB.commit(); } + if (id % 2000 == 0) { + System.out.println("Deleting roberts"); + testDB.command(new OCommandSQL("delete from Person where name lucene 'Robert' ")).execute(); + testDB.commit(); + } int nameIdx = (int) (id % names.size()); ODatabaseRecordThreadLocal.INSTANCE.set(testDB);