Search in sources :

Example 76 with Path

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

the class TableWriterTest method testRenameColumn.

private void testRenameColumn(TableModel model) throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        CairoTestUtils.create(model);
        long ts = TimestampFormatUtils.parseTimestamp("2013-03-04T00:00:00.000Z");
        Rnd rnd = new Rnd();
        try (TableWriter writer = new TableWriter(configuration, model.getName())) {
            // optional
            writer.warmUp();
            ts = append10KProducts(ts, rnd, writer);
            int columnTypeTag = ColumnType.tagOf(writer.getMetadata().getColumnType("supplier"));
            writer.renameColumn("supplier", "sup");
            final NativeLPSZ lpsz = new NativeLPSZ();
            try (Path path = new Path()) {
                path.of(root).concat(model.getName());
                final int plen = path.length();
                if (columnTypeTag == ColumnType.SYMBOL) {
                    Assert.assertFalse(FF.exists(path.trimTo(plen).concat(lpsz).concat("supplier.v").$()));
                    Assert.assertFalse(FF.exists(path.trimTo(plen).concat(lpsz).concat("supplier.o").$()));
                    Assert.assertFalse(FF.exists(path.trimTo(plen).concat(lpsz).concat("supplier.c").$()));
                    Assert.assertFalse(FF.exists(path.trimTo(plen).concat(lpsz).concat("supplier.k").$()));
                    Assert.assertTrue(FF.exists(path.trimTo(plen).concat(lpsz).concat("sup.v").$()));
                    Assert.assertTrue(FF.exists(path.trimTo(plen).concat(lpsz).concat("sup.o").$()));
                    Assert.assertTrue(FF.exists(path.trimTo(plen).concat(lpsz).concat("sup.c").$()));
                    Assert.assertTrue(FF.exists(path.trimTo(plen).concat(lpsz).concat("sup.k").$()));
                }
                path.trimTo(plen);
                FF.iterateDir(path.$(), (file, type) -> {
                    lpsz.of(file);
                    if (type == Files.DT_DIR && !Files.isDots(lpsz)) {
                        Assert.assertFalse(FF.exists(path.trimTo(plen).concat(lpsz).concat("supplier.i").$()));
                        Assert.assertFalse(FF.exists(path.trimTo(plen).concat(lpsz).concat("supplier.d").$()));
                        Assert.assertFalse(FF.exists(path.trimTo(plen).concat(lpsz).concat("supplier.top").$()));
                        Assert.assertTrue(FF.exists(path.trimTo(plen).concat(lpsz).concat("sup.d").$()));
                        if (columnTypeTag == ColumnType.BINARY || columnTypeTag == ColumnType.STRING) {
                            Assert.assertTrue(FF.exists(path.trimTo(plen).concat(lpsz).concat("sup.i").$()));
                        }
                    }
                });
            }
            ts = append10KWithNewName(ts, rnd, writer);
            writer.commit();
            Assert.assertEquals(20000, writer.size());
        }
        try (TableWriter writer = new TableWriter(configuration, model.getName())) {
            append10KWithNewName(ts, rnd, writer);
            writer.commit();
            Assert.assertEquals(30000, writer.size());
        }
    });
}
Also used : Path(io.questdb.std.str.Path) NativeLPSZ(io.questdb.std.str.NativeLPSZ)

Example 77 with Path

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

the class TableWriterTest method testSkipOverSpuriousDir.

@Test
public void testSkipOverSpuriousDir() throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        create(FF, PartitionBy.DAY, 10);
        try (Path path = new Path()) {
            // create random directory
            path.of(configuration.getRoot()).concat(PRODUCT).concat("somethingortheother").slash$();
            Assert.assertEquals(0, configuration.getFilesFacade().mkdirs(path, configuration.getMkDirMode()));
            new TableWriter(configuration, PRODUCT).close();
            Assert.assertFalse(configuration.getFilesFacade().exists(path));
        }
    });
}
Also used : Path(io.questdb.std.str.Path) Test(org.junit.Test)

Example 78 with Path

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

the class TableReaderMetadataTimestampTest method assertThatTimestampRemains.

