Search in sources :

Example 6 with OSBTreeCollectionManager

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

the class ONetworkProtocolBinary method sbTreeBonsaiFirstKey.

private void sbTreeBonsaiFirstKey(OClientConnection connection) throws IOException {
    setDataCommandInfo(connection, "SB-Tree bonsai get first key");
    OBonsaiCollectionPointer collectionPointer = OCollectionNetworkSerializer.INSTANCE.readCollectionPointer(channel);
    final OSBTreeCollectionManager sbTreeCollectionManager = connection.getDatabase().getSbTreeCollectionManager();
    final OSBTreeBonsai<OIdentifiable, Integer> tree = sbTreeCollectionManager.loadSBTree(collectionPointer);
    if (tree == null)
        throw new ORecordContentNotFoundException(collectionPointer);
    try {
        OIdentifiable result = tree.firstKey();
        final OBinarySerializer<? super OIdentifiable> keySerializer;
        if (result == null) {
            keySerializer = ONullSerializer.INSTANCE;
        } else {
            keySerializer = tree.getKeySerializer();
        }
        byte[] stream = new byte[OByteSerializer.BYTE_SIZE + keySerializer.getObjectSize(result)];
        OByteSerializer.INSTANCE.serialize(keySerializer.getId(), stream, 0);
        keySerializer.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 7 with OSBTreeCollectionManager

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

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

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

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

the class ONetworkProtocolBinary method commit.

protected void commit(OClientConnection connection) throws IOException {
    setDataCommandInfo(connection, "Transaction commit");
    if (!isConnectionAlive(connection))
        return;
    final OTransactionOptimisticProxy tx = new OTransactionOptimisticProxy(connection, this);
    try {
        try {
            connection.getDatabase().begin(tx);
        } catch (final ORecordNotFoundException e) {
            sendShutdown();
            throw e.getCause() instanceof OOfflineClusterException ? (OOfflineClusterException) e.getCause() : e;
        }
        try {
            try {
                connection.getDatabase().commit();
            } catch (final ORecordNotFoundException e) {
                throw e.getCause() instanceof OOfflineClusterException ? (OOfflineClusterException) e.getCause() : e;
            }
            beginResponse();
            try {
                sendOk(connection, clientTxId);
                // SEND BACK ALL THE RECORD IDS FOR THE CREATED RECORDS
                channel.writeInt(tx.getCreatedRecords().size());
                for (Entry<ORecordId, ORecord> entry : tx.getCreatedRecords().entrySet()) {
                    channel.writeRID(entry.getKey());
                    channel.writeRID(entry.getValue().getIdentity());
                    // IF THE NEW OBJECT HAS VERSION > 0 MEANS THAT HAS BEEN UPDATED IN THE SAME TX. THIS HAPPENS FOR GRAPHS
                    if (entry.getValue().getVersion() > 0)
                        tx.getUpdatedRecords().put((ORecordId) entry.getValue().getIdentity(), entry.getValue());
                }
                // SEND BACK ALL THE NEW VERSIONS FOR THE UPDATED RECORDS
                channel.writeInt(tx.getUpdatedRecords().size());
                for (Entry<ORecordId, ORecord> entry : tx.getUpdatedRecords().entrySet()) {
                    channel.writeRID(entry.getKey());
                    channel.writeVersion(entry.getValue().getVersion());
                }
                if (connection.getData().protocolVersion >= 20)
                    sendCollectionChanges(connection);
            } finally {
                endResponse(connection);
            }
        } catch (Exception e) {
            if (connection != null && connection.getDatabase() != null) {
                if (connection.getDatabase().getTransaction().isActive())
                    connection.getDatabase().rollback(true);
                final OSBTreeCollectionManager collectionManager = connection.getDatabase().getSbTreeCollectionManager();
                if (collectionManager != null)
                    collectionManager.clearChangedIds();
            }
            sendErrorOrDropConnection(connection, clientTxId, e);
        }
    } catch (OTransactionAbortedException e) {
    // TX ABORTED BY THE CLIENT
    } catch (Exception e) {
        // Error during TX initialization, possibly index constraints violation.
        if (tx.isActive())
            tx.rollback(true, -1);
        sendErrorOrDropConnection(connection, clientTxId, e);
    }
}
Also used : OTransactionOptimisticProxy(com.orientechnologies.orient.server.tx.OTransactionOptimisticProxy) ORecord(com.orientechnologies.orient.core.record.ORecord) ORecordId(com.orientechnologies.orient.core.id.ORecordId) OLockException(com.orientechnologies.common.concur.lock.OLockException) OException(com.orientechnologies.common.exception.OException) SocketException(java.net.SocketException) OInterruptedException(com.orientechnologies.common.concur.lock.OInterruptedException) OIOException(com.orientechnologies.common.io.OIOException) OOfflineClusterException(com.orientechnologies.orient.core.storage.impl.local.paginated.OOfflineClusterException) IOException(java.io.IOException) OOfflineClusterException(com.orientechnologies.orient.core.storage.impl.local.paginated.OOfflineClusterException) OSBTreeCollectionManager(com.orientechnologies.orient.core.db.record.ridbag.sbtree.OSBTreeCollectionManager)

Aggregations

OSBTreeCollectionManager (com.orientechnologies.orient.core.db.record.ridbag.sbtree.OSBTreeCollectionManager)10 OBonsaiCollectionPointer (com.orientechnologies.orient.core.db.record.ridbag.sbtree.OBonsaiCollectionPointer)6 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)5 OIOException (com.orientechnologies.common.io.OIOException)3 ORecordId (com.orientechnologies.orient.core.id.ORecordId)3 IOException (java.io.IOException)3 OChannelBinaryAsynchClient (com.orientechnologies.orient.client.binary.OChannelBinaryAsynchClient)2 OSBTreeRidBag (com.orientechnologies.orient.core.db.record.ridbag.sbtree.OSBTreeRidBag)2 ORecord (com.orientechnologies.orient.core.record.ORecord)2 OInterruptedException (com.orientechnologies.common.concur.lock.OInterruptedException)1 OLockException (com.orientechnologies.common.concur.lock.OLockException)1 OException (com.orientechnologies.common.exception.OException)1 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)1 OEmbeddedRidBag (com.orientechnologies.orient.core.db.record.ridbag.embedded.OEmbeddedRidBag)1 OTreeInternal (com.orientechnologies.orient.core.index.sbtree.OTreeInternal)1 OSBTreeBonsaiLocal (com.orientechnologies.orient.core.index.sbtreebonsai.local.OSBTreeBonsaiLocal)1 OAbstractPaginatedStorage (com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage)1 OOfflineClusterException (com.orientechnologies.orient.core.storage.impl.local.paginated.OOfflineClusterException)1 ORecordSerializationContext (com.orientechnologies.orient.core.storage.impl.local.paginated.ORecordSerializationContext)1 OAtomicOperationsManager (com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperationsManager)1