use of com.orientechnologies.orient.core.db.record.ridbag.sbtree.OIndexRIDContainer in project orientdb by orientechnologies.
the class OStreamSerializerSBTreeIndexRIDContainerTest method testSerializeInByteBufferEmbeddedNonDurable.
public void testSerializeInByteBufferEmbeddedNonDurable() {
final OIndexRIDContainer indexRIDContainer = new OIndexRIDContainer("test", false);
indexRIDContainer.setTopThreshold(100);
for (int i = 0; i < 5; i++) {
indexRIDContainer.add(new ORecordId(1, i));
}
Assert.assertTrue(indexRIDContainer.isEmbedded());
final int len = streamSerializerSBTreeIndexRIDContainer.getObjectSize(indexRIDContainer);
final int serializationOffset = 5;
final ByteBuffer buffer = ByteBuffer.allocate(len + serializationOffset);
buffer.position(serializationOffset);
streamSerializerSBTreeIndexRIDContainer.serializeInByteBufferObject(indexRIDContainer, buffer);
final int binarySize = buffer.position() - serializationOffset;
Assert.assertEquals(binarySize, len);
buffer.position(serializationOffset);
Assert.assertEquals(streamSerializerSBTreeIndexRIDContainer.getObjectSizeInByteBuffer(buffer), len);
buffer.position(serializationOffset);
OIndexRIDContainer newRidContainer = streamSerializerSBTreeIndexRIDContainer.deserializeFromByteBufferObject(buffer);
Assert.assertEquals(buffer.position() - serializationOffset, len);
Assert.assertNotSame(newRidContainer, indexRIDContainer);
Assert.assertTrue(newRidContainer.isEmbedded());
Assert.assertFalse(newRidContainer.isDurableNonTxMode());
final Set<OIdentifiable> storedRids = new HashSet<OIdentifiable>(newRidContainer);
final Set<OIdentifiable> newRids = new HashSet<OIdentifiable>(indexRIDContainer);
Assert.assertEquals(newRids, storedRids);
}
use of com.orientechnologies.orient.core.db.record.ridbag.sbtree.OIndexRIDContainer in project orientdb by orientechnologies.
the class OStreamSerializerSBTreeIndexRIDContainerTest method testSerializeInByteBufferNonEmbeddedDurable.
public void testSerializeInByteBufferNonEmbeddedDurable() {
final OIndexRIDContainer indexRIDContainer = new OIndexRIDContainer("test", true);
indexRIDContainer.setTopThreshold(1);
for (int i = 0; i < 5; i++) {
indexRIDContainer.add(new ORecordId(1, i * 4));
}
Assert.assertFalse(indexRIDContainer.isEmbedded());
final int len = streamSerializerSBTreeIndexRIDContainer.getObjectSize(indexRIDContainer);
final int serializationOffset = 5;
final ByteBuffer buffer = ByteBuffer.allocate(len + serializationOffset);
buffer.position(serializationOffset);
streamSerializerSBTreeIndexRIDContainer.serializeInByteBufferObject(indexRIDContainer, buffer);
final int binarySize = buffer.position() - serializationOffset;
Assert.assertEquals(binarySize, len);
buffer.position(serializationOffset);
Assert.assertEquals(streamSerializerSBTreeIndexRIDContainer.getObjectSizeInByteBuffer(buffer), len);
buffer.position(serializationOffset);
OIndexRIDContainer newRidContainer = streamSerializerSBTreeIndexRIDContainer.deserializeFromByteBufferObject(buffer);
Assert.assertEquals(buffer.position() - serializationOffset, len);
Assert.assertNotSame(newRidContainer, indexRIDContainer);
Assert.assertFalse(newRidContainer.isEmbedded());
Assert.assertTrue(newRidContainer.isDurableNonTxMode());
final Set<OIdentifiable> storedRids = new HashSet<OIdentifiable>(newRidContainer);
final Set<OIdentifiable> newRids = new HashSet<OIdentifiable>(indexRIDContainer);
Assert.assertEquals(newRids, storedRids);
}
use of com.orientechnologies.orient.core.db.record.ridbag.sbtree.OIndexRIDContainer in project orientdb by orientechnologies.
the class OStreamSerializerSBTreeIndexRIDContainerTest method testSerializeInByteBufferNonEmbeddedNonDurable.
public void testSerializeInByteBufferNonEmbeddedNonDurable() {
final OIndexRIDContainer indexRIDContainer = new OIndexRIDContainer("test", false);
indexRIDContainer.setTopThreshold(1);
for (int i = 0; i < 5; i++) {
indexRIDContainer.add(new ORecordId(1, i * 3));
}
Assert.assertFalse(indexRIDContainer.isEmbedded());
final int len = streamSerializerSBTreeIndexRIDContainer.getObjectSize(indexRIDContainer);
final int serializationOffset = 5;
final ByteBuffer buffer = ByteBuffer.allocate(len + serializationOffset);
buffer.position(serializationOffset);
streamSerializerSBTreeIndexRIDContainer.serializeInByteBufferObject(indexRIDContainer, buffer);
final int binarySize = buffer.position() - serializationOffset;
Assert.assertEquals(binarySize, len);
buffer.position(serializationOffset);
Assert.assertEquals(streamSerializerSBTreeIndexRIDContainer.getObjectSizeInByteBuffer(buffer), len);
buffer.position(serializationOffset);
OIndexRIDContainer newRidContainer = streamSerializerSBTreeIndexRIDContainer.deserializeFromByteBufferObject(buffer);
Assert.assertEquals(buffer.position() - serializationOffset, len);
Assert.assertNotSame(newRidContainer, indexRIDContainer);
Assert.assertFalse(newRidContainer.isEmbedded());
Assert.assertFalse(newRidContainer.isDurableNonTxMode());
final Set<OIdentifiable> storedRids = new HashSet<OIdentifiable>(newRidContainer);
final Set<OIdentifiable> newRids = new HashSet<OIdentifiable>(indexRIDContainer);
Assert.assertEquals(newRids, storedRids);
}
use of com.orientechnologies.orient.core.db.record.ridbag.sbtree.OIndexRIDContainer in project orientdb by orientechnologies.
the class OStreamSerializerSBTreeIndexRIDContainerTest method testSerializeWALChangesEmbeddedDurable.
public void testSerializeWALChangesEmbeddedDurable() {
final OIndexRIDContainer indexRIDContainer = new OIndexRIDContainer("test", true);
indexRIDContainer.setTopThreshold(100);
for (int i = 0; i < 5; i++) {
indexRIDContainer.add(new ORecordId(1, i * 2));
}
Assert.assertTrue(indexRIDContainer.isEmbedded());
final int len = streamSerializerSBTreeIndexRIDContainer.getObjectSize(indexRIDContainer);
final int serializationOffset = 5;
final ByteBuffer buffer = ByteBuffer.allocateDirect(len + serializationOffset).order(ByteOrder.nativeOrder());
final byte[] data = new byte[len];
streamSerializerSBTreeIndexRIDContainer.serializeNativeObject(indexRIDContainer, data, 0);
final OWALChanges walChanges = new OWALChangesTree();
walChanges.setBinaryValue(buffer, data, serializationOffset);
Assert.assertEquals(streamSerializerSBTreeIndexRIDContainer.getObjectSizeInByteBuffer(buffer, walChanges, serializationOffset), len);
OIndexRIDContainer newRidContainer = streamSerializerSBTreeIndexRIDContainer.deserializeFromByteBufferObject(buffer, walChanges, serializationOffset);
Assert.assertNotSame(newRidContainer, indexRIDContainer);
Assert.assertTrue(newRidContainer.isEmbedded());
Assert.assertTrue(newRidContainer.isDurableNonTxMode());
final Set<OIdentifiable> storedRids = new HashSet<OIdentifiable>(newRidContainer);
final Set<OIdentifiable> newRids = new HashSet<OIdentifiable>(indexRIDContainer);
Assert.assertEquals(newRids, storedRids);
}
use of com.orientechnologies.orient.core.db.record.ridbag.sbtree.OIndexRIDContainer in project orientdb by orientechnologies.
the class OIndexMultiValues method put.
public OIndexMultiValues put(Object key, final OIdentifiable singleValue) {
if (singleValue != null && !singleValue.getIdentity().isPersistent())
throw new IllegalArgumentException("Cannot index a non persistent record (" + singleValue.getIdentity() + ")");
key = getCollatingValue(key);
final ODatabase database = getDatabase();
final boolean txIsActive = database.getTransaction().isActive();
if (!txIsActive) {
keyLockManager.acquireExclusiveLock(key);
}
try {
acquireSharedLock();
try {
if (!singleValue.getIdentity().isValid())
(singleValue.getRecord()).save();
final ORID identity = singleValue.getIdentity();
final boolean durable;
if (metadata != null && Boolean.TRUE.equals(metadata.field("durableInNonTxMode")))
durable = true;
else
durable = false;
Set<OIdentifiable> values = null;
while (true) {
try {
values = (Set<OIdentifiable>) storage.getIndexValue(indexId, key);
break;
} catch (OInvalidIndexEngineIdException e) {
doReloadIndexEngine();
}
}
final Set<OIdentifiable> cvalues = values;
final Callable<Object> creator = new Callable<Object>() {
@Override
public Object call() throws Exception {
Set<OIdentifiable> result = cvalues;
if (result == null) {
if (ODefaultIndexFactory.SBTREEBONSAI_VALUE_CONTAINER.equals(valueContainerAlgorithm)) {
result = new OIndexRIDContainer(getName(), durable);
} else {
throw new IllegalStateException("MVRBTree is not supported any more");
}
}
result.add(identity);
return result;
}
};
while (true) {
try {
storage.updateIndexEntry(indexId, key, creator);
return this;
} catch (OInvalidIndexEngineIdException e) {
doReloadIndexEngine();
}
}
} finally {
releaseSharedLock();
}
} finally {
if (!txIsActive)
keyLockManager.releaseExclusiveLock(key);
}
}
Aggregations