Search in sources :

Example 6 with LPSZ

use of com.questdb.std.str.LPSZ in project questdb by bluestreak01.

the class TableReadFailTest method testTxnFileMissingConstructor.

@Test
public void testTxnFileMissingConstructor() throws Exception {
    FilesFacade ff = new FilesFacadeImpl() {

        @Override
        public boolean exists(LPSZ path) {
            return !Chars.endsWith(path, TableUtils.TXN_FILE_NAME) && super.exists(path);
        }
    };
    assertConstructorFail(ff);
}
Also used : FilesFacade(com.questdb.std.FilesFacade) LPSZ(com.questdb.std.str.LPSZ) FilesFacadeImpl(com.questdb.std.FilesFacadeImpl) Test(org.junit.Test)

Example 7 with LPSZ

use of com.questdb.std.str.LPSZ in project questdb by bluestreak01.

the class TableUtilsTest method testCreateFailure.

@Test
public void testCreateFailure() throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        class X extends FilesFacadeImpl {

            @Override
            public int mkdirs(LPSZ path, int mode) {
                return -1;
            }
        }
        X ff = new X();
        JournalMetadata metadata = getJournalStructure().build();
        try (AppendMemory appendMemory = new AppendMemory()) {
            try (Path path = new Path()) {
                TableUtils.create(ff, path, appendMemory, temp.getRoot().getAbsolutePath(), metadata, 509);
                Assert.fail();
            } catch (CairoException e) {
                Assert.assertNotNull(e.getMessage());
            }
        }
    });
}
Also used : Path(com.questdb.std.str.Path) JournalMetadata(com.questdb.store.factory.configuration.JournalMetadata) LPSZ(com.questdb.std.str.LPSZ) FilesFacadeImpl(com.questdb.std.FilesFacadeImpl) Test(org.junit.Test)

Example 8 with LPSZ

use of com.questdb.std.str.LPSZ in project questdb by bluestreak01.

the class CairoLineProtoParserTest method testCannotCreateTable.

@Test
public void testCannotCreateTable() throws Exception {
    TestFilesFacade ff = new TestFilesFacade() {

        boolean called = false;

        @Override
        public int mkdirs(LPSZ path, int mode) {
            if (Chars.endsWith(path, "x" + Files.SEPARATOR)) {
                called = true;
                return -1;
            }
            return super.mkdirs(path, mode);
        }

        @Override
        public boolean wasCalled() {
            return called;
        }
    };
    final String expected = "sym\tdouble\tint\tbool\tstr\ttimestamp\n" + "zzz\t1.300000000000\t11\tfalse\tnice\t2017-10-03T10:00:00.000Z\n";
    String lines = "x,sym2=xyz double=1.6,int=15i,bool=true,str=\"string1\"\n" + "x,sym1=abc double=1.3,int=11i,bool=false,str=\"string2\"\n" + "y,sym=zzz double=1.3,int=11i,bool=false,str=\"nice\"\n";
    CairoConfiguration configuration = new DefaultCairoConfiguration(root) {

        @Override
        public FilesFacade getFilesFacade() {
            return ff;
        }

        @Override
        public MicrosecondClock getClock() {
            try {
                return new TestMicroClock(DateFormatUtils.parseDateTime("2017-10-03T10:00:00.000Z"), 10);
            } catch (NumericException e) {
                throw new RuntimeException(e);
            }
        }
    };
    assertThat(expected, lines, "y", configuration);
    Assert.assertTrue(ff.wasCalled());
    try (Path path = new Path()) {
        Assert.assertEquals(TableUtils.TABLE_DOES_NOT_EXIST, TableUtils.exists(ff, path, root, "all"));
    }
}
Also used : Path(com.questdb.std.str.Path) LPSZ(com.questdb.std.str.LPSZ) NumericException(com.questdb.common.NumericException) TestMicroClock(com.questdb.test.tools.TestMicroClock) Test(org.junit.Test)

Example 9 with LPSZ

use of com.questdb.std.str.LPSZ in project questdb by bluestreak01.

the class CairoMemoryTest method testAppendAndCannotRead.

