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;
}
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);
}
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();
}
}
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();
}
}
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();
}
Aggregations