use of io.questdb.cairo.vm.api.MemoryMR in project questdb by bluestreak01.
the class CairoMemoryTest method testWriteAndReadWithReadOnlyMem.
@Test
public void testWriteAndReadWithReadOnlyMem() throws Exception {
long used = Unsafe.getMemUsed();
try (Path path = new Path().of(temp.newFile().getAbsolutePath()).$()) {
try (MemoryCMARW mem = Vm.getCMARWInstance(FF, path, 2 * FF.getPageSize(), -1, MemoryTag.MMAP_DEFAULT)) {
for (int i = 0; i < N; i++) {
mem.putLong(i);
}
Assert.assertEquals(8L * N, mem.getAppendOffset());
}
try (MemoryMR mem = new MemoryCMRImpl(FF, path, 8L * N, MemoryTag.MMAP_DEFAULT)) {
for (int i = 0; i < N; i++) {
Assert.assertEquals(i, mem.getLong(i * 8));
}
}
}
Assert.assertEquals(used, Unsafe.getMemUsed());
}
use of io.questdb.cairo.vm.api.MemoryMR in project questdb by bluestreak01.
the class CairoMemoryTest method testVirtualMemoryJump.
private void testVirtualMemoryJump(VirtualMemoryFactory factory) throws Exception {
TestUtils.assertMemoryLeak(() -> {
try (Path path = new Path().of(temp.newFile().getAbsolutePath()).$()) {
try (MemoryARW mem = factory.newInstance(path)) {
for (int i = 0; i < 100; i++) {
mem.putLong(i);
}
mem.jumpTo(0);
for (int i = 0; i < 50; i++) {
mem.putLong(50 - i);
}
// keep previously written data
mem.jumpTo(800);
}
try (MemoryMR roMem = new MemoryCMRImpl(FF, path, 800, MemoryTag.MMAP_DEFAULT)) {
for (int i = 0; i < 50; i++) {
Assert.assertEquals(50 - i, roMem.getLong(i * 8));
}
for (int i = 50; i < 100; i++) {
Assert.assertEquals(i, roMem.getLong(i * 8));
}
}
}
});
}
use of io.questdb.cairo.vm.api.MemoryMR in project questdb by bluestreak01.
the class TableReaderMetadata method createTransitionIndex.
public long createTransitionIndex() {
if (transitionMeta == null) {
transitionMeta = Vm.getMRInstance();
}
transitionMeta.smallFile(ff, path, MemoryTag.MMAP_DEFAULT);
try (MemoryMR metaMem = transitionMeta) {
tmpValidationMap.clear();
TableUtils.validate(ff, metaMem, tmpValidationMap, ColumnType.VERSION);
return TableUtils.createTransitionIndex(metaMem, this.metaMem, this.columnCount, this.columnNameIndexMap);
}
}
use of io.questdb.cairo.vm.api.MemoryMR in project questdb by bluestreak01.
the class BinarySearchTest method testFindReverseTwoValues.
@Test
public void testFindReverseTwoValues() throws Exception {
assertMemoryLeak(() -> {
try (Path path = new Path()) {
path.of(root).concat("binsearch.d").$();
try (MemoryMA appendMem = Vm.getSmallCMARWInstance(FilesFacadeImpl.INSTANCE, path, MemoryTag.MMAP_DEFAULT)) {
appendMem.putLong(1);
appendMem.putLong(3);
try (MemoryMR mem = Vm.getMRInstance(FilesFacadeImpl.INSTANCE, path, 400 * Long.BYTES, MemoryTag.MMAP_DEFAULT)) {
Assert.assertEquals(0, BinarySearch.find(mem, 2, 0, 1, BinarySearch.SCAN_UP));
}
}
}
});
}
use of io.questdb.cairo.vm.api.MemoryMR in project questdb by bluestreak01.
the class BinarySearchTest method testFindForwardTwoValues.
@Test
public void testFindForwardTwoValues() {
try (Path path = new Path()) {
path.of(root).concat("binsearch.d").$();
try (MemoryMA appendMem = Vm.getSmallCMARWInstance(FilesFacadeImpl.INSTANCE, path, MemoryTag.MMAP_DEFAULT)) {
appendMem.putLong(1);
appendMem.putLong(3);
try (MemoryMR mem = Vm.getMRInstance(FilesFacadeImpl.INSTANCE, path, 400 * Long.BYTES, MemoryTag.MMAP_DEFAULT)) {
Assert.assertEquals(0, BinarySearch.find(mem, 2, 0, 1, BinarySearch.SCAN_DOWN));
}
}
}
}
Aggregations