Search in sources :

Example 1 with MemoryMR

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());
}
Also used : Path(io.questdb.std.str.Path) MemoryCMARW(io.questdb.cairo.vm.api.MemoryCMARW) MemoryMR(io.questdb.cairo.vm.api.MemoryMR) MemoryCMRImpl(io.questdb.cairo.vm.MemoryCMRImpl) Test(org.junit.Test)

Example 2 with MemoryMR

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));
                }
            }
        }
    });
}
Also used : Path(io.questdb.std.str.Path) MemoryMR(io.questdb.cairo.vm.api.MemoryMR) MemoryCMRImpl(io.questdb.cairo.vm.MemoryCMRImpl) MemoryARW(io.questdb.cairo.vm.api.MemoryARW)

Example 3 with MemoryMR

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);
    }
}
Also used : MemoryMR(io.questdb.cairo.vm.api.MemoryMR)

Example 4 with MemoryMR

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));
                }
            }
        }
    });
}
Also used : Path(io.questdb.std.str.Path) MemoryMA(io.questdb.cairo.vm.api.MemoryMA) MemoryMR(io.questdb.cairo.vm.api.MemoryMR) Test(org.junit.Test)

Example 5 with MemoryMR

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));
            }
        }
    }
}
Also used : Path(io.questdb.std.str.Path) MemoryMA(io.questdb.cairo.vm.api.MemoryMA) MemoryMR(io.questdb.cairo.vm.api.MemoryMR) Test(org.junit.Test)

Aggregations

MemoryMR (io.questdb.cairo.vm.api.MemoryMR)15 Path (io.questdb.std.str.Path)10 MemoryCMRImpl (io.questdb.cairo.vm.MemoryCMRImpl)5 Test (org.junit.Test)5 MemoryCMARW (io.questdb.cairo.vm.api.MemoryCMARW)2 MemoryMA (io.questdb.cairo.vm.api.MemoryMA)2 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 MemoryARW (io.questdb.cairo.vm.api.MemoryARW)1 AbstractGriffinTest (io.questdb.griffin.AbstractGriffinTest)1