Search in sources :

Example 11 with Path

use of io.questdb.std.str.Path in project questdb by bluestreak01.

the class BitmapIndexTest method testForwardReaderKeyUpdateFail.

@Test
public void testForwardReaderKeyUpdateFail() {
    create(configuration, path.trimTo(plen), "x", 1024);
    try (BitmapIndexWriter writer = new BitmapIndexWriter(configuration, path, "x")) {
        writer.add(0, 1000);
    }
    try (BitmapIndexFwdReader reader = new BitmapIndexFwdReader(configuration, path.trimTo(plen), "x", 0)) {
        // should have single value in cursor
        RowCursor cursor = reader.getCursor(true, 0, 0, Long.MAX_VALUE);
        Assert.assertTrue(cursor.hasNext());
        Assert.assertEquals(1000, cursor.next());
        Assert.assertFalse(cursor.hasNext());
        try (Path path = new Path();
            MemoryCMARW mem = Vm.getSmallCMARWInstance(configuration.getFilesFacade(), path.of(root).concat("x").put(".k").$(), MemoryTag.MMAP_DEFAULT)) {
            // change sequence but not sequence check
            long seq = mem.getLong(BitmapIndexUtils.KEY_RESERVED_OFFSET_SEQUENCE);
            mem.putLong(BitmapIndexUtils.KEY_RESERVED_OFFSET_SEQUENCE, 22);
            try {
                reader.getCursor(true, 10, 0, Long.MAX_VALUE);
                Assert.fail();
            } catch (CairoException e) {
                Assert.assertTrue(Chars.contains(e.getMessage(), "could not consistently"));
            }
            try {
                reader.getCursor(true, 0, 0, Long.MAX_VALUE);
                Assert.fail();
            } catch (CairoException e) {
                Assert.assertTrue(Chars.contains(e.getMessage(), "could not consistently"));
            }
            mem.putLong(BitmapIndexUtils.KEY_RESERVED_OFFSET_SEQUENCE, seq);
            // test that index recovers
            cursor = reader.getCursor(true, 0, 0, Long.MAX_VALUE);
            Assert.assertTrue(cursor.hasNext());
            Assert.assertEquals(1000, cursor.next());
            Assert.assertFalse(cursor.hasNext());
        }
    }
}
Also used : Path(io.questdb.std.str.Path) RowCursor(io.questdb.cairo.sql.RowCursor) Test(org.junit.Test)

Example 12 with Path

use of io.questdb.std.str.Path in project questdb by bluestreak01.

the class BitmapIndexTest method openKey.

private MemoryA openKey() {
    try (Path path = new Path()) {
        MemoryMA mem = Vm.getSmallCMARWInstance(configuration.getFilesFacade(), path.of(configuration.getRoot()).concat("x").put(".k").$(), MemoryTag.MMAP_DEFAULT);
        mem.toTop();
        return mem;
    }
}
Also used : Path(io.questdb.std.str.Path)

Example 13 with Path

use of io.questdb.std.str.Path in project questdb by bluestreak01.

the class BitmapIndexTest method testForwardCursorTimeout.

@Test
public void testForwardCursorTimeout() throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        create(configuration, path.trimTo(plen), "x", 1024);
        try (BitmapIndexWriter w = new BitmapIndexWriter(configuration, path.trimTo(plen), "x")) {
            w.add(0, 10);
        }
        try (BitmapIndexFwdReader reader = new BitmapIndexFwdReader(configuration, path.trimTo(plen), "x", 0)) {
            try (MemoryMARW mem = Vm.getMARWInstance()) {
                try (Path path = new Path()) {
                    path.of(configuration.getRoot()).concat("x").put(".k").$();
                    mem.smallFile(configuration.getFilesFacade(), path, MemoryTag.MMAP_DEFAULT);
                }
                long offset = BitmapIndexUtils.getKeyEntryOffset(0);
                mem.putLong(offset + BitmapIndexUtils.KEY_ENTRY_OFFSET_VALUE_COUNT, 10);
                try {
                    reader.getCursor(true, 0, 0, Long.MAX_VALUE);
                    Assert.fail();
                } catch (CairoException e) {
                    Assert.assertTrue(Chars.contains(e.getMessage(), "cursor could not consistently read index header"));
                }
            }
        }
    });
}
Also used : Path(io.questdb.std.str.Path) Test(org.junit.Test)

Example 14 with Path

use of io.questdb.std.str.Path 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 15 with Path

use of io.questdb.std.str.Path in project questdb by bluestreak01.

the class CairoMemoryTest method testWriteAndRead.

@Test
public void testWriteAndRead() 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);
            }
            // read in place
            for (int i = 0; i < N; i++) {
                Assert.assertEquals(i, mem.getLong(i * 8));
            }
            Assert.assertEquals(8L * N, mem.getAppendOffset());
        }
        try (MemoryCMARW mem = Vm.getSmallCMARWInstance(FF, path, MemoryTag.MMAP_DEFAULT)) {
            final int M = (int) (mem.size() / Long.BYTES);
            for (int i = 0; i < M; i++) {
                Assert.assertEquals(i, mem.getLong(i * 8L));
            }
        }
    }
    Assert.assertEquals(used, Unsafe.getMemUsed());
}
Also used : Path(io.questdb.std.str.Path) MemoryCMARW(io.questdb.cairo.vm.api.MemoryCMARW) Test(org.junit.Test)

Aggregations

Path (io.questdb.std.str.Path)141 Test (org.junit.Test)89 File (java.io.File)14 FilesFacade (io.questdb.std.FilesFacade)13 MemoryCMARW (io.questdb.cairo.vm.api.MemoryCMARW)10 MemoryMR (io.questdb.cairo.vm.api.MemoryMR)10 Rnd (io.questdb.std.Rnd)10 AbstractCairoTest (io.questdb.cairo.AbstractCairoTest)7 MemoryMA (io.questdb.cairo.vm.api.MemoryMA)7 MemoryMARW (io.questdb.cairo.vm.api.MemoryMARW)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 AbstractGriffinTest (io.questdb.griffin.AbstractGriffinTest)6 NativeLPSZ (io.questdb.std.str.NativeLPSZ)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 SOCountDownLatch (io.questdb.mp.SOCountDownLatch)5 LPSZ (io.questdb.std.str.LPSZ)5 RecordCursor (io.questdb.cairo.sql.RecordCursor)4 RowCursor (io.questdb.cairo.sql.RowCursor)4 MemoryARW (io.questdb.cairo.vm.api.MemoryARW)4 RingQueue (io.questdb.mp.RingQueue)4