Search in sources :

Example 1 with OffHeapMemory

use of com.cinchapi.lib.offheap.memory.OffHeapMemory in project concourse by cinchapi.

the class ChunkTest method testShiftExisting.

@SuppressWarnings("unchecked")
@Test
public void testShiftExisting() {
    int count = TestData.getScaleCount();
    for (int i = 0; i < count; ++i) {
        chunk.insert(getLocator(), getKey(), getValue(), Time.now(), Action.ADD);
    }
    Iterator<Revision<L, K, V>> expected = ((Iterable<Revision<L, K, V>>) Reflection.get("revisions", chunk)).iterator();
    OffHeapMemory memory = OffHeapMemory.allocateDirect(count * 3 * Write.MINIMUM_SIZE);
    chunk.shift(memory);
    Iterator<Revision<L, K, V>> actual = chunk.iterator();
    while (expected.hasNext()) {
        Revision<L, K, V> a = expected.next();
        Revision<L, K, V> b = actual.next();
        Assert.assertEquals(a, b);
    }
}
Also used : Revision(com.cinchapi.concourse.server.storage.db.Revision) OffHeapMemory(com.cinchapi.lib.offheap.memory.OffHeapMemory) ConcourseBaseTest(com.cinchapi.concourse.test.ConcourseBaseTest) Test(org.junit.Test)

Example 2 with OffHeapMemory

use of com.cinchapi.lib.offheap.memory.OffHeapMemory in project concourse by cinchapi.

the class Segment method createOffHeap.

/**
 * Return a {@link Segment} where each of its {@link Chunk Chunks} is
 * {@link Chunk#shift(OffHeapMemory) shifted} to {@link OffHeapMemory}.
 *
 * @param expectedInsertions
 * @return the {@link Segment}
 */
public static Segment createOffHeap(int expectedInsertions) {
    Segment segment = create(expectedInsertions);
    long capacity = expectedInsertions * Write.MINIMUM_SIZE * 3;
    for (Chunk<? extends Byteable, ? extends Byteable, ? extends Byteable> chunk : Array.containing(segment.table, segment.index, segment.corpus)) {
        // NOTE: Using DirectMemory because UnsafeMemory causes a segfault
        // on CircleCI, so it isn't reliable yet. In the future, the kind of
        // OffHeapMemory to use may be configurable based on tuning.
        OffHeapMemory memory = OffHeapMemory.allocateDirect(capacity);
        chunk.shift(memory);
    }
    return segment;
}
Also used : OffHeapMemory(com.cinchapi.lib.offheap.memory.OffHeapMemory)

Example 3 with OffHeapMemory

use of com.cinchapi.lib.offheap.memory.OffHeapMemory in project concourse by cinchapi.

the class CorpusChunkTest method testShiftExisting.

@SuppressWarnings("unchecked")
@Test
@Override
public void testShiftExisting() {
    int count = TestData.getScaleCount();
    CorpusChunk corpus = (CorpusChunk) chunk;
    for (int i = 0; i < count; ++i) {
        corpus.insert(Text.wrap(TestData.getString()), Value.wrap(Convert.javaToThrift(TestData.getString())), Identifier.of(Time.now()), Time.now(), Action.ADD);
    }
    Iterator<Revision<Text, Text, Position>> expected = ((Iterable<Revision<Text, Text, Position>>) Reflection.get("revisions", chunk)).iterator();
    OffHeapMemory memory = OffHeapMemory.allocateDirect(count * 3 * Write.MINIMUM_SIZE);
    chunk.shift(memory);
    Iterator<Revision<Text, Text, Position>> actual = chunk.iterator();
    while (expected.hasNext()) {
        Revision<Text, Text, Position> a = expected.next();
        Revision<Text, Text, Position> b = actual.next();
        Assert.assertEquals(a, b);
    }
}
Also used : Revision(com.cinchapi.concourse.server.storage.db.Revision) Position(com.cinchapi.concourse.server.model.Position) Text(com.cinchapi.concourse.server.model.Text) OffHeapMemory(com.cinchapi.lib.offheap.memory.OffHeapMemory) Test(org.junit.Test)

Aggregations

OffHeapMemory (com.cinchapi.lib.offheap.memory.OffHeapMemory)3 Revision (com.cinchapi.concourse.server.storage.db.Revision)2 Test (org.junit.Test)2 Position (com.cinchapi.concourse.server.model.Position)1 Text (com.cinchapi.concourse.server.model.Text)1 ConcourseBaseTest (com.cinchapi.concourse.test.ConcourseBaseTest)1