Search in sources :

Example 1 with OSBTreeBonsaiLocal

use of com.orientechnologies.orient.core.index.sbtreebonsai.local.OSBTreeBonsaiLocal in project orientdb by orientechnologies.

the class OSBTreeCollectionManagerShared method loadTree.

@Override
protected OSBTreeBonsai<OIdentifiable, Integer> loadTree(OBonsaiCollectionPointer collectionPointer) {
    String fileName;
    OAtomicOperation atomicOperation = storage.getAtomicOperationsManager().getCurrentOperation();
    if (atomicOperation == null) {
        fileName = storage.getWriteCache().fileNameById(collectionPointer.getFileId());
    } else {
        fileName = atomicOperation.fileNameById(collectionPointer.getFileId());
    }
    OSBTreeBonsaiLocal<OIdentifiable, Integer> tree = new OSBTreeBonsaiLocal<OIdentifiable, Integer>(fileName.substring(0, fileName.length() - DEFAULT_EXTENSION.length()), DEFAULT_EXTENSION, storage);
    if (tree.load(collectionPointer.getRootPointer()))
        return tree;
    else
        return null;
}
Also used : OAtomicOperation(com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation) OSBTreeBonsaiLocal(com.orientechnologies.orient.core.index.sbtreebonsai.local.OSBTreeBonsaiLocal) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable)

Example 2 with OSBTreeBonsaiLocal

use of com.orientechnologies.orient.core.index.sbtreebonsai.local.OSBTreeBonsaiLocal 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)

Aggregations

OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)2 OSBTreeBonsaiLocal (com.orientechnologies.orient.core.index.sbtreebonsai.local.OSBTreeBonsaiLocal)2 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)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 OAbstractPaginatedStorage (com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage)1 OAtomicOperation (com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation)1 OAtomicOperationsManager (com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperationsManager)1 ExecutorService (java.util.concurrent.ExecutorService)1 TimeoutException (java.util.concurrent.TimeoutException)1 Test (org.testng.annotations.Test)1