Search in sources :

Example 1 with OWALChanges

use of com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OWALChanges 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 2 with OWALChanges

use of com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OWALChanges in project orientdb by orientechnologies.

the class OSimpleKeySerializerTest method testSerializeWALChanges.

public void testSerializeWALChanges() {
    final int serializationOffset = 5;
    final ByteBuffer buffer = ByteBuffer.allocateDirect(FIELD_SIZE + serializationOffset).order(ByteOrder.nativeOrder());
    final byte[] data = new byte[FIELD_SIZE];
    simpleKeySerializer.serializeNativeObject(OBJECT, data, 0);
    final OWALChanges walChanges = new OWALChangesTree();
    walChanges.setBinaryValue(buffer, data, serializationOffset);
    Assert.assertEquals(simpleKeySerializer.getObjectSizeInByteBuffer(buffer, walChanges, serializationOffset), FIELD_SIZE);
    Assert.assertEquals(simpleKeySerializer.deserializeFromByteBufferObject(buffer, walChanges, serializationOffset), OBJECT);
}
Also used : OWALChangesTree(com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OWALChangesTree) OWALChanges(com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OWALChanges) ByteBuffer(java.nio.ByteBuffer)

Example 3 with OWALChanges

use of com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OWALChanges in project orientdb by orientechnologies.

the class OStreamSerializerRIDTest method testsSerializeWALChanges.

public void testsSerializeWALChanges() {
    final int serializationOffset = 5;
    final ByteBuffer buffer = ByteBuffer.allocateDirect(FIELD_SIZE + serializationOffset).order(ByteOrder.nativeOrder());
    final byte[] data = new byte[FIELD_SIZE];
    streamSerializerRID.serializeNativeObject(OBJECT, data, 0);
    final OWALChanges walChanges = new OWALChangesTree();
    walChanges.setBinaryValue(buffer, data, serializationOffset);
    Assert.assertEquals(streamSerializerRID.getObjectSizeInByteBuffer(buffer, walChanges, serializationOffset), FIELD_SIZE);
    Assert.assertEquals(streamSerializerRID.deserializeFromByteBufferObject(buffer, walChanges, serializationOffset), OBJECT);
}
Also used : OWALChangesTree(com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OWALChangesTree) OWALChanges(com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OWALChanges) ByteBuffer(java.nio.ByteBuffer)

Example 4 with OWALChanges

use of com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OWALChanges in project orientdb by orientechnologies.

the class ClusterPageTest method assertChangesTracking.

private void assertChangesTracking(OClusterPage localPage, ByteBuffer buffer, OByteBufferPool bufferPool) throws IOException {
    ByteBuffer restoredBuffer = bufferPool.acquireDirect(true);
    OCachePointer cachePointer = new OCachePointer(restoredBuffer, bufferPool, new OLogSequenceNumber(0, 0), 0, 0);
    cachePointer.incrementReferrer();
    OCacheEntry cacheEntry = new OCacheEntry(0, 0, cachePointer, false);
    cacheEntry.acquireExclusiveLock();
    try {
        OClusterPage restoredPage = new OClusterPage(cacheEntry, false, null);
        OWALChanges changes = localPage.getChanges();
        restoredPage.restoreChanges(changes);
        Assert.assertEquals(getBytes(restoredBuffer, SYSTEM_OFFSET, OClusterPage.PAGE_SIZE - SYSTEM_OFFSET), getBytes(buffer, SYSTEM_OFFSET, OClusterPage.PAGE_SIZE - SYSTEM_OFFSET));
    } finally {
        cacheEntry.releaseExclusiveLock();
        cachePointer.decrementReferrer();
    }
}
Also used : OCacheEntry(com.orientechnologies.orient.core.storage.cache.OCacheEntry) OLogSequenceNumber(com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber) OWALChanges(com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OWALChanges) ByteBuffer(java.nio.ByteBuffer) OCachePointer(com.orientechnologies.orient.core.storage.cache.OCachePointer)

Example 5 with OWALChanges

use of com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OWALChanges in project orientdb by orientechnologies.

the class DateSerializerTest method testSerializeWALChanges.

public void testSerializeWALChanges() {
    final int serializationOffset = 5;
    final ByteBuffer buffer = ByteBuffer.allocateDirect(FIELD_SIZE + serializationOffset).order(ByteOrder.nativeOrder());
    final byte[] data = new byte[FIELD_SIZE];
    dateSerializer.serializeNativeObject(OBJECT, data, 0);
    final OWALChanges walChanges = new OWALChangesTree();
    walChanges.setBinaryValue(buffer, data, serializationOffset);
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(OBJECT);
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    Assert.assertEquals(dateSerializer.getObjectSizeInByteBuffer(buffer, walChanges, serializationOffset), FIELD_SIZE);
    Assert.assertEquals(dateSerializer.deserializeFromByteBufferObject(buffer, walChanges, serializationOffset), calendar.getTime());
}
Also used : OWALChangesTree(com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OWALChangesTree) OWALChanges(com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OWALChanges) Calendar(java.util.Calendar) ByteBuffer(java.nio.ByteBuffer)

Aggregations

OWALChanges (com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OWALChanges)22 ByteBuffer (java.nio.ByteBuffer)22 OWALChangesTree (com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OWALChangesTree)21 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)4 OIndexRIDContainer (com.orientechnologies.orient.core.db.record.ridbag.sbtree.OIndexRIDContainer)4 ORecordId (com.orientechnologies.orient.core.id.ORecordId)4 HashSet (java.util.HashSet)4 OCacheEntry (com.orientechnologies.orient.core.storage.cache.OCacheEntry)1 OCachePointer (com.orientechnologies.orient.core.storage.cache.OCachePointer)1 OLogSequenceNumber (com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber)1 Calendar (java.util.Calendar)1