Search in sources :

Example 11 with RandomPageReplacementPolicy

use of herddb.core.RandomPageReplacementPolicy in project herddb by diennea.

the class BlockRangeIndexTest method testRemoveHead.

@Test
public void testRemoveHead() {
    BlockRangeIndex<Sized<Integer>, Sized<String>> index = new BlockRangeIndex<>(1024, new RandomPageReplacementPolicy(10));
    index.boot(BlockRangeIndexMetadata.empty());
    index.boot(BlockRangeIndexMetadata.empty());
    index.put(Sized.valueOf(1), Sized.valueOf("a"));
    index.delete(Sized.valueOf(1), Sized.valueOf("a"));
    List<Sized<String>> searchResult = index.search(Sized.valueOf(1));
    assertTrue(searchResult.isEmpty());
}
Also used : Sized(herddb.utils.Sized) RandomPageReplacementPolicy(herddb.core.RandomPageReplacementPolicy) Test(org.junit.Test)

Example 12 with RandomPageReplacementPolicy

use of herddb.core.RandomPageReplacementPolicy in project herddb by diennea.

the class BlockRangeIndexStorageTest method testUnload.

@Test
public void testUnload() throws Exception {
    PageReplacementPolicy policy = new RandomPageReplacementPolicy(10);
    IndexDataStorage<Sized<Integer>, Sized<String>> storage = new MemoryIndexDataStorage<>();
    BlockRangeIndex<Sized<Integer>, Sized<String>> index = new BlockRangeIndex<>(1024, policy, storage);
    index.boot(BlockRangeIndexMetadata.empty());
    for (int i = 0; i < 100; i++) {
        index.put(Sized.valueOf(i), Sized.valueOf("a"));
    }
    BlockRangeIndexMetadata<Sized<Integer>> metadata = index.checkpoint();
    assertEquals(index.getNumBlocks(), metadata.getBlocksMetadata().size());
    for (int i = 0; i < 100; i++) {
        assertEquals(Sized.valueOf("a"), index.search(Sized.valueOf(i)).get(0));
    }
    assertEquals(10, policy.size());
    index.clear();
    /* No pages should remain in memory after unload!! */
    assertEquals(0, policy.size());
}
Also used : Sized(herddb.utils.Sized) RandomPageReplacementPolicy(herddb.core.RandomPageReplacementPolicy) PageReplacementPolicy(herddb.core.PageReplacementPolicy) RandomPageReplacementPolicy(herddb.core.RandomPageReplacementPolicy) Test(org.junit.Test)

Example 13 with RandomPageReplacementPolicy

use of herddb.core.RandomPageReplacementPolicy in project herddb by diennea.

the class BlockRangeIndexStorageTest method testNextBlockIdAfterReload.

@Test
public void testNextBlockIdAfterReload() throws Exception {
    PageReplacementPolicy policy = new RandomPageReplacementPolicy(10);
    IndexDataStorage<Sized<Integer>, Sized<Integer>> storage = new MemoryIndexDataStorage<>();
    BlockRangeIndex<Sized<Integer>, Sized<Integer>> index = new BlockRangeIndex<>(1024, policy, storage);
    index.boot(BlockRangeIndexMetadata.empty());
    Sized<Integer> data = Sized.valueOf(1);
    while (index.getNumBlocks() < 2) {
        index.put(data, data);
    }
    /* Ensure that the second block has a negative blockId (so we have both positive and negative blockIds) */
    assertTrue(index.getBlocks().lastEntry().getKey().blockId < 0);
    BlockRangeIndexMetadata<Sized<Integer>> metadata = index.checkpoint();
    assertEquals(index.getNumBlocks(), metadata.getBlocksMetadata().size());
    BlockRangeIndex<Sized<Integer>, Sized<Integer>> indexAfterBoot = new BlockRangeIndex<>(1024, new RandomPageReplacementPolicy(10), storage);
    indexAfterBoot.boot(metadata);
    /* Ensure that current block id is correct even if was generated a negative blockId */
    assertEquals(index.getCurrentBlockId(), indexAfterBoot.getCurrentBlockId());
}
Also used : Sized(herddb.utils.Sized) RandomPageReplacementPolicy(herddb.core.RandomPageReplacementPolicy) PageReplacementPolicy(herddb.core.PageReplacementPolicy) RandomPageReplacementPolicy(herddb.core.RandomPageReplacementPolicy) Test(org.junit.Test)

Example 14 with RandomPageReplacementPolicy

use of herddb.core.RandomPageReplacementPolicy in project herddb by diennea.

the class BLinkTest method testScanAndSplit.