private void assertThatTimestampRemains(TableReaderMetadataTest.ColumnManipulator manipulator, String expected, int expectedInitialTimestampIndex, int expectedFinalTimestampIndex, int expectedColumnCount) throws Exception {
    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")) {
                    manipulator.restructure(writer);
                }
                long address = metadata.createTransitionIndex();
                StringSink sink = new StringSink();
                try {
                    metadata.applyTransitionIndex(address);
                    Assert.assertEquals(expectedColumnCount, metadata.getColumnCount());
                    for (int i = 0; i < expectedColumnCount; i++) {
                        sink.put(metadata.getColumnName(i)).put(':').put(ColumnType.nameOf(metadata.getColumnType(i))).put('\n');
                    }
                    TestUtils.assertEquals(expected, sink);
                    Assert.assertEquals(expectedFinalTimestampIndex, metadata.getTimestampIndex());
                } finally {
                    TableUtils.freeTransitionIndex(address);
                }
            }
        }
    });
}
Also used : Path(io.questdb.std.str.Path) StringSink(io.questdb.std.str.StringSink)

Example 79 with Path

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

the class TableWriterTest method testIncorrectTodoCode.

@Test
public void testIncorrectTodoCode() throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        CairoTestUtils.createAllTable(configuration, PartitionBy.NONE);
        try (MemoryCMARW mem = Vm.getCMARWInstance();
            Path path = new Path().of(root).concat("all").concat(TableUtils.TODO_FILE_NAME).$()) {
            mem.smallFile(FilesFacadeImpl.INSTANCE, path, MemoryTag.MMAP_DEFAULT);
            mem.putLong(32, 1);
            mem.putLong(40, 9990001L);
            mem.jumpTo(48);
        }
        try (TableWriter writer = new TableWriter(configuration, "all")) {
            Assert.assertNotNull(writer);
            Assert.assertTrue(writer.isOpen());
        }
        try (TableWriter writer = new TableWriter(configuration, "all")) {
            Assert.assertNotNull(writer);
            Assert.assertTrue(writer.isOpen());
        }
    });
}
Also used : Path(io.questdb.std.str.Path) MemoryCMARW(io.questdb.cairo.vm.api.MemoryCMARW) Test(org.junit.Test)

Example 80 with Path

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

the class EngineMigration method migrateEngineTo.

public static void migrateEngineTo(CairoEngine engine, int latestVersion, boolean force) {
    final FilesFacade ff = engine.getConfiguration().getFilesFacade();
    final CairoConfiguration configuration = engine.getConfiguration();
    int tempMemSize = 8;
    long mem = Unsafe.malloc(tempMemSize, MemoryTag.NATIVE_DEFAULT);
    try (MemoryARW virtualMem = Vm.getARWInstance(ff.getPageSize(), Integer.MAX_VALUE, MemoryTag.NATIVE_DEFAULT);
        Path path = new Path();
        MemoryMARW rwMemory = Vm.getMARWInstance()) {
        MigrationContext context = new MigrationContext(engine, mem, tempMemSize, virtualMem, rwMemory);
        path.of(configuration.getRoot());
        // check if all tables have been upgraded already
        path.concat(TableUtils.UPGRADE_FILE_NAME).$();
        final boolean existed = !force && ff.exists(path);
        long upgradeFd = openFileRWOrFail(ff, path);
        LOG.debug().$("open [fd=").$(upgradeFd).$(", path=").$(path).$(']').$();
        if (existed) {
            int currentVersion = TableUtils.readIntOrFail(ff, upgradeFd, 0, mem, path);
            if (currentVersion >= latestVersion) {
                LOG.info().$("table structures are up to date").$();
                ff.close(upgradeFd);
                upgradeFd = -1;
            }
        }
        if (upgradeFd != -1) {
            try {
                LOG.info().$("upgrading database [version=").$(latestVersion).I$();
                if (upgradeTables(context, latestVersion)) {
                    TableUtils.writeIntOrFail(ff, upgradeFd, 0, latestVersion, mem, path);
                }
            } finally {
                Vm.bestEffortClose(ff, LOG, upgradeFd, true, Integer.BYTES);
            }
        }
    } finally {
        Unsafe.free(mem, tempMemSize, MemoryTag.NATIVE_DEFAULT);
    }
}
Also used : Path(io.questdb.std.str.Path) MemoryMARW(io.questdb.cairo.vm.api.MemoryMARW) MemoryARW(io.questdb.cairo.vm.api.MemoryARW)

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