use of com.orientechnologies.orient.core.db.record.ridbag.sbtree.OBonsaiCollectionPointer in project orientdb by orientechnologies.
the class OCollectionNetworkSerializer method readCollectionPointer.
public OBonsaiCollectionPointer readCollectionPointer(final OChannelBinary client) throws IOException {
final long fileId = client.readLong();
final OBonsaiBucketPointer rootPointer = readBonsaiBucketPointer(client);
return new OBonsaiCollectionPointer(fileId, rootPointer);
}
use of com.orientechnologies.orient.core.db.record.ridbag.sbtree.OBonsaiCollectionPointer in project orientdb by orientechnologies.
the class OSBTreeCollectionManagerRemoteTest method testLoadTree.
@Test
public void testLoadTree() throws Exception {
OSBTreeCollectionManagerRemote remoteManager = new OSBTreeCollectionManagerRemote(storageMock, networkSerializerMock);
OSBTreeBonsai<OIdentifiable, Integer> tree = remoteManager.loadTree(new OBonsaiCollectionPointer(EXPECTED_FILE_ID, EXPECTED_ROOT_POINTER));
assertNotNull(tree);
assertEquals(tree.getFileId(), EXPECTED_FILE_ID);
assertEquals(tree.getRootBucketPointer(), EXPECTED_ROOT_POINTER);
}
use of com.orientechnologies.orient.core.db.record.ridbag.sbtree.OBonsaiCollectionPointer in project orientdb by orientechnologies.
the class OSBTreeCollectionManagerRemoteTest method testCreateTree.
@Test(enabled = false)
public void testCreateTree() throws Exception {
OSBTreeCollectionManagerRemote remoteManager = new OSBTreeCollectionManagerRemote(storageMock, networkSerializerMock);
ODatabaseRecordThreadLocal.INSTANCE.set(dbMock);
when(dbMock.getStorage()).thenReturn(storageMock);
when(storageMock.getUnderlying()).thenReturn(storageMock);
when(storageMock.beginRequest(Mockito.any(OChannelBinaryAsynchClient.class), eq(OChannelBinaryProtocol.REQUEST_CREATE_SBTREE_BONSAI), Mockito.any(OStorageRemoteSession.class))).thenReturn(clientMock);
when(networkSerializerMock.readCollectionPointer(Mockito.<OChannelBinaryAsynchClient>any())).thenReturn(new OBonsaiCollectionPointer(EXPECTED_FILE_ID, EXPECTED_ROOT_POINTER));
OSBTreeBonsaiRemote<OIdentifiable, Integer> tree = remoteManager.createTree(EXPECTED_CLUSTER_ID);
assertNotNull(tree);
assertEquals(tree.getFileId(), EXPECTED_FILE_ID);
assertEquals(tree.getRootBucketPointer(), EXPECTED_ROOT_POINTER);
verify(dbMock).getStorage();
verifyNoMoreInteractions(dbMock);
verify(storageMock).getUnderlying();
verify(storageMock).beginRequest(Mockito.any(OChannelBinaryAsynchClient.class), eq(OChannelBinaryProtocol.REQUEST_CREATE_SBTREE_BONSAI), Mockito.any(OStorageRemoteSession.class));
verify(clientMock).writeInt(eq(EXPECTED_CLUSTER_ID));
verify(storageMock).endRequest(Matchers.same(clientMock));
verify(storageMock).beginResponse(Matchers.same(clientMock), Mockito.any(OStorageRemoteSession.class));
verify(networkSerializerMock).readCollectionPointer(Matchers.same(clientMock));
verify(storageMock).endResponse(Matchers.same(clientMock));
verifyNoMoreInteractions(storageMock);
}
use of com.orientechnologies.orient.core.db.record.ridbag.sbtree.OBonsaiCollectionPointer in project orientdb by orientechnologies.
the class SBTreeBagDeleteTest method testDeleteRidbagNoTx.
@Test
public void testDeleteRidbagNoTx() {
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.delete(doc);
doc = db.load(id);
assertNull(doc);
((OSBTreeCollectionManagerShared) db.getSbTreeCollectionManager()).clear();
OSBTreeBonsai<OIdentifiable, Integer> tree = db.getSbTreeCollectionManager().loadSBTree(pointer);
assertNull(tree);
}
use of com.orientechnologies.orient.core.db.record.ridbag.sbtree.OBonsaiCollectionPointer 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);
}
}
Aggregations