Search in sources :

Example 1 with OBonsaiCollectionPointer

use of com.orientechnologies.orient.core.db.record.ridbag.sbtree.OBonsaiCollectionPointer in project orientdb by orientechnologies.

the class OStorageRemote method readCollectionChanges.

private Map<OBonsaiCollectionPointer, OPair<Long, Long>> readCollectionChanges(final OChannelBinaryAsynchClient network) throws IOException {
    final int count = network.readInt();
    final Map<OBonsaiCollectionPointer, OPair<Long, Long>> changes = new HashMap<OBonsaiCollectionPointer, OPair<Long, Long>>(count);
    for (int i = 0; i < count; i++) {
        final long mBitsOfId = network.readLong();
        final long lBitsOfId = network.readLong();
        final OBonsaiCollectionPointer pointer = OCollectionNetworkSerializer.INSTANCE.readCollectionPointer(network);
        changes.put(pointer, new OPair<Long, Long>(mBitsOfId, lBitsOfId));
    }
    return changes;
}
Also used : OBonsaiCollectionPointer(com.orientechnologies.orient.core.db.record.ridbag.sbtree.OBonsaiCollectionPointer) OPair(com.orientechnologies.common.util.OPair)

Example 2 with OBonsaiCollectionPointer

use of com.orientechnologies.orient.core.db.record.ridbag.sbtree.OBonsaiCollectionPointer in project orientdb by orientechnologies.

the class SBTreeBagDeleteTest method testDeleteRidbagTx.

@Test
public void testDeleteRidbagTx() {
    ODocument doc = new ODocument();
    ORidBag bag = new ORidBag();
    int size = OGlobalConfiguration.INDEX_EMBEDDED_TO_SBTREEBONSAI_THRESHOLD.getValueAsInteger() * 2;
    for (int i = 0; i < size; i++) bag.add(new ORecordId(10, i));
    doc.field("bag", bag);
    ORID id = db.save(doc).getIdentity();
    bag = doc.field("bag");
    OBonsaiCollectionPointer pointer = bag.getPointer();
    db.begin();
    db.delete(doc);
    db.commit();
    doc = db.load(id);
    assertNull(doc);
    ((OSBTreeCollectionManagerShared) db.getSbTreeCollectionManager()).clear();
    OSBTreeBonsai<OIdentifiable, Integer> tree = db.getSbTreeCollectionManager().loadSBTree(pointer);
    assertNull(tree);
}
Also used : OBonsaiCollectionPointer(com.orientechnologies.orient.core.db.record.ridbag.sbtree.OBonsaiCollectionPointer) ORidBag(com.orientechnologies.orient.core.db.record.ridbag.ORidBag) ORID(com.orientechnologies.orient.core.id.ORID) OSBTreeCollectionManagerShared(com.orientechnologies.orient.core.db.record.ridbag.sbtree.OSBTreeCollectionManagerShared) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ORecordId(com.orientechnologies.orient.core.id.ORecordId) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Example 3 with OBonsaiCollectionPointer

use of com.orientechnologies.orient.core.db.record.ridbag.sbtree.OBonsaiCollectionPointer 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 4 with OBonsaiCollectionPointer

use of com.orientechnologies.orient.core.db.record.ridbag.sbtree.OBonsaiCollectionPointer in project orientdb by orientechnologies.

the class ONetworkProtocolBinary method sendCollectionChanges.

private void sendCollectionChanges(OClientConnection connection) throws IOException {
    OSBTreeCollectionManager collectionManager = connection.getDatabase().getSbTreeCollectionManager();
    if (collectionManager != null) {
        Map<UUID, OBonsaiCollectionPointer> changedIds = collectionManager.changedIds();
        channel.writeInt(changedIds.size());
        for (Entry<UUID, OBonsaiCollectionPointer> entry : changedIds.entrySet()) {
            UUID id = entry.getKey();
            channel.writeLong(id.getMostSignificantBits());
            channel.writeLong(id.getLeastSignificantBits());
            OCollectionNetworkSerializer.INSTANCE.writeCollectionPointer(channel, entry.getValue());
        }
        collectionManager.clearChangedIds();
    }
}
Also used : OBonsaiCollectionPointer(com.orientechnologies.orient.core.db.record.ridbag.sbtree.OBonsaiCollectionPointer) OSBTreeCollectionManager(com.orientechnologies.orient.core.db.record.ridbag.sbtree.OSBTreeCollectionManager)

Example 5 with OBonsaiCollectionPointer

use of com.orientechnologies.orient.core.db.record.ridbag.sbtree.OBonsaiCollectionPointer in project orientdb by orientechnologies.

the class OStorageRemote method updateCollection.

private void updateCollection(final Map<OBonsaiCollectionPointer, OPair<Long, Long>> changes, final OSBTreeCollectionManager collectionManager) throws IOException {
    if (collectionManager == null)
        return;
    for (Map.Entry<OBonsaiCollectionPointer, OPair<Long, Long>> entry : changes.entrySet()) {
        final OBonsaiCollectionPointer pointer = entry.getKey();
        final long mBitsOfId = entry.getValue().getKey();
        final long lBitsOfId = entry.getValue().getValue();
        collectionManager.updateCollectionPointer(new UUID(mBitsOfId, lBitsOfId), pointer);
    }
    if (ORecordSerializationContext.getDepth() <= 1)
        collectionManager.clearPendingCollections();
}
Also used : OBonsaiCollectionPointer(com.orientechnologies.orient.core.db.record.ridbag.sbtree.OBonsaiCollectionPointer) OPair(com.orientechnologies.common.util.OPair)

Aggregations

OBonsaiCollectionPointer (com.orientechnologies.orient.core.db.record.ridbag.sbtree.OBonsaiCollectionPointer)14 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)9 OSBTreeCollectionManager (com.orientechnologies.orient.core.db.record.ridbag.sbtree.OSBTreeCollectionManager)6 ORecordId (com.orientechnologies.orient.core.id.ORecordId)3 Test (org.testng.annotations.Test)3 OPair (com.orientechnologies.common.util.OPair)2 ORidBag (com.orientechnologies.orient.core.db.record.ridbag.ORidBag)2 OSBTreeCollectionManagerShared (com.orientechnologies.orient.core.db.record.ridbag.sbtree.OSBTreeCollectionManagerShared)2 ORID (com.orientechnologies.orient.core.id.ORID)2 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)2 Test (org.junit.Test)2 OChannelBinaryAsynchClient (com.orientechnologies.orient.client.binary.OChannelBinaryAsynchClient)1 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)1 OSBTreeRidBag (com.orientechnologies.orient.core.db.record.ridbag.sbtree.OSBTreeRidBag)1 OTreeInternal (com.orientechnologies.orient.core.index.sbtree.OTreeInternal)1 OBonsaiBucketPointer (com.orientechnologies.orient.core.index.sbtreebonsai.local.OBonsaiBucketPointer)1 OSBTreeBonsaiLocal (com.orientechnologies.orient.core.index.sbtreebonsai.local.OSBTreeBonsaiLocal)1 OAbstractPaginatedStorage (com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage)1 OAtomicOperationsManager (com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperationsManager)1 Entry (java.util.Map.Entry)1