Search in sources :

Example 6 with RandomPageReplacementPolicy

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

the class BlockRangeIndexTest method testDelete.

@Test
public void testDelete() {
    BlockRangeIndex<Sized<Integer>, Sized<String>> index = new BlockRangeIndex<>(1024, new RandomPageReplacementPolicy(10));
    index.boot(BlockRangeIndexMetadata.empty());
    index.put(Sized.valueOf(3), Sized.valueOf("c"));
    index.put(Sized.valueOf(2), Sized.valueOf("b"));
    index.put(Sized.valueOf(1), Sized.valueOf("a"));
    index.delete(Sized.valueOf(1), Sized.valueOf("a"));
    assertTrue(index.search(Sized.valueOf(1)).isEmpty());
    assertEquals(Sized.valueOf("b"), index.search(Sized.valueOf(2)).get(0));
    assertEquals(Sized.valueOf("c"), index.search(Sized.valueOf(3)).get(0));
    index.delete(Sized.valueOf(2), Sized.valueOf("b"));
    assertTrue(index.search(Sized.valueOf(2)).isEmpty());
    assertEquals(Sized.valueOf("c"), index.search(Sized.valueOf(3)).get(0));
    index.delete(Sized.valueOf(3), Sized.valueOf("c"));
    assertTrue(index.search(Sized.valueOf(3)).isEmpty());
}
Also used : Sized(herddb.utils.Sized) RandomPageReplacementPolicy(herddb.core.RandomPageReplacementPolicy) Test(org.junit.Test)

Example 7 with RandomPageReplacementPolicy

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

the class BlockRangeIndexTest method testDeleteAndUnload.

/**
 * Verify that deleted entries stay deleted ever after a page unload
 *
 * @author diego.salvi
 */
@Test
public void testDeleteAndUnload() throws IOException {
    /* Must be 1 to keep just one page in memory keeping to unload on every page load */
    final PageReplacementPolicy policy = new RandomPageReplacementPolicy(1);
    final IndexDataStorage<Sized<Integer>, Sized<String>> storage = new MemoryIndexDataStorage<>();
    final BlockRangeIndex<Sized<Integer>, Sized<String>> index = new BlockRangeIndex<>(400, policy, storage);
    index.boot(BlockRangeIndexMetadata.empty());
    /* Add values until block split */
    int elements;
    for (elements = 0; index.getNumBlocks() < 2; elements++) {
        index.put(Sized.valueOf(elements), Sized.valueOf("test_" + elements));
    }
    /* NumBlocks must be greater than 1 to permit unloading */
    Assert.assertTrue(index.getNumBlocks() > 1);
    /* Check every value existance */
    for (int i = 0; i < elements; i++) {
        List<Sized<String>> result = index.search(Sized.valueOf(i));
        Assert.assertEquals(1, result.size());
    }
    /* Remove every value */
    for (int i = 0; i < elements; i++) {
        index.delete(Sized.valueOf(i), Sized.valueOf("test_" + i));
    }
    /* Check every value non existance */
    for (int i = 0; i < elements; i++) {
        List<Sized<String>> result = index.search(Sized.valueOf(i));
        Assert.assertEquals(0, result.size());
    }
    index.clear();
}
Also used : Sized(herddb.utils.Sized) RandomPageReplacementPolicy(herddb.core.RandomPageReplacementPolicy) PageReplacementPolicy(herddb.core.PageReplacementPolicy) RandomPageReplacementPolicy(herddb.core.RandomPageReplacementPolicy) Test(org.junit.Test)

Example 8 with RandomPageReplacementPolicy

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

the class BlockRangeIndexBench method testHuge.