@Test
public void testAppendAndCannotRead() throws Exception {
    long used = Unsafe.getMemUsed();
    class X extends FilesFacadeImpl {

        int count = 2;

        @Override
        public long openRO(LPSZ name) {
            return --count > 0 ? -1 : super.openRO(name);
        }
    }
    X ff = new X();
    try (Path path = new Path().of(temp.newFile().getAbsolutePath()).$()) {
        try (AppendMemory mem = new AppendMemory(FF, path, 2 * FF.getPageSize())) {
            for (int i = 0; i < N; i++) {
                mem.putLong(i);
            }
            Assert.assertEquals(8L * N, mem.getAppendOffset());
        }
        try (ReadOnlyMemory mem = new ReadOnlyMemory()) {
            // open non-existing
            try {
                mem.of(ff, path, ff.getPageSize(), 8L * N);
                Assert.fail();
            } catch (CairoException ignore) {
            }
            mem.of(ff, path, ff.getPageSize(), 8L * N);
            for (int i = 0; i < N; i++) {
                Assert.assertEquals(i, mem.getLong(i * 8));
            }
        }
    }
    Assert.assertEquals(used, Unsafe.getMemUsed());
}
Also used : Path(com.questdb.std.str.Path) LPSZ(com.questdb.std.str.LPSZ) Test(org.junit.Test)

Example 10 with LPSZ

use of com.questdb.std.str.LPSZ in project questdb by bluestreak01.

the class FullTableFrameCursorTest method testParallelIndexFailureAtRuntime.