@Test
public void testScanAndSplit() throws Exception {
    long splitAt;
    try (BLink<Sized<Long>, Long> blink = new BLink<>(1024L, new LongSizeEvaluator(), new RandomPageReplacementPolicy(10), new DummyBLinkIndexDataStorage<>())) {
        long l = 0;
        while (blink.nodes() < 2) {
            blink.insert(Sized.valueOf(l), l);
            l++;
        }
        splitAt = l - 1;
    }
    try (BLink<Sized<Long>, Long> blink = new BLink<>(1024L, new LongSizeEvaluator(), new RandomPageReplacementPolicy(10), new DummyBLinkIndexDataStorage<>())) {
        long l = 0;
        while (l < splitAt) {
            System.out.println("insert " + l);
            blink.insert(Sized.valueOf(l), l);
            l++;
        }
        Stream<Entry<Sized<Long>, Long>> s = blink.scan(Sized.valueOf(0L), null);
        long keyStream;
        Iterator<Entry<Sized<Long>, Long>> i = s.iterator();
        do {
            keyStream = i.next().getValue();
            System.out.println("read " + keyStream);
        } while (keyStream < splitAt - 4);
        System.out.println("insert " + splitAt);
        blink.insert(Sized.valueOf(splitAt), splitAt);
        while (i.hasNext()) {
            long nowStream = i.next().getValue();
            if (nowStream < keyStream) {
                Assert.fail("Unordered!");
            }
            keyStream = nowStream;
            System.out.println("read " + keyStream);
        }
    }
}
Also used : Sized(herddb.utils.Sized) Entry(java.util.Map.Entry) AtomicLong(java.util.concurrent.atomic.AtomicLong) RandomPageReplacementPolicy(herddb.core.RandomPageReplacementPolicy) Test(org.junit.Test)

Example 15 with RandomPageReplacementPolicy

use of herddb.core.RandomPageReplacementPolicy in project herddb by diennea.

the class BLinkTest method testScanHeadNotExistent.

@Test
public void testScanHeadNotExistent() throws Exception {
    BLinkIndexDataStorage<Sized<Long>, Long> storage = new DummyBLinkIndexDataStorage<>();
    try (BLink<Sized<Long>, Long> blink = new BLink<>(2048L, new LongSizeEvaluator(), new RandomPageReplacementPolicy(10), storage)) {
        final long headNonExistent = 100;
        final long inserts = 100;
        for (long l = headNonExistent; l < inserts + headNonExistent; l++) {
            blink.insert(Sized.valueOf(l), l);
        }
        BLinkMetadata<Sized<Long>> metadata = blink.checkpoint();
        /* Require at least two nodes! */
        assertNotEquals(1, metadata.nodes.size());
        long offset = 10;
        for (long l = 0; l < headNonExistent - offset; l++) {
            Stream<Entry<Sized<Long>, Long>> stream = blink.scan(Sized.valueOf(l), Sized.valueOf(l + offset));
            Holder<Long> h = new Holder<>(l);
            Holder<Long> count = new Holder<>(0L);
            StringBuilder builder = new StringBuilder();
            /* Check each value */
            stream.forEach(entry -> {
                assertEquals(h.value, entry.getValue());
                h.value++;
                count.value++;
                builder.append(entry.getValue()).append(", ");
            });
            assertEquals(0, (long) count.value);
        }
    }
}
Also used : Sized(herddb.utils.Sized) Holder(herddb.utils.Holder) RandomPageReplacementPolicy(herddb.core.RandomPageReplacementPolicy) Entry(java.util.Map.Entry) AtomicLong(java.util.concurrent.atomic.AtomicLong) Test(org.junit.Test)

Aggregations

RandomPageReplacementPolicy (herddb.core.RandomPageReplacementPolicy)35 Sized (herddb.utils.Sized)35 Test (org.junit.Test)34 AtomicLong (java.util.concurrent.atomic.AtomicLong)12 PageReplacementPolicy (herddb.core.PageReplacementPolicy)8 Entry (java.util.Map.Entry)7 List (java.util.List)6 Holder (herddb.utils.Holder)5 ArrayList (java.util.ArrayList)4 ExecutionException (java.util.concurrent.ExecutionException)3 ExecutorService (java.util.concurrent.ExecutorService)3 Block (herddb.index.brin.BlockRangeIndex.Block)2 Random (java.util.Random)2 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 Future (java.util.concurrent.Future)2 Assert (org.junit.Assert)2 Assert.assertEquals (org.junit.Assert.assertEquals)2 Assert.assertTrue (org.junit.Assert.assertTrue)2 BLinkNodeMetadata (herddb.index.blink.BLinkMetadata.BLinkNodeMetadata)1