@Test
public void testHuge() {
    final int testSize = 1_000_000;
    final int tenPerc = testSize / 10;
    long _start = System.currentTimeMillis();
    BlockRangeIndex<Sized<Integer>, Sized<String>> index = new BlockRangeIndex<>(10000, new RandomPageReplacementPolicy(10000));
    index.boot(BlockRangeIndexMetadata.empty());
    for (int i = 0; i < testSize; i++) {
        index.put(Sized.valueOf(i), Sized.valueOf("test_" + i));
        if (i % tenPerc == 0) {
            System.out.println("insert : " + (1 + i / tenPerc) * 10 + "%: " + i);
        }
    }
    long _stop = System.currentTimeMillis();
    System.out.println("time w: " + (_stop - _start));
    System.out.println("num segments: " + index.getNumBlocks());
    for (int i = 0; i < testSize; i++) {
        List<Sized<String>> s = index.search(Sized.valueOf(i));
        Assert.assertEquals(1, s.size());
        Assert.assertEquals("test_" + i, s.get(0).dummy);
        if (i % tenPerc == 0) {
            System.out.println("search : " + (1 + i / tenPerc) * 10 + "%: " + i);
        }
    }
    _start = _stop;
    _stop = System.currentTimeMillis();
    System.out.println("time r: " + (_stop - _start));
    index.clear();
}
Also used : Sized(herddb.utils.Sized) RandomPageReplacementPolicy(herddb.core.RandomPageReplacementPolicy) Test(org.junit.Test)

Example 9 with RandomPageReplacementPolicy

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

the class BlockRangeIndexTest method testSimpleSplitInverse.

@Test
public void testSimpleSplitInverse() {
    BlockRangeIndex<Sized<Integer>, Sized<String>> index = new BlockRangeIndex<>(400, new RandomPageReplacementPolicy(10));
    index.boot(BlockRangeIndexMetadata.empty());
    index.put(Sized.valueOf(3), Sized.valueOf("c"));
    index.put(Sized.valueOf(2), Sized.valueOf("b"));
    index.put(Sized.valueOf(1), Sized.valueOf("a"));
    dumpIndex(index);
    assertEquals(Sized.valueOf("a"), index.search(Sized.valueOf(1)).get(0));
    assertEquals(Sized.valueOf("b"), index.search(Sized.valueOf(2)).get(0));
    assertEquals(Sized.valueOf("c"), index.search(Sized.valueOf(3)).get(0));
    assertEquals(2, index.getNumBlocks());
}
Also used : Sized(herddb.utils.Sized) RandomPageReplacementPolicy(herddb.core.RandomPageReplacementPolicy) Test(org.junit.Test)

Example 10 with RandomPageReplacementPolicy

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

the class BlockRangeIndexTest method testMultiple.

@Test
public void testMultiple() {
    BlockRangeIndex<Sized<Integer>, Sized<String>> index = new BlockRangeIndex<>(1024, new RandomPageReplacementPolicy(10));
    index.boot(BlockRangeIndexMetadata.empty());
    for (int i = 0; i < 10; i++) {
        index.put(Sized.valueOf(i), Sized.valueOf("test_" + i));
    }
    for (int i = 0; i < 10; i++) {
        List<Sized<String>> result = index.search(Sized.valueOf(i));
        assertEquals(1, result.size());
        assertEquals(Sized.valueOf("test_" + i), result.get(0));
    }
    for (int i = 0; i < 10; i++) {
        index.put(Sized.valueOf(i), Sized.valueOf("test_" + i));
    }
    for (int i = 0; i < 10; i++) {
        if (i == 6) {
            System.out.println("QUI");
        }
        List<Sized<String>> result = index.search(Sized.valueOf(i));
        System.out.println("result for " + i + " :" + result);
        assertEquals(2, result.size());
        assertEquals(Sized.valueOf("test_" + i), result.get(0));
        assertEquals(Sized.valueOf("test_" + i), result.get(1));
    }
    List<Sized<String>> range = index.search(Sized.valueOf(3), Sized.valueOf(5));
    assertEquals(6, range.size());
    for (int i = 0; i < 10; i++) {
        index.delete(Sized.valueOf(i), Sized.valueOf("test_" + i));
        index.delete(Sized.valueOf(i), Sized.valueOf("test_" + i));
    }
    for (int i = 0; i < 10; i++) {
        List<Sized<String>> result = index.search(Sized.valueOf(i));
        assertEquals(0, result.size());
    }
}
Also used : Sized(herddb.utils.Sized) RandomPageReplacementPolicy(herddb.core.RandomPageReplacementPolicy) 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