Search in sources :

Example 11 with OBonsaiCollectionPointer

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

the class ONetworkProtocolBinary method ridBagSize.

private void ridBagSize(OClientConnection connection) throws IOException {
    setDataCommandInfo(connection, "RidBag get size");
    OBonsaiCollectionPointer collectionPointer = OCollectionNetworkSerializer.INSTANCE.readCollectionPointer(channel);
    final byte[] changeStream = channel.readBytes();
    final OSBTreeCollectionManager sbTreeCollectionManager = connection.getDatabase().getSbTreeCollectionManager();
    final OSBTreeBonsai<OIdentifiable, Integer> tree = sbTreeCollectionManager.loadSBTree(collectionPointer);
    if (tree == null)
        throw new ORecordContentNotFoundException(collectionPointer);
    try {
        final Map<OIdentifiable, OSBTreeRidBag.Change> changes = OSBTreeRidBag.ChangeSerializationHelper.INSTANCE.deserializeChanges(changeStream, 0);
        int realSize = tree.getRealBagSize(changes);
        beginResponse();
        try {
            sendOk(connection, clientTxId);
            channel.writeInt(realSize);
        } finally {
            endResponse(connection);
        }
    } finally {
        sbTreeCollectionManager.releaseSBTree(collectionPointer);
    }
}
Also used : OBonsaiCollectionPointer(com.orientechnologies.orient.core.db.record.ridbag.sbtree.OBonsaiCollectionPointer) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) OSBTreeCollectionManager(com.orientechnologies.orient.core.db.record.ridbag.sbtree.OSBTreeCollectionManager)

Example 12 with OBonsaiCollectionPointer

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

the class ONetworkProtocolBinary method sbTreeBonsaiGetEntriesMajor.

private void sbTreeBonsaiGetEntriesMajor(OClientConnection connection) throws IOException {
    setDataCommandInfo(connection, "SB-Tree bonsai get values major");
    OBonsaiCollectionPointer collectionPointer = OCollectionNetworkSerializer.INSTANCE.readCollectionPointer(channel);
    byte[] keyStream = channel.readBytes();
    boolean inclusive = channel.readBoolean();
    int pageSize = 128;
    if (connection.getData().protocolVersion >= 21)
        pageSize = channel.readInt();
    final OSBTreeCollectionManager sbTreeCollectionManager = connection.getDatabase().getSbTreeCollectionManager();
    final OSBTreeBonsai<OIdentifiable, Integer> tree = sbTreeCollectionManager.loadSBTree(collectionPointer);
    if (tree == null)
        throw new ORecordContentNotFoundException(collectionPointer);
    try {
        final OBinarySerializer<OIdentifiable> keySerializer = tree.getKeySerializer();
        OIdentifiable key = keySerializer.deserialize(keyStream, 0);
        final OBinarySerializer<Integer> valueSerializer = tree.getValueSerializer();
        OTreeInternal.AccumulativeListener<OIdentifiable, Integer> listener = new OTreeInternal.AccumulativeListener<OIdentifiable, Integer>(pageSize);
        tree.loadEntriesMajor(key, inclusive, true, listener);
        List<Entry<OIdentifiable, Integer>> result = listener.getResult();
        byte[] stream = serializeSBTreeEntryCollection(result, keySerializer, valueSerializer);
        beginResponse();
        try {
            sendOk(connection, clientTxId);
            channel.writeBytes(stream);
        } finally {
            endResponse(connection);
        }
    } finally {
        sbTreeCollectionManager.releaseSBTree(collectionPointer);
    }
}
Also used : OBonsaiCollectionPointer(com.orientechnologies.orient.core.db.record.ridbag.sbtree.OBonsaiCollectionPointer) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) OTreeInternal(com.orientechnologies.orient.core.index.sbtree.OTreeInternal) OSBTreeCollectionManager(com.orientechnologies.orient.core.db.record.ridbag.sbtree.OSBTreeCollectionManager) Entry(java.util.Map.Entry)

Example 13 with OBonsaiCollectionPointer

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

the class ONetworkProtocolBinary method sbTreeBonsaiGet.

private void sbTreeBonsaiGet(OClientConnection connection) throws IOException {
    setDataCommandInfo(connection, "SB-Tree bonsai get");
    OBonsaiCollectionPointer collectionPointer = OCollectionNetworkSerializer.INSTANCE.readCollectionPointer(channel);
    final byte[] keyStream = channel.readBytes();
    final OSBTreeCollectionManager sbTreeCollectionManager = connection.getDatabase().getSbTreeCollectionManager();
    final OSBTreeBonsai<OIdentifiable, Integer> tree = sbTreeCollectionManager.loadSBTree(collectionPointer);
    if (tree == null)
        throw new ORecordContentNotFoundException(collectionPointer);
    try {
        final OIdentifiable key = tree.getKeySerializer().deserialize(keyStream, 0);
        Integer result = tree.get(key);
        final OBinarySerializer<? super Integer> valueSerializer;
        if (result == null) {
            valueSerializer = ONullSerializer.INSTANCE;
        } else {
            valueSerializer = tree.getValueSerializer();
        }
        byte[] stream = new byte[OByteSerializer.BYTE_SIZE + valueSerializer.getObjectSize(result)];
        OByteSerializer.INSTANCE.serialize(valueSerializer.getId(), stream, 0);
        valueSerializer.serialize(result, stream, OByteSerializer.BYTE_SIZE);
        beginResponse();
        try {
            sendOk(connection, clientTxId);
            channel.writeBytes(stream);
        } finally {
            endResponse(connection);
        }
    } finally {
        sbTreeCollectionManager.releaseSBTree(collectionPointer);
    }
}
Also used : OBonsaiCollectionPointer(com.orientechnologies.orient.core.db.record.ridbag.sbtree.OBonsaiCollectionPointer) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) OSBTreeCollectionManager(com.orientechnologies.orient.core.db.record.ridbag.sbtree.OSBTreeCollectionManager)

Example 14 with OBonsaiCollectionPointer

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

the class ONetworkProtocolBinary method createSBTreeBonsai.

private void createSBTreeBonsai(OClientConnection connection) throws IOException {
    setDataCommandInfo(connection, "Create SB-Tree bonsai instance");
    int clusterId = channel.readInt();
    OBonsaiCollectionPointer collectionPointer = connection.getDatabase().getSbTreeCollectionManager().createSBTree(clusterId, null);
    beginResponse();
    try {
        sendOk(connection, clientTxId);
        OCollectionNetworkSerializer.INSTANCE.writeCollectionPointer(channel, collectionPointer);
    } finally {
        endResponse(connection);
    }
}
Also used : OBonsaiCollectionPointer(com.orientechnologies.orient.core.db.record.ridbag.sbtree.OBonsaiCollectionPointer)

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