Search in sources :

Example 6 with OIndexRIDContainer

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);
}
Also used : OWALChangesTree(com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OWALChangesTree) OIndexRIDContainer(com.orientechnologies.orient.core.db.record.ridbag.sbtree.OIndexRIDContainer) OWALChanges(com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OWALChanges) ByteBuffer(java.nio.ByteBuffer) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ORecordId(com.orientechnologies.orient.core.id.ORecordId) HashSet(java.util.HashSet)

Example 7 with OIndexRIDContainer

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

the class OStreamSerializerSBTreeIndexRIDContainer method deserializeFromByteBufferObject.

/**
   * {@inheritDoc}
   */
@Override
public OIndexRIDContainer deserializeFromByteBufferObject(ByteBuffer buffer, OWALChanges walChanges, int offset) {
    final long fileId = walChanges.getLongValue(buffer, offset + FILE_ID_OFFSET);
    final boolean durable = walChanges.getByteValue(buffer, offset + DURABLE_OFFSET) > 0;
    if (walChanges.getByteValue(buffer, offset + EMBEDDED_OFFSET) > 0) {
        final int size = walChanges.getIntValue(buffer, offset + EMBEDDED_SIZE_OFFSET);
        final Set<OIdentifiable> underlying = new HashSet<OIdentifiable>(Math.max((int) (size / .75f) + 1, 16));
        int p = offset + EMBEDDED_VALUES_OFFSET;
        for (int i = 0; i < size; i++) {
            underlying.add(LINK_SERIALIZER.deserializeFromByteBufferObject(buffer, walChanges, p));
            p += RID_SIZE;
        }
        return new OIndexRIDContainer(fileId, underlying, durable);
    } else {
        final long pageIndex = walChanges.getLongValue(buffer, offset + SBTREE_ROOTINDEX_OFFSET);
        final int pageOffset = walChanges.getIntValue(buffer, offset + SBTREE_ROOTOFFSET_OFFSET);
        final OBonsaiBucketPointer rootPointer = new OBonsaiBucketPointer(pageIndex, pageOffset);
        final ODatabaseDocumentInternal db = ODatabaseRecordThreadLocal.INSTANCE.get();
        final OIndexRIDContainerSBTree underlying = new OIndexRIDContainerSBTree(fileId, rootPointer, durable, (OAbstractPaginatedStorage) db.getStorage().getUnderlying());
        return new OIndexRIDContainer(fileId, underlying, durable);
    }
}
Also used : OBonsaiBucketPointer(com.orientechnologies.orient.core.index.sbtreebonsai.local.OBonsaiBucketPointer) OIndexRIDContainer(com.orientechnologies.orient.core.db.record.ridbag.sbtree.OIndexRIDContainer) OIndexRIDContainerSBTree(com.orientechnologies.orient.core.db.record.ridbag.sbtree.OIndexRIDContainerSBTree) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal) HashSet(java.util.HashSet)

Example 8 with OIndexRIDContainer

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

the class OStreamSerializerSBTreeIndexRIDContainer method deserializeFromByteBufferObject.

/**
   * {@inheritDoc}
   */
@Override
public OIndexRIDContainer deserializeFromByteBufferObject(ByteBuffer buffer) {
    final long fileId = buffer.getLong();
    final boolean embedded = buffer.get() > 0;
    final boolean durable = buffer.get() > 0;
    if (embedded) {
        final int size = buffer.getInt();
        final Set<OIdentifiable> underlying = new HashSet<OIdentifiable>(Math.max((int) (size / .75f) + 1, 16));
        for (int i = 0; i < size; i++) {
            underlying.add(LINK_SERIALIZER.deserializeFromByteBufferObject(buffer));
        }
        return new OIndexRIDContainer(fileId, underlying, durable);
    } else {
        final long pageIndex = buffer.getLong();
        final int pageOffset = buffer.getInt();
        final OBonsaiBucketPointer rootPointer = new OBonsaiBucketPointer(pageIndex, pageOffset);
        final ODatabaseDocumentInternal db = ODatabaseRecordThreadLocal.INSTANCE.get();
        final OIndexRIDContainerSBTree underlying = new OIndexRIDContainerSBTree(fileId, rootPointer, durable, (OAbstractPaginatedStorage) db.getStorage().getUnderlying());
        return new OIndexRIDContainer(fileId, underlying, durable);
    }
}
Also used : OBonsaiBucketPointer(com.orientechnologies.orient.core.index.sbtreebonsai.local.OBonsaiBucketPointer) OIndexRIDContainer(com.orientechnologies.orient.core.db.record.ridbag.sbtree.OIndexRIDContainer) OIndexRIDContainerSBTree(com.orientechnologies.orient.core.db.record.ridbag.sbtree.OIndexRIDContainerSBTree) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal) HashSet(java.util.HashSet)