private void testParallelIndexFailureAtRuntime(int partitionBy, long increment, boolean empty, String fileUnderAttack, int expectedPartitionCount) throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        int N = 10000;
        int S = 512;
        Rnd rnd = new Rnd();
        Rnd eRnd = new Rnd();
        FilesFacade ff = new FilesFacadeImpl() {

            private long fd = -1;

            private int mapCount = 0;

            @Override
            public long getMapPageSize() {
                return 65535;
            }

            @Override
            public long mmap(long fd, long len, long offset, int mode) {
                // mess with the target FD
                if (fd == this.fd) {
                    if (mapCount == 1) {
                        return -1;
                    }
                    mapCount++;
                }
                return super.mmap(fd, len, offset, mode);
            }

            @Override
            public long openRW(LPSZ name) {
                // remember FD of the file we are targeting
                if (Chars.endsWith(name, fileUnderAttack)) {
                    return fd = super.openRW(name);
                }
                return super.openRW(name);
            }
        };
        CairoConfiguration configuration = new DefaultCairoConfiguration(root) {

            @Override
            public FilesFacade getFilesFacade() {
                return ff;
            }

            @Override
            public int getParallelIndexThreshold() {
                return 1;
            }
        };
        SymbolGroup sg = new SymbolGroup(rnd, S, N, partitionBy);
        // align pseudo-random generators
        // we have to do this because asserting code will not be re-populating symbol group
        eRnd.syncWith(rnd);
        long timestamp = 0;
        if (!empty) {
            timestamp = sg.appendABC(AbstractCairoTest.configuration, rnd, N, timestamp, increment);
        }
        int nWorkers = 2;
        CountDownLatch workerHaltLatch = new CountDownLatch(nWorkers);
        Worker[] workers;
        RingQueue<ColumnIndexerEntry> queue = new RingQueue<>(ColumnIndexerEntry::new, 1024);
        MPSequence pubSeq;
        MCSequence subSeq;
        ObjHashSet<Job> jobs = new ObjHashSet<>();
        pubSeq = new MPSequence(queue.getCapacity());
        subSeq = new MCSequence(queue.getCapacity(), null);
        pubSeq.then(subSeq).then(pubSeq);
        jobs.add(new ColumnIndexerJob(queue, subSeq));
        workers = new Worker[nWorkers];
        for (int i = 0; i < nWorkers; i++) {
            workers[i] = new Worker(jobs, workerHaltLatch);
            workers[i].start();
        }
        try (TableWriter writer = new TableWriter(configuration, "ABC", queue, pubSeq)) {
            try {
                for (int i = 0; i < (long) N; i++) {
                    TableWriter.Row r = writer.newRow(timestamp += increment);
                    r.putSym(0, sg.symA[rnd.nextPositiveInt() % sg.S]);
                    r.putSym(1, sg.symB[rnd.nextPositiveInt() % sg.S]);
                    r.putSym(2, sg.symC[rnd.nextPositiveInt() % sg.S]);
                    r.putDouble(3, rnd.nextDouble());
                    r.append();
                }
                writer.commit();
                Assert.fail();
            } catch (CairoError ignored) {
            }
            // test that we cannot commit
            try {
                writer.commit();
                Assert.fail();
            } catch (CairoError e) {
                TestUtils.assertContains(e.getMessage(), "distressed");
            }
            // test that we cannot rollback
            try {
                writer.rollback();
                Assert.fail();
            } catch (CairoError e) {
                TestUtils.assertContains(e.getMessage(), "distressed");
            }
        }
        // constructor must attempt to recover non-partitioned empty table
        if (empty && partitionBy == PartitionBy.NONE) {
            try {
                new TableWriter(configuration, "ABC");
                Assert.fail();
            } catch (CairoException ignore) {
            }
        }
        for (int i = 0; i < nWorkers; i++) {
            workers[i].halt();
        }
        workerHaltLatch.await();
        // lets see what we can read after this catastrophe
        try (TableReader reader = new TableReader(AbstractCairoTest.configuration, "ABC")) {
            FullTableFrameCursor cursor = new FullTableFrameCursor();
            TableReaderRecord record = new TableReaderRecord();
            Assert.assertEquals(expectedPartitionCount, reader.getPartitionCount());
            cursor.of(reader);
            record.of(reader);
            assertSymbolFoundInIndex(cursor, record, 0, empty ? 0 : N);
            cursor.toTop();
            assertSymbolFoundInIndex(cursor, record, 1, empty ? 0 : N);
            cursor.toTop();
            assertSymbolFoundInIndex(cursor, record, 2, empty ? 0 : N);
            cursor.toTop();
            assertIndexRowsMatchSymbol(cursor, record, 0, empty ? 0 : N);
            cursor.toTop();
            assertIndexRowsMatchSymbol(cursor, record, 1, empty ? 0 : N);
            cursor.toTop();
            assertIndexRowsMatchSymbol(cursor, record, 2, empty ? 0 : N);
            cursor.toTop();
            assertData(cursor, record, eRnd, sg, empty ? 0 : N);
            assertMetadataEquals(reader.getMetadata(), cursor.getReader().getMetadata());
            // we should be able to append more rows to new writer instance once the
            // original problem is resolved, e.g. system can mmap again
            sg.appendABC(AbstractCairoTest.configuration, rnd, N, timestamp, increment);
            Assert.assertTrue(cursor.reload());
            assertSymbolFoundInIndex(cursor, record, 0, empty ? N : N * 2);
            cursor.toTop();
            assertSymbolFoundInIndex(cursor, record, 1, empty ? N : N * 2);
            cursor.toTop();
            assertSymbolFoundInIndex(cursor, record, 2, empty ? N : N * 2);
            cursor.toTop();
            assertIndexRowsMatchSymbol(cursor, record, 0, empty ? N : N * 2);
            cursor.toTop();
            assertIndexRowsMatchSymbol(cursor, record, 1, empty ? N : N * 2);
            cursor.toTop();
            assertIndexRowsMatchSymbol(cursor, record, 2, empty ? N : N * 2);
        }
    });
}
Also used : LPSZ(com.questdb.std.str.LPSZ) CountDownLatch(java.util.concurrent.CountDownLatch)

Aggregations

LPSZ (com.questdb.std.str.LPSZ)13 Test (org.junit.Test)11 FilesFacadeImpl (com.questdb.std.FilesFacadeImpl)7 FilesFacade (com.questdb.std.FilesFacade)6 Path (com.questdb.std.str.Path)6 CairoEngine (com.questdb.cairo.sql.CairoEngine)1 NumericException (com.questdb.common.NumericException)1 NativeLPSZ (com.questdb.std.str.NativeLPSZ)1 JournalMetadata (com.questdb.store.factory.configuration.JournalMetadata)1 TestMicroClock (com.questdb.test.tools.TestMicroClock)1 CountDownLatch (java.util.concurrent.CountDownLatch)1