Search in sources :

Example 1 with Path

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

the class TableReaderMetadataCorruptionTest method assertTransitionIndexValidation.

private void assertTransitionIndexValidation(int columnCount) throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        try (Path path = new Path()) {
            CairoTestUtils.createAllTable(configuration, PartitionBy.NONE);
            path.of(root).concat("all").concat(TableUtils.META_FILE_NAME).$();
            long len = FilesFacadeImpl.INSTANCE.length(path);
            try (TableReaderMetadata metadata = new TableReaderMetadata(FilesFacadeImpl.INSTANCE, path)) {
                try (MemoryCMARW mem = Vm.getCMARWInstance()) {
                    mem.smallFile(FilesFacadeImpl.INSTANCE, path, MemoryTag.MMAP_DEFAULT);
                    mem.jumpTo(0);
                    mem.putInt(columnCount);
                    mem.skip(len - 4);
                }
                try {
                    metadata.createTransitionIndex();
                } catch (CairoException e) {
                    TestUtils.assertContains(e.getFlyweightMessage(), "Invalid metadata at ");
                }
            }
        }
    });
}
Also used : Path(io.questdb.std.str.Path) MemoryCMARW(io.questdb.cairo.vm.api.MemoryCMARW)

Example 2 with Path

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

the class TableReaderMetadataCorruptionTest method assertMetaConstructorFailure.

private void assertMetaConstructorFailure(String[] names, int[] types, int columnCount, int timestampIndex, String contains, long pageSize) throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        try (Path path = new Path()) {
            path.of(root).concat("x");
            final int rootLen = path.length();
            if (FilesFacadeImpl.INSTANCE.mkdirs(path.slash$(), configuration.getMkDirMode()) == -1) {
                throw CairoException.instance(FilesFacadeImpl.INSTANCE.errno()).put("Cannot create dir: ").put(path);
            }
            try (MemoryMA mem = Vm.getMAInstance()) {
                mem.of(FilesFacadeImpl.INSTANCE, path.trimTo(rootLen).concat(TableUtils.META_FILE_NAME).$(), pageSize, MemoryTag.MMAP_DEFAULT);
                mem.putInt(columnCount);
                mem.putInt(PartitionBy.NONE);
                mem.putInt(timestampIndex);
                mem.putInt(ColumnType.VERSION);
                mem.jumpTo(TableUtils.META_OFFSET_COLUMN_TYPES);
                for (int i = 0; i < names.length; i++) {
                    mem.putInt(types[i]);
                    mem.putLong(0);
                    mem.putInt(0);
                    mem.skip(16);
                }
                for (int i = 0; i < names.length; i++) {
                    mem.putStr(names[i]);
                }
            }
            try {
                new TableReaderMetadata(FilesFacadeImpl.INSTANCE, path);
                Assert.fail();
            } catch (CairoException e) {
                TestUtils.assertContains(e.getFlyweightMessage(), contains);
            }
        }
    });
}
Also used : Path(io.questdb.std.str.Path) MemoryMA(io.questdb.cairo.vm.api.MemoryMA)

Example 3 with Path

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

the class TableReaderMetadataTimestampTest method assertThat.

private void assertThat(String expected, int expectedInitialTimestampIndex) throws Exception {
    int columnCount = 11;
    TestUtils.assertMemoryLeak(() -> {
        try (Path path = new Path().of(root).concat("all")) {
            try (TableReaderMetadata metadata = new TableReaderMetadata(FilesFacadeImpl.INSTANCE, path.concat(TableUtils.META_FILE_NAME).$())) {
                Assert.assertEquals(12, metadata.getColumnCount());
                Assert.assertEquals(expectedInitialTimestampIndex, metadata.getTimestampIndex());
                try (TableWriter writer = new TableWriter(configuration, "all")) {
                    writer.removeColumn("timestamp");
                }
                long pTransitionIndex = metadata.createTransitionIndex();
                StringSink sink = new StringSink();
                try {
                    metadata.applyTransitionIndex(pTransitionIndex);
                    Assert.assertEquals(columnCount, metadata.getColumnCount());
                    for (int i = 0; i < columnCount; i++) {
                        sink.put(metadata.getColumnName(i)).put(':').put(ColumnType.nameOf(metadata.getColumnType(i))).put('\n');
                    }
                    TestUtils.assertEquals(expected, sink);
                    Assert.assertEquals(-1, metadata.getTimestampIndex());
                } finally {
                    TableUtils.freeTransitionIndex(pTransitionIndex);
                }
            }
        }
    });
}
Also used : Path(io.questdb.std.str.Path) StringSink(io.questdb.std.str.StringSink)

Example 4 with Path

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

the class TableWriterTest method testCancelRowRecoveryFromAppendPosErrors.

@Test
public void testCancelRowRecoveryFromAppendPosErrors() throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        final Rnd rnd = new Rnd();
        class X extends FilesFacadeImpl {

            boolean fail = false;

            @Override
            public int rmdir(Path name) {
                if (fail) {
                    return -1;
                }
                return super.rmdir(name);
            }
        }
        X ff = new X();
        final int N = 10000;
        create(ff, PartitionBy.DAY, N);
        // supposed to be stored have matching partitions
        try (MemoryARW vmem = Vm.getARWInstance(ff.getPageSize(), Integer.MAX_VALUE, MemoryTag.NATIVE_DEFAULT)) {
            try (TableWriter writer = new TableWriter(new DefaultCairoConfiguration(root) {

                @Override
                public FilesFacade getFilesFacade() {
                    return ff;
                }
            }, PRODUCT)) {
                long ts = TimestampFormatUtils.parseTimestamp("2013-03-04T00:00:00.000Z");
                int i = 0;
                int cancelCount = 0;
                int failCount = 0;
                while (i < N) {
                    TableWriter.Row r = writer.newRow(ts += 60000 * 1000L);
                    r.putInt(0, rnd.nextPositiveInt());
                    r.putStr(1, rnd.nextString(7));
                    r.putSym(2, rnd.nextString(4));
                    r.putSym(3, rnd.nextString(11));
                    r.putDouble(4, rnd.nextDouble());
                    if (rnd.nextPositiveInt() % 50 == 0) {
                        ff.fail = true;
                        try {
                            r.cancel();
                        } catch (CairoException ignored) {
                            failCount++;
                            ff.fail = false;
                            r.cancel();
                        } finally {
                            ff.fail = false;
                        }
                        cancelCount++;
                    } else {
                        r.append();
                        // second append() is expected to be a NOOP
                        r.append();
                        vmem.putLong(ts);
                        i++;
                    }
                }
                writer.commit();
                Assert.assertEquals(N, writer.size());
                Assert.assertTrue(cancelCount > 0);
                Assert.assertTrue(failCount > 0);
                verifyTimestampPartitions(vmem);
            }
        }
    });
}
Also used : Path(io.questdb.std.str.Path) MemoryARW(io.questdb.cairo.vm.api.MemoryARW) Test(org.junit.Test)

Example 5 with Path

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

the class TableWriterTest method verifyTimestampPartitions.

void verifyTimestampPartitions(MemoryARW vmem) {
    int i;
    TimestampFormatCompiler compiler = new TimestampFormatCompiler();
    DateFormat fmt = compiler.compile("yyyy-MM-dd");
    DateLocale enGb = DateLocaleFactory.INSTANCE.getLocale("en-gb");
    try (Path vp = new Path()) {
        for (i = 0; i < 10000; i++) {
            vp.of(root).concat(PRODUCT).slash();
            fmt.format(vmem.getLong(i * 8L), enGb, "UTC", vp);
            if (!FF.exists(vp.$())) {
                Assert.fail();
            }
        }
    }
}
Also used : DateLocale(io.questdb.std.datetime.DateLocale) Path(io.questdb.std.str.Path) TimestampFormatCompiler(io.questdb.std.datetime.microtime.TimestampFormatCompiler) DateFormat(io.questdb.std.datetime.DateFormat)

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