Example 9 with OIndexRIDContainer

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

the class OStreamSerializerSBTreeIndexRIDContainer method deserializeNativeObject.

@Override
public OIndexRIDContainer deserializeNativeObject(byte[] stream, int offset) {
    final long fileId = LONG_SERIALIZER.deserializeNative(stream, offset + FILE_ID_OFFSET);
    final boolean durable = BOOLEAN_SERIALIZER.deserializeNative(stream, offset + DURABLE_OFFSET);
    if (BOOLEAN_SERIALIZER.deserializeNative(stream, offset + EMBEDDED_OFFSET)) {
        final int size = INT_SERIALIZER.deserializeNative(stream, offset + EMBEDDED_SIZE_OFFSET);
        final Set<OIdentifiable> underlying = new HashSet<OIdentifiable>(Math.max((int) (size / .75f) + 1, 16));
        int p = offset + EMBEDDED_VALUES_OFFSET;
        for (int i = 0; i < size; i++) {
            underlying.add(LINK_SERIALIZER.deserializeNativeObject(stream, p));
            p += RID_SIZE;
        }
        return new OIndexRIDContainer(fileId, underlying, durable);
    } else {
        final long pageIndex = LONG_SERIALIZER.deserializeNative(stream, offset + SBTREE_ROOTINDEX_OFFSET);
        final int pageOffset = INT_SERIALIZER.deserializeNative(stream, offset + SBTREE_ROOTOFFSET_OFFSET);
        final OBonsaiBucketPointer rootPointer = new OBonsaiBucketPointer(pageIndex, pageOffset);
        final ODatabaseDocumentInternal db = ODatabaseRecordThreadLocal.INSTANCE.get();
        final OIndexRIDContainerSBTree underlying = new OIndexRIDContainerSBTree(fileId, rootPointer, durable, (OAbstractPaginatedStorage) db.getStorage().getUnderlying());
        return new OIndexRIDContainer(fileId, underlying, durable);
    }
}
Also used : OBonsaiBucketPointer(com.orientechnologies.orient.core.index.sbtreebonsai.local.OBonsaiBucketPointer) OIndexRIDContainer(com.orientechnologies.orient.core.db.record.ridbag.sbtree.OIndexRIDContainer) OIndexRIDContainerSBTree(com.orientechnologies.orient.core.db.record.ridbag.sbtree.OIndexRIDContainerSBTree) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal) HashSet(java.util.HashSet)

Example 10 with OIndexRIDContainer

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

the class OStreamSerializerSBTreeIndexRIDContainerTest method testSerializeInByteBufferEmbeddedDurable.

public void testSerializeInByteBufferEmbeddedDurable() {
    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.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.assertTrue(newRidContainer.isDurableNonTxMode());
    final Set<OIdentifiable> storedRids = new HashSet<OIdentifiable>(newRidContainer);
    final Set<OIdentifiable> newRids = new HashSet<OIdentifiable>(indexRIDContainer);
    Assert.assertEquals(newRids, storedRids);
}
Also used : OIndexRIDContainer(com.orientechnologies.orient.core.db.record.ridbag.sbtree.OIndexRIDContainer) ByteBuffer(java.nio.ByteBuffer) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ORecordId(com.orientechnologies.orient.core.id.ORecordId) HashSet(java.util.HashSet)

Aggregations

OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)13 OIndexRIDContainer (com.orientechnologies.orient.core.db.record.ridbag.sbtree.OIndexRIDContainer)13 HashSet (java.util.HashSet)12 ORecordId (com.orientechnologies.orient.core.id.ORecordId)8 ByteBuffer (java.nio.ByteBuffer)8 OWALChanges (com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OWALChanges)4 OWALChangesTree (com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OWALChangesTree)4 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)3 OIndexRIDContainerSBTree (com.orientechnologies.orient.core.db.record.ridbag.sbtree.OIndexRIDContainerSBTree)3 OBonsaiBucketPointer (com.orientechnologies.orient.core.index.sbtreebonsai.local.OBonsaiBucketPointer)3 ODatabase (com.orientechnologies.orient.core.db.ODatabase)2 OInvalidIndexEngineIdException (com.orientechnologies.orient.core.exception.OInvalidIndexEngineIdException)2 ORID (com.orientechnologies.orient.core.id.ORID)1 Set (java.util.Set)1 Callable (java.util.concurrent.Callable)1