Search in sources :

Example 6 with OAbstractPaginatedStorage

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;
}
Also used : OLockException(com.orientechnologies.common.concur.lock.OLockException) OStorage(com.orientechnologies.orient.core.storage.OStorage) ORID(com.orientechnologies.orient.core.id.ORID) OAbstractPaginatedStorage(com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage)

Example 7 with OAbstractPaginatedStorage

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();
    }
}
Also used : OBonsaiCollectionPointer(com.orientechnologies.orient.core.db.record.ridbag.sbtree.OBonsaiCollectionPointer) OSBTreeRidBag(com.orientechnologies.orient.core.db.record.ridbag.sbtree.OSBTreeRidBag) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ORecordId(com.orientechnologies.orient.core.id.ORecordId) TimeoutException(java.util.concurrent.TimeoutException) OSBTreeCollectionManager(com.orientechnologies.orient.core.db.record.ridbag.sbtree.OSBTreeCollectionManager) OSBTreeBonsaiLocal(com.orientechnologies.orient.core.index.sbtreebonsai.local.OSBTreeBonsaiLocal) ExecutorService(java.util.concurrent.ExecutorService) OAtomicOperationsManager(com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperationsManager) OAbstractPaginatedStorage(com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage) TimeoutException(java.util.concurrent.TimeoutException) Test(org.testng.annotations.Test)

Example 8 with OAbstractPaginatedStorage

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();
}
Also used : OStorage(com.orientechnologies.orient.core.storage.OStorage) ODatabaseException(com.orientechnologies.orient.core.exception.ODatabaseException) OAbstractPaginatedStorage(com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage) OException(com.orientechnologies.common.exception.OException) ORecordNotFoundException(com.orientechnologies.orient.core.exception.ORecordNotFoundException) ONeedRetryException(com.orientechnologies.common.concur.ONeedRetryException) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException) ODatabaseException(com.orientechnologies.orient.core.exception.ODatabaseException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 9 with OAbstractPaginatedStorage

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;
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) OStorage(com.orientechnologies.orient.core.storage.OStorage) OAbstractPaginatedStorage(com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage) File(java.io.File)

Example 10 with OAbstractPaginatedStorage

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();
}
Also used : ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OAbstractPaginatedStorage(com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage)

Aggregations

OAbstractPaginatedStorage (com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage)38 OStorage (com.orientechnologies.orient.core.storage.OStorage)12 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)9 OWriteCache (com.orientechnologies.orient.core.storage.cache.OWriteCache)7 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)5 Test (org.testng.annotations.Test)5 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)4 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)4 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)4 OLocalPaginatedStorage (com.orientechnologies.orient.core.storage.impl.local.paginated.OLocalPaginatedStorage)4 File (java.io.File)4 BeforeClass (org.testng.annotations.BeforeClass)4 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)3 ORecordId (com.orientechnologies.orient.core.id.ORecordId)3 IOException (java.io.IOException)3 OLockException (com.orientechnologies.common.concur.lock.OLockException)2 OException (com.orientechnologies.common.exception.OException)2 OCommandExecutionException (com.orientechnologies.orient.core.exception.OCommandExecutionException)2 ORID (com.orientechnologies.orient.core.id.ORID)2 ORemoteIndexEngine (com.orientechnologies.orient.core.index.engine.ORemoteIndexEngine)2