use of com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage in project orientdb by orientechnologies.
the class OTransactionAbstract method unlockRecord.
@Override
public OTransaction unlockRecord(final OIdentifiable iRecord) {
final OStorage stg = database.getStorage();
if (!(stg.getUnderlying() instanceof OAbstractPaginatedStorage))
throw new OLockException("Cannot lock record across remote connections");
final ORID rid = iRecord.getIdentity();
final LockedRecordMetadata lockedRecordMetadata = locks.get(rid);
if (lockedRecordMetadata == null || lockedRecordMetadata.locksCount == 0)
throw new OLockException("Cannot unlock a never acquired lock");
else if (lockedRecordMetadata.strategy == OStorage.LOCKING_STRATEGY.EXCLUSIVE_LOCK)
((OAbstractPaginatedStorage) stg.getUnderlying()).releaseWriteLock(rid);
else if (lockedRecordMetadata.strategy == OStorage.LOCKING_STRATEGY.SHARED_LOCK)
((OAbstractPaginatedStorage) stg.getUnderlying()).releaseReadLock(rid);
else
throw new IllegalStateException("Unsupported locking strategy " + lockedRecordMetadata.strategy);
lockedRecordMetadata.locksCount--;
if (lockedRecordMetadata.locksCount == 0)
locks.remove(rid);
return this;
}
use of com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage in project orientdb by orientechnologies.
the class ConcurrencySBTreeBonsaiLocalTest method testName.
@Test
public void testName() throws Exception {
ODatabaseDocumentTx db = new ODatabaseDocumentTx("memory:" + ConcurrencySBTreeBonsaiLocalTest.class.getName());
db.create();
ExecutorService exec = Executors.newCachedThreadPool();
try {
OSBTreeCollectionManager coll = db.getSbTreeCollectionManager();
OBonsaiCollectionPointer treePointer = coll.createSBTree(3, null);
OSBTreeBonsaiLocal<OIdentifiable, Integer> tree = (OSBTreeBonsaiLocal<OIdentifiable, Integer>) coll.loadSBTree(treePointer);
OBonsaiCollectionPointer treePointer1 = coll.createSBTree(3, null);
final OSBTreeBonsaiLocal<OIdentifiable, Integer> tree1 = (OSBTreeBonsaiLocal<OIdentifiable, Integer>) coll.loadSBTree(treePointer1);
final OAtomicOperationsManager atomManager = ((OAbstractPaginatedStorage) db.getStorage()).getAtomicOperationsManager();
atomManager.startAtomicOperation(tree, false);
for (int i = 1000; i < 2000; i++) tree.put(new ORecordId(10, i), 1);
Future<?> ex = null;
try {
ex = exec.submit(new Runnable() {
@Override
public void run() {
try {
atomManager.startAtomicOperation(tree1, false);
for (int i = 2000; i < 3000; i++) tree1.put(new ORecordId(10, i), 1);
atomManager.endAtomicOperation(false, null, tree1);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
});
ex.get(10, TimeUnit.MILLISECONDS);
} catch (TimeoutException e) {
// Is supposed to go in deadlock correct that goes in timeout
}
atomManager.endAtomicOperation(false, null, tree);
ex.get();
OSBTreeRidBag bag = new OSBTreeRidBag();
bag.setCollectionPointer(tree.getCollectionPointer());
bag.setAutoConvertToRecord(false);
Assert.assertEquals(tree.size(), 1000);
for (OIdentifiable id : bag) {
if (id.getIdentity().getClusterPosition() > 2000)
Assert.fail("found a wrong rid in the ridbag");
}
OSBTreeRidBag secondBag = new OSBTreeRidBag();
secondBag.setAutoConvertToRecord(false);
secondBag.setCollectionPointer(tree1.getCollectionPointer());
Assert.assertEquals(tree1.size(), 1000);
for (OIdentifiable id : secondBag) {
if (id.getIdentity().getClusterPosition() < 2000)
Assert.fail("found a wrong rid in the ridbag");
}
} finally {
exec.shutdown();
db.drop();
}
}
use of com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage in project orientdb by orientechnologies.
the class OrientBaseGraph method shutdown.
/**
* Closes the Graph. After closing the Graph cannot be used.
*/
public void shutdown(boolean closeDb, boolean commitTx) {
makeActive();
try {
if (!isClosed() && commitTx) {
final OStorage storage = getDatabase().getStorage().getUnderlying();
if (storage instanceof OAbstractPaginatedStorage) {
if (((OAbstractPaginatedStorage) storage).getWALInstance() != null)
getDatabase().commit();
}
}
} catch (RuntimeException e) {
OLogManager.instance().error(this, "Error during context close for db " + url, e);
throw e;
} catch (Exception e) {
OLogManager.instance().error(this, "Error during context close for db " + url, e);
throw OException.wrapException(new ODatabaseException("Error during context close for db " + url), e);
} finally {
try {
if (closeDb) {
getDatabase().close();
if (getDatabase().isPooled()) {
database = null;
}
}
} catch (Exception e) {
OLogManager.instance().error(this, "Error during context close for db " + url, e);
}
}
url = null;
username = null;
password = null;
pollGraphFromStack(closeDb);
if (!closeDb)
getDatabase().activateOnCurrentThread();
}
use of com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage in project orientdb by orientechnologies.
the class OServer method getAvailableStorageNames.
public Map<String, String> getAvailableStorageNames() {
final OServerConfiguration configuration = serverCfg.getConfiguration();
// SEARCH IN CONFIGURED PATHS
final Map<String, String> storages = new HashMap<String, String>();
if (configuration.storages != null && configuration.storages.length > 0)
for (OServerStorageConfiguration s : configuration.storages) storages.put(OIOUtils.getDatabaseNameFromPath(s.name), s.path);
// SEARCH IN DEFAULT DATABASE DIRECTORY
final String rootDirectory = getDatabaseDirectory();
scanDatabaseDirectory(new File(rootDirectory), storages);
for (OStorage storage : Orient.instance().getStorages()) {
final String storageUrl = storage.getURL();
// TEST IT'S OF CURRENT SERVER INSTANCE BY CHECKING THE PATH
if (storage instanceof OAbstractPaginatedStorage && storage.exists() && !storages.containsValue(storageUrl) && isStorageOfCurrentServerInstance(storage))
storages.put(OIOUtils.getDatabaseNameFromPath(storage.getName()), storageUrl);
}
if (storages != null)
storages.remove(OSystemDatabase.SYSTEM_DB_NAME);
return storages;
}
use of com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage in project orientdb by orientechnologies.
the class OHashTableDirectoryTest method beforeClass.
@BeforeClass
public void beforeClass() throws IOException {
String buildDirectory = System.getProperty("buildDirectory");
if (buildDirectory == null)
buildDirectory = ".";
databaseDocumentTx = new ODatabaseDocumentTx("memory:" + OHashTableDirectoryTest.class.getSimpleName());
if (databaseDocumentTx.exists()) {
databaseDocumentTx.open("admin", "admin");
databaseDocumentTx.drop();
}
databaseDocumentTx.create();
OMurmurHash3HashFunction<Integer> murmurHash3HashFunction = new OMurmurHash3HashFunction<Integer>();
murmurHash3HashFunction.setValueSerializer(OIntegerSerializer.INSTANCE);
directory = new OHashTableDirectory(".tsc", "hashTableDirectoryTest", "hashTableDirectoryTest", false, (OAbstractPaginatedStorage) databaseDocumentTx.getStorage());
directory.create();
}
Aggregations