Skip to content

Commit

Permalink
reviews of sync in case of MT access phase 2
Browse files Browse the repository at this point in the history
refs #7555
  • Loading branch information
robfrank committed Jul 20, 2017
1 parent 75990f0 commit e389d10
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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<Future> futures = new ArrayList<Future>();
for (int i = 0; i < 4; i++) {
futures.add(executorService.submit(new DataPropagationTask(testDocumentTx)));
}
List<Future> 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
Expand All @@ -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");

Expand Down Expand Up @@ -201,6 +222,25 @@ public void testEntriesAddition() throws Exception {

}

private void stopLoaders(List<Future> futures) {
for (Future future : futures) {
try {
future.cancel(true);
} catch (Exception e) {
future.cancel(true);
}
}
}

private List<Future> startLoaders() {
List<Future> futures = new ArrayList<Future>();
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();

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit e389d10

Please sign in to comment.