Search in sources :

Example 1 with OAtomicOperationsManager

use of com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperationsManager 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 2 with OAtomicOperationsManager

use of com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperationsManager in project orientdb by orientechnologies.

the class OAbstractPaginatedStorage method open.

public void open(final String iUserName, final String iUserPassword, final Map<String, Object> iProperties) {
    stateLock.acquireReadLock();
    try {
        if (status == STATUS.OPEN)
            // REUSED
            return;
    } finally {
        stateLock.releaseReadLock();
    }
    stateLock.acquireWriteLock();
    try {
        if (status == STATUS.OPEN)
            // REUSED
            return;
        if (!exists())
            throw new OStorageException("Cannot open the storage '" + name + "' because it does not exist in path: " + url);
        configuration.load(iProperties);
        final String cs = configuration.getConflictStrategy();
        if (cs != null) {
            // SET THE CONFLICT STORAGE STRATEGY FROM THE LOADED CONFIGURATION
            setConflictStrategy(Orient.instance().getRecordConflictStrategy().getStrategy(cs));
        }
        componentsFactory = new OCurrentStorageComponentsFactory(configuration);
        preOpenSteps();
        try {
            performanceStatisticManager.registerMBean(name, id);
        } catch (Exception e) {
            OLogManager.instance().error(this, "MBean for profiler cannot be registered.");
        }
        initWalAndDiskCache();
        atomicOperationsManager = new OAtomicOperationsManager(this);
        try {
            atomicOperationsManager.registerMBean();
        } catch (Exception e) {
            OLogManager.instance().error(this, "MBean for atomic operations manager cannot be registered", e);
        }
        recoverIfNeeded();
        openClusters();
        openIndexes();
        if (OGlobalConfiguration.STORAGE_MAKE_FULL_CHECKPOINT_AFTER_OPEN.getValueAsBoolean())
            makeFullCheckpoint();
        writeCache.startFuzzyCheckpoints();
        status = STATUS.OPEN;
        readCache.loadCacheState(writeCache);
    } catch (Exception e) {
        for (OCluster c : clusters) {
            try {
                if (c != null)
                    c.close(false);
            } catch (IOException e1) {
                OLogManager.instance().error(this, "Cannot close cluster after exception on open");
            }
        }
        try {
            status = STATUS.OPEN;
            close(true, false);
        } catch (RuntimeException re) {
            OLogManager.instance().error(this, "Error during storage close", e);
        }
        status = STATUS.CLOSED;
        throw OException.wrapException(new OStorageException("Cannot open local storage '" + url + "' with mode=" + mode), e);
    } finally {
        stateLock.releaseWriteLock();
    }
}
Also used : OAtomicOperationsManager(com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperationsManager) OCurrentStorageComponentsFactory(com.orientechnologies.orient.core.db.record.OCurrentStorageComponentsFactory) OException(com.orientechnologies.common.exception.OException) OModificationOperationProhibitedException(com.orientechnologies.common.concur.lock.OModificationOperationProhibitedException)

Example 3 with OAtomicOperationsManager

use of com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperationsManager in project orientdb by orientechnologies.

the class OAbstractPaginatedStorage method create.

public void create(final Map<String, Object> iProperties) {
    stateLock.acquireWriteLock();
    try {
        if (status != STATUS.CLOSED)
            throw new OStorageExistsException("Cannot create new storage '" + getURL() + "' because it is not closed");
        if (exists())
            throw new OStorageExistsException("Cannot create new storage '" + getURL() + "' because it already exists");
        if (!configuration.getContextConfiguration().getContextKeys().contains(OGlobalConfiguration.STORAGE_COMPRESSION_METHOD.getKey())) {
            final String compression = iProperties != null ? (String) iProperties.get(OGlobalConfiguration.STORAGE_COMPRESSION_METHOD.getKey().toLowerCase(configuration.getLocaleInstance())) : null;
            if (compression != null)
                configuration.getContextConfiguration().setValue(OGlobalConfiguration.STORAGE_COMPRESSION_METHOD, compression);
            else
                configuration.getContextConfiguration().setValue(OGlobalConfiguration.STORAGE_COMPRESSION_METHOD, OGlobalConfiguration.STORAGE_COMPRESSION_METHOD.getValue());
        }
        if (!configuration.getContextConfiguration().getContextKeys().contains(OGlobalConfiguration.STORAGE_ENCRYPTION_METHOD.getKey())) {
            final String encryption = iProperties != null ? (String) iProperties.get(OGlobalConfiguration.STORAGE_ENCRYPTION_METHOD.getKey().toLowerCase(configuration.getLocaleInstance())) : null;
            if (encryption != null)
                configuration.getContextConfiguration().setValue(OGlobalConfiguration.STORAGE_ENCRYPTION_METHOD, encryption);
            else
                configuration.getContextConfiguration().setValue(OGlobalConfiguration.STORAGE_ENCRYPTION_METHOD, OGlobalConfiguration.STORAGE_ENCRYPTION_METHOD.getValue());
        }
        // SAVE COMPRESSION OPTIONS IF ANY. THIS IS USED FOR ENCRYPTION AT REST WHERE IN THE 'STORAGE_ENCRYPTION_KEY' IS STORED
        // THE KEY
        final String encryptionKey = iProperties != null ? (String) iProperties.get(OGlobalConfiguration.STORAGE_ENCRYPTION_KEY.getKey().toLowerCase(configuration.getLocaleInstance())) : null;
        if (encryptionKey != null)
            configuration.getContextConfiguration().setValue(OGlobalConfiguration.STORAGE_ENCRYPTION_KEY, encryptionKey);
        else
            configuration.getContextConfiguration().setValue(OGlobalConfiguration.STORAGE_ENCRYPTION_KEY, OGlobalConfiguration.STORAGE_ENCRYPTION_KEY.getValue());
        componentsFactory = new OCurrentStorageComponentsFactory(configuration);
        try {
            performanceStatisticManager.registerMBean(name, id);
        } catch (Exception e) {
            OLogManager.instance().error(this, "MBean for profiler cannot be registered.");
        }
        initWalAndDiskCache();
        atomicOperationsManager = new OAtomicOperationsManager(this);
        try {
            atomicOperationsManager.registerMBean();
        } catch (Exception e) {
            OLogManager.instance().error(this, "MBean for atomic operations manager cannot be registered", e);
        }
        preCreateSteps();
        status = STATUS.OPEN;
        // ADD THE METADATA CLUSTER TO STORE INTERNAL STUFF
        doAddCluster(OMetadataDefault.CLUSTER_INTERNAL_NAME, null);
        configuration.create();
        // ADD THE INDEX CLUSTER TO STORE, BY DEFAULT, ALL THE RECORDS OF
        // INDEXING
        doAddCluster(OMetadataDefault.CLUSTER_INDEX_NAME, null);
        // ADD THE INDEX CLUSTER TO STORE, BY DEFAULT, ALL THE RECORDS OF
        // INDEXING
        doAddCluster(OMetadataDefault.CLUSTER_MANUAL_INDEX_NAME, null);
        // ADD THE DEFAULT CLUSTER
        defaultClusterId = doAddCluster(CLUSTER_DEFAULT_NAME, null);
        clearStorageDirty();
        if (OGlobalConfiguration.STORAGE_MAKE_FULL_CHECKPOINT_AFTER_CREATE.getValueAsBoolean())
            makeFullCheckpoint();
        writeCache.startFuzzyCheckpoints();
        postCreateSteps();
    } catch (OStorageException e) {
        close();
        throw e;
    } catch (IOException e) {
        close();
        throw OException.wrapException(new OStorageException("Error on creation of storage '" + name + "'"), e);
    } finally {
        stateLock.releaseWriteLock();
    }
}
Also used : OAtomicOperationsManager(com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperationsManager) OCurrentStorageComponentsFactory(com.orientechnologies.orient.core.db.record.OCurrentStorageComponentsFactory) OException(com.orientechnologies.common.exception.OException) OModificationOperationProhibitedException(com.orientechnologies.common.concur.lock.OModificationOperationProhibitedException)

Aggregations

OAtomicOperationsManager (com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperationsManager)3 OModificationOperationProhibitedException (com.orientechnologies.common.concur.lock.OModificationOperationProhibitedException)2 OException (com.orientechnologies.common.exception.OException)2 OCurrentStorageComponentsFactory (com.orientechnologies.orient.core.db.record.OCurrentStorageComponentsFactory)2 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)1 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)1 OBonsaiCollectionPointer (com.orientechnologies.orient.core.db.record.ridbag.sbtree.OBonsaiCollectionPointer)1 OSBTreeCollectionManager (com.orientechnologies.orient.core.db.record.ridbag.sbtree.OSBTreeCollectionManager)1 OSBTreeRidBag (com.orientechnologies.orient.core.db.record.ridbag.sbtree.OSBTreeRidBag)1 ORecordId (com.orientechnologies.orient.core.id.ORecordId)1 OSBTreeBonsaiLocal (com.orientechnologies.orient.core.index.sbtreebonsai.local.OSBTreeBonsaiLocal)1 OAbstractPaginatedStorage (com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage)1 ExecutorService (java.util.concurrent.ExecutorService)1 TimeoutException (java.util.concurrent.TimeoutException)1 Test (org.testng.annotations.Test)1