Skip to content

Commit

Permalink
PrjHub issue #9735 is fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
laa committed Apr 18, 2018
1 parent db429bd commit a7e8adb
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 38 deletions.
Expand Up @@ -167,8 +167,8 @@ public abstract class OAbstractPaginatedStorage extends OStorageAbstract
private final List<OCluster> clusters = new ArrayList<>();

private volatile ThreadLocal<OStorageTransaction> transaction;
private final AtomicBoolean checkpointInProgress = new AtomicBoolean();
private final AtomicBoolean walVacuumInProgress = new AtomicBoolean();
private final AtomicBoolean checkpointInProgress = new AtomicBoolean();
private final AtomicBoolean walVacuumInProgress = new AtomicBoolean();

/**
* Error which happened inside of storage or during data processing related to this storage.
Expand All @@ -191,16 +191,16 @@ public abstract class OAbstractPaginatedStorage extends OStorageAbstract
private volatile ORecordConflictStrategy recordConflictStrategy = Orient.instance().getRecordConflictStrategy()
.getDefaultImplementation();

private volatile int defaultClusterId = -1;
private volatile int defaultClusterId = -1;
@SuppressWarnings("WeakerAccess")
protected volatile OAtomicOperationsManager atomicOperationsManager;
private volatile boolean wereNonTxOperationsPerformedInPreviousOpen = false;
private volatile OLowDiskSpaceInformation lowDiskSpace = null;
private volatile boolean pessimisticLock = false;
private volatile boolean wereNonTxOperationsPerformedInPreviousOpen = false;
private volatile OLowDiskSpaceInformation lowDiskSpace = null;
private volatile boolean pessimisticLock = false;
/**
* Set of pages which were detected as broken and need to be repaired.
*/
private final Set<OPair<String, Long>> brokenPages = Collections
private final Set<OPair<String, Long>> brokenPages = Collections
.newSetFromMap(new ConcurrentHashMap<>());

protected volatile OScheduledThreadPoolExecutorWithLogging fuzzyCheckpointExecutor;
Expand Down Expand Up @@ -2067,6 +2067,7 @@ private List<ORecordOperation> commit(final OTransactionInternal transaction, bo
this.transaction.set(null);
}
} finally {
atomicOperationsManager.ensureThatComponentsUnlocked();
database.getMetadata().clearThreadLocalSchemaSnapshot();
}
} finally {
Expand Down
Expand Up @@ -365,6 +365,9 @@ public OLogSequenceNumber endAtomicOperation(boolean rollback, Exception excepti
operation.rollback(exception);
}

final int counter = operation.getCounter();
assert counter > 0;

if (operation.isRollback() && !rollback) {
final StringWriter writer = new StringWriter();
writer.append("Atomic operation was rolled back by internal component");
Expand All @@ -376,13 +379,21 @@ public OLogSequenceNumber endAtomicOperation(boolean rollback, Exception excepti

atomicOperationsCount.decrement();

operation.decrementCounter();

if (counter == 1) {
for (String lockObject : operation.lockedObjects()) {
lockManager.releaseLock(this, lockObject, OOneEntryPerKeyLockManager.LOCK.EXCLUSIVE);
}

currentOperation.set(null);
}


final ONestedRollbackException nre = new ONestedRollbackException(writer.toString());
throw OException.wrapException(nre, exception);
}

final int counter = operation.getCounter();
assert counter > 0;

final OLogSequenceNumber lsn;
if (counter == 1) {
try {
Expand Down Expand Up @@ -423,6 +434,15 @@ public OLogSequenceNumber endAtomicOperation(boolean rollback, Exception excepti
return lsn;
}

public void ensureThatComponentsUnlocked() {
final OAtomicOperation operation = currentOperation.get();
if (operation != null) {
for (String lockObject : operation.lockedObjects()) {
lockManager.releaseLock(this, lockObject, OOneEntryPerKeyLockManager.LOCK.EXCLUSIVE);
}
}
}

/**
* Acquires exclusive lock with the given lock name in the given atomic operation.
*
Expand Down
66 changes: 38 additions & 28 deletions .../src/test/java/com/orientechnologies/spatial/LuceneSpatialAutomaticBackupRestoreTest.java 100644 → 100755
Expand Up @@ -18,6 +18,7 @@

package com.orientechnologies.spatial;

import com.orientechnologies.common.io.OFileUtils;
import com.orientechnologies.common.io.OIOUtils;
import com.orientechnologies.orient.core.command.OCommandOutputListener;
import com.orientechnologies.orient.core.db.ODatabaseDocumentInternal;
Expand All @@ -32,12 +33,16 @@
import com.orientechnologies.orient.server.OServer;
import com.orientechnologies.orient.server.config.OServerParameterConfiguration;
import com.orientechnologies.orient.server.handler.OAutomaticBackup;
import com.sun.jna.Platform;
import org.junit.*;
import org.junit.rules.TemporaryFolder;
import org.junit.rules.TestName;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.CountDownLatch;
Expand All @@ -50,19 +55,30 @@
*/
public class LuceneSpatialAutomaticBackupRestoreTest {

private final static String DBNAME = "OLuceneAutomaticBackupRestoreTest";
@Rule
public TemporaryFolder tempFolder = new TemporaryFolder();
private final static String DBNAME = "OLuceneAutomaticBackupRestoreTest";

public File tempFolder;
private OrientDB orientDB;
private String URL = null;
private String BACKUPDIR = null;
private String BACKUFILE = null;
private String URL = null;
private String BACKUPDIR = null;
private String BACKUFILE = null;

private OServer server;
private ODatabaseDocumentInternal db;

@Rule
public TestName name = new TestName();

@Before
public void setUp() throws Exception {
Assume.assumeFalse(Platform.isWindows());

final String buildDirectory = System.getProperty("buildDirectory", "target");
final File buildDirectoryFile = new File(buildDirectory);

tempFolder = new File(buildDirectoryFile, name.getMethodName());
OFileUtils.deleteRecursively(tempFolder);
Assert.assertTrue(tempFolder.mkdirs());

server = new OServer() {
@Override
Expand All @@ -74,18 +90,19 @@ public Map<String, String> getAvailableStorageNames() {
};
server.startup();

System.setProperty("ORIENTDB_HOME", tempFolder.getRoot().getAbsolutePath());
System.setProperty("ORIENTDB_HOME", tempFolder.getAbsolutePath());

String path = tempFolder.getRoot().getAbsolutePath() + File.separator + "databases";
String path = tempFolder.getAbsolutePath() + File.separator + "databases";
orientDB = server.getContext();

URL = "plocal:" + path + File.separator + DBNAME;

BACKUPDIR = tempFolder.getRoot().getAbsolutePath() + File.separator + "backups";
BACKUPDIR = tempFolder.getAbsolutePath() + File.separator + "backups";

BACKUFILE = BACKUPDIR + File.separator + DBNAME;

tempFolder.newFolder("config");
final File config = new File(tempFolder, "config");
Assert.assertTrue(config.mkdirs());

dropIfExists();

Expand Down Expand Up @@ -127,10 +144,11 @@ private void dropIfExists() {

@After
public void tearDown() throws Exception {
dropIfExists();

tempFolder.delete();
if (!Platform.isWindows()) {
dropIfExists();

tempFolder.delete();
}
}

@Test
Expand All @@ -145,15 +163,11 @@ public void shouldBackupAndRestore() throws IOException, InterruptedException {

String jsonConfig = OIOUtils.readStreamAsString(getClass().getClassLoader().getResourceAsStream("automatic-backup.json"));

ODocument doc = new ODocument()
.fromJSON(jsonConfig)
.field("enabled", true)
.field("targetFileName", "${DBNAME}.zip")
.field("targetDirectory", BACKUPDIR)
.field("dbInclude", new String[] { DBNAME })
ODocument doc = new ODocument().fromJSON(jsonConfig).field("enabled", true).field("targetFileName", "${DBNAME}.zip")
.field("targetDirectory", BACKUPDIR).field("dbInclude", new String[] { DBNAME })
.field("firstTime", new SimpleDateFormat("HH:mm:ss").format(new Date(System.currentTimeMillis() + 2000)));

OIOUtils.writeFile(new File(tempFolder.getRoot().getAbsolutePath() + "/config/automatic-backup.json"), doc.toJSON());
OIOUtils.writeFile(new File(tempFolder.getAbsolutePath() + "/config/automatic-backup.json"), doc.toJSON());

final OAutomaticBackup aBackup = new OAutomaticBackup();

Expand Down Expand Up @@ -218,15 +232,11 @@ public void shouldExportImport() throws IOException, InterruptedException {

String jsonConfig = OIOUtils.readStreamAsString(getClass().getClassLoader().getResourceAsStream("automatic-backup.json"));

ODocument doc = new ODocument()
.fromJSON(jsonConfig)
.field("enabled", true)
.field("targetFileName", "${DBNAME}.json")
.field("targetDirectory", BACKUPDIR).field("mode", "EXPORT")
.field("dbInclude", new String[] { DBNAME })
ODocument doc = new ODocument().fromJSON(jsonConfig).field("enabled", true).field("targetFileName", "${DBNAME}.json")
.field("targetDirectory", BACKUPDIR).field("mode", "EXPORT").field("dbInclude", new String[] { DBNAME })
.field("firstTime", new SimpleDateFormat("HH:mm:ss").format(new Date(System.currentTimeMillis() + 2000)));

OIOUtils.writeFile(new File(tempFolder.getRoot().getAbsolutePath() + "/config/automatic-backup.json"), doc.toJSON());
OIOUtils.writeFile(new File(tempFolder.getAbsolutePath() + "/config/automatic-backup.json"), doc.toJSON());

final OAutomaticBackup aBackup = new OAutomaticBackup();

Expand Down

0 comments on commit a7e8adb

Please sign in to comment.