use of herddb.utils.Sized in project herddb by diennea.
the class BlockRangeIndexBench method testHuge.
@Test
public // @Ignore
void testHuge() {
final int testSize = 1_000_000;
long _start = System.currentTimeMillis();
BlockRangeIndex<Sized<Integer>, Sized<String>> index = new BlockRangeIndex<>(10000, new RandomPageReplacementPolicy(10000));
for (int i = 0; i < testSize; i++) {
index.put(Sized.valueOf(i), Sized.valueOf("test_" + 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++) {
index.search(Sized.valueOf(i));
// index.lookUpRange(i, i + 1000);
}
_start = _stop;
_stop = System.currentTimeMillis();
System.out.println("time r: " + (_stop - _start));
index.clear();
}
use of herddb.utils.Sized in project herddb by diennea.
the class BlockRangeIndexConcurrentTest method testConcurrentReadsWritesDeletesWithSplits.
@Test
public void testConcurrentReadsWritesDeletesWithSplits() throws Exception {
int testSize = 1000;
int parallelism = 6;
BlockRangeIndex<Sized<Integer>, Sized<String>> index = new BlockRangeIndex<>(1024, new RandomPageReplacementPolicy(3));
ExecutorService threadpool = Executors.newFixedThreadPool(parallelism);
CountDownLatch l = new CountDownLatch(testSize);
ConcurrentLinkedQueue<Sized<String>> results = new ConcurrentLinkedQueue<>();
ConcurrentLinkedQueue<Sized<String>> results2 = new ConcurrentLinkedQueue<>();
try {
for (int i = 0; i < testSize; i++) {
int _i = i;
threadpool.submit(() -> {
try {
index.put(Sized.valueOf(_i), Sized.valueOf("a" + _i));
List<Sized<String>> search = index.search(Sized.valueOf(_i));
results.addAll(search);
if (search.isEmpty()) {
throw new IllegalStateException("Empty Search! i " + _i);
}
index.delete(Sized.valueOf(_i), Sized.valueOf("a" + _i));
List<Sized<String>> search2 = index.search(Sized.valueOf(_i));
results2.addAll(search2);
l.countDown();
} catch (Throwable t) {
t.printStackTrace();
}
});
}
} finally {
threadpool.shutdown();
}
assertTrue(l.await(10, TimeUnit.SECONDS));
dumpIndex(index);
verifyIndex(index);
List<Sized<String>> result = index.lookUpRange(Sized.valueOf(0), Sized.valueOf(testSize + 1));
assertTrue(result.isEmpty());
System.out.println(results);
for (int i = 0; i < testSize; i++) {
assertTrue("cannot find a" + i, results.contains(Sized.valueOf("a" + i)));
}
assertTrue(results2.isEmpty());
}
use of herddb.utils.Sized in project herddb by diennea.
the class BlockRangeIndexConcurrentTest method testConcurrentReadsWritesWithSplits.
@Test
public void testConcurrentReadsWritesWithSplits() throws Exception {
int testSize = 1000;
int parallelism = 6;
BlockRangeIndex<Sized<Integer>, Sized<String>> index = new BlockRangeIndex<>(1024, new RandomPageReplacementPolicy(3));
ExecutorService threadpool = Executors.newFixedThreadPool(parallelism);
CountDownLatch l = new CountDownLatch(testSize);
ConcurrentLinkedQueue<Sized<String>> results = new ConcurrentLinkedQueue<>();
try {
for (int i = 0; i < testSize; i++) {
int _i = i;
threadpool.submit(() -> {
try {
index.put(Sized.valueOf(_i), Sized.valueOf("a" + _i));
List<Sized<String>> search = index.search(Sized.valueOf(_i));
results.addAll(search);
if (search.isEmpty()) {
throw new IllegalStateException("Empty Search! i " + _i);
}
l.countDown();
} catch (RuntimeException e) {
e.printStackTrace();
}
});
}
} finally {
threadpool.shutdown();
}
assertTrue(l.await(10, TimeUnit.SECONDS));
dumpIndex(index);
verifyIndex(index);
List<Sized<String>> result = index.lookUpRange(Sized.valueOf(0), Sized.valueOf(testSize + 1));
for (Sized<String> res : result) {
System.out.println("res " + res.dummy);
}
for (int i = 0; i < testSize; i++) {
assertTrue("cannot find " + i, index.containsKey(Sized.valueOf(i)));
assertTrue("cannot find a" + i, results.contains(Sized.valueOf("a" + i)));
}
}
use of herddb.utils.Sized in project herddb by diennea.
the class BlockRangeIndexStorageTest method testSimple.
@Test
public void testSimple() throws Exception {
IndexDataStorage<Sized<Integer>, Sized<String>> storage = new IndexDataStorage<Sized<Integer>, Sized<String>>() {
AtomicLong newPageId = new AtomicLong();
private ConcurrentHashMap<Long, List<Map.Entry<Sized<Integer>, Sized<String>>>> pages = new ConcurrentHashMap<>();
@Override
public List<Map.Entry<Sized<Integer>, Sized<String>>> loadDataPage(long pageId) throws IOException {
return pages.get(pageId);
}
@Override
public long createDataPage(List<Map.Entry<Sized<Integer>, Sized<String>>> values) throws IOException {
long newid = newPageId.incrementAndGet();
pages.put(newid, values);
return newid;
}
};
BlockRangeIndex<Sized<Integer>, Sized<String>> index = new BlockRangeIndex<>(400, new RandomPageReplacementPolicy(10), storage);
index.put(Sized.valueOf(1), Sized.valueOf("a"));
index.put(Sized.valueOf(2), Sized.valueOf("b"));
index.put(Sized.valueOf(3), Sized.valueOf("c"));
BlockRangeIndexMetadata<Sized<Integer>> metadata = index.checkpoint();
assertEquals(index.getNumBlocks(), metadata.getBlocksMetadata().size());
BlockRangeIndex<Sized<Integer>, Sized<String>> indexAfterBoot = new BlockRangeIndex<>(1024, new RandomPageReplacementPolicy(10), storage);
indexAfterBoot.boot(metadata);
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, indexAfterBoot.getNumBlocks());
}
use of herddb.utils.Sized in project herddb by diennea.
the class BlockRangeIndexStorageTest method testUnload.
@Test
public void testUnload() throws Exception {
IndexDataStorage<Sized<Integer>, Sized<String>> storage = new IndexDataStorage<Sized<Integer>, Sized<String>>() {
AtomicLong newPageId = new AtomicLong();
private ConcurrentHashMap<Long, List<Map.Entry<Sized<Integer>, Sized<String>>>> pages = new ConcurrentHashMap<>();
@Override
public List<Map.Entry<Sized<Integer>, Sized<String>>> loadDataPage(long pageId) throws IOException {
return pages.get(pageId);
}
@Override
public long createDataPage(List<Map.Entry<Sized<Integer>, Sized<String>>> values) throws IOException {
long newid = newPageId.incrementAndGet();
pages.put(newid, values);
return newid;
}
};
PageReplacementPolicy policy = new RandomPageReplacementPolicy(10);
BlockRangeIndex<Sized<Integer>, Sized<String>> index = new BlockRangeIndex<>(1024, policy, storage);
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());
}
Aggregations