Search in sources :

Example 1 with FilesFacade

use of io.questdb.std.FilesFacade in project questdb by bluestreak01.

the class SymbolCache method of.

void of(CairoConfiguration configuration, Path path, CharSequence columnName, int symbolIndexInTxFile) {
    FilesFacade ff = configuration.getFilesFacade();
    transientSymCountOffset = TableUtils.getSymbolWriterTransientIndexOffset(symbolIndexInTxFile);
    final int plen = path.length();
    txMem.of(ff, path.concat(TableUtils.TXN_FILE_NAME).$(), transientSymCountOffset, // must ensure there is mapped memory
    transientSymCountOffset + 4, MemoryTag.MMAP_INDEX_READER);
    int symCount = txMem.getInt(transientSymCountOffset);
    path.trimTo(plen);
    symbolMapReader.of(configuration, path, columnName, symCount);
    symbolValueToKeyMap.clear(symCount);
}
Also used : FilesFacade(io.questdb.std.FilesFacade)

Example 2 with FilesFacade

use of io.questdb.std.FilesFacade in project questdb by bluestreak01.

the class TxnTest method testFailedTxWriterDoesNotCorruptTable.

@Test
public void testFailedTxWriterDoesNotCorruptTable() throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        FilesFacade errorFf = new FilesFacadeImpl() {

            @Override
            public long mremap(long fd, long addr, long previousSize, long newSize, long offset, int mode, int memoryTag) {
                return -1;
            }
        };
        FilesFacadeImpl cleanFf = new FilesFacadeImpl();
        assertMemoryLeak(() -> {
            String tableName = "txntest";
            try (Path path = new Path()) {
                try (MemoryMARW mem = Vm.getCMARWInstance();
                    TableModel model = new TableModel(configuration, tableName, PartitionBy.DAY)) {
                    model.timestamp();
                    TableUtils.createTable(configuration, mem, path, model, 1);
                }
            }
            try (Path path = new Path()) {
                path.of(configuration.getRoot()).concat(tableName);
                int testPartitionCount = 3000;
                try (TxWriter txWriter = new TxWriter(cleanFf, path, PartitionBy.DAY)) {
                    // Add lots of partitions
                    for (int i = 0; i < testPartitionCount; i++) {
                        txWriter.updatePartitionSizeByTimestamp(i * Timestamps.DAY_MICROS, i + 1);
                    }
                    txWriter.updateMaxTimestamp(testPartitionCount * Timestamps.DAY_MICROS + 1);
                    txWriter.finishPartitionSizeUpdate();
                    txWriter.commit(CommitMode.SYNC, new ObjList<>());
                }
                // Reopen without OS errors
                try (TxWriter txWriter = new TxWriter(cleanFf, path, PartitionBy.DAY)) {
                    // Read lots of partitions
                    Assert.assertEquals(testPartitionCount, txWriter.getPartitionCount());
                    for (int i = 0; i < testPartitionCount - 1; i++) {
                        Assert.assertEquals(i + 1, txWriter.getPartitionSize(i));
                    }
                }
                // Open with OS error to file extend
                try (TxWriter ignored = new TxWriter(errorFf, path, PartitionBy.DAY)) {
                    Assert.fail("Should not be able to extend on opening");
                } catch (CairoException ex) {
                // expected
                }
                // Reopen without OS errors
                try (TxWriter txWriter = new TxWriter(cleanFf, path, PartitionBy.DAY)) {
                    // Read lots of partitions
                    Assert.assertEquals(testPartitionCount, txWriter.getPartitionCount());
                    for (int i = 0; i < testPartitionCount - 1; i++) {
                        Assert.assertEquals(i + 1, txWriter.getPartitionSize(i));
                    }
                }
            }
        });
    });
}
Also used : Path(io.questdb.std.str.Path) FilesFacade(io.questdb.std.FilesFacade) MemoryMARW(io.questdb.cairo.vm.api.MemoryMARW) FilesFacadeImpl(io.questdb.std.FilesFacadeImpl) Test(org.junit.Test)

Example 3 with FilesFacade

use of io.questdb.std.FilesFacade in project questdb by bluestreak01.

the class SqlParserTest method testTableNameCannotOpen.

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

        @Override
        public long openRO(LPSZ name) {
            if (Chars.endsWith(name, TableUtils.META_FILE_NAME)) {
                return -1;
            }
            return super.openRO(name);
        }
    };
    CairoConfiguration configuration = new DefaultCairoConfiguration(root) {

        @Override
        public FilesFacade getFilesFacade() {
            return ff;
        }
    };
    assertMemoryLeak(() -> {
        try (CairoEngine engine = new CairoEngine(configuration);
            SqlCompiler compiler = new SqlCompiler(engine)) {
            TableModel[] tableModels = new TableModel[] { modelOf("tab").col("x", ColumnType.INT) };
            try {
                try {
                    for (int i = 0, n = tableModels.length; i < n; i++) {
                        CairoTestUtils.create(tableModels[i]);
                    }
                    compiler.compile("select * from tab", sqlExecutionContext);
                    Assert.fail("Exception expected");
                } catch (SqlException e) {
                    Assert.assertEquals(14, e.getPosition());
                    TestUtils.assertContains(e.getFlyweightMessage(), "could not open");
                }
            } finally {
                for (int i = 0, n = tableModels.length; i < n; i++) {
                    TableModel tableModel = tableModels[i];
                    Path path = tableModel.getPath().of(tableModel.getConfiguration().getRoot()).concat(tableModel.getName()).slash$();
                    Assert.assertEquals(0, configuration.getFilesFacade().rmdir(path));
                    tableModel.close();
                }
            }
        }
    });
}
Also used : Path(io.questdb.std.str.Path) FilesFacade(io.questdb.std.FilesFacade) LPSZ(io.questdb.std.str.LPSZ) FilesFacadeImpl(io.questdb.std.FilesFacadeImpl) Test(org.junit.Test)

Example 4 with FilesFacade

use of io.questdb.std.FilesFacade in project questdb by bluestreak01.

the class O3CopyJob method copyTail.

private static void copyTail(AtomicInteger columnCounter, @Nullable AtomicInteger partCounter, long timestampMergeIndexAddr, long srcDataFixFd, long srcDataFixAddr, long srcDataFixSize, long srcDataVarFd, long srcDataVarAddr, long srcDataVarSize, long srcDataMax, long srcOooMax, long srcOooPartitionLo, long srcOooPartitionHi, long timestampMin, long timestampMax, long partitionTimestamp, long dstFixFd, long dstFixAddr, long dstFixSize, long dstVarFd, long dstVarAddr, long dstVarSize, long dstKFd, long dstVFd, long dstIndexOffset, long dstIndexAdjust, boolean isIndexed, long srcTimestampFd, long srcTimestampAddr, long srcTimestampSize, boolean partitionMutates, TableWriter tableWriter, BitmapIndexWriter indexWriter) {
    if (partCounter == null || partCounter.decrementAndGet() == 0) {
        final FilesFacade ff = tableWriter.getFilesFacade();
        if (isIndexed) {
            updateIndex(columnCounter, timestampMergeIndexAddr, srcDataFixFd, srcDataFixAddr, srcDataFixSize, srcDataVarFd, srcDataVarAddr, srcDataVarSize, dstFixFd, dstFixAddr, Math.abs(dstFixSize), dstVarFd, dstVarAddr, Math.abs(dstVarSize), dstKFd, dstVFd, dstIndexOffset, dstIndexAdjust, srcTimestampFd, srcTimestampAddr, srcTimestampSize, tableWriter, indexWriter);
        }
        // unmap memory
        O3Utils.unmapAndClose(ff, srcDataFixFd, srcDataFixAddr, srcDataFixSize);
        O3Utils.unmapAndClose(ff, srcDataVarFd, srcDataVarAddr, srcDataVarSize);
        O3Utils.unmapAndClose(ff, dstFixFd, dstFixAddr, dstFixSize);
        O3Utils.unmapAndClose(ff, dstVarFd, dstVarAddr, dstVarSize);
        final int columnsRemaining = columnCounter.decrementAndGet();
        LOG.debug().$("organic [columnsRemaining=").$(columnsRemaining).I$();
        if (columnsRemaining == 0) {
            updatePartition(timestampMergeIndexAddr, srcDataMax, srcOooMax, srcOooPartitionLo, srcOooPartitionHi, timestampMin, timestampMax, partitionTimestamp, srcTimestampFd, srcTimestampAddr, srcTimestampSize, partitionMutates, tableWriter);
        }
    }
}
Also used : FilesFacade(io.questdb.std.FilesFacade)

Example 5 with FilesFacade

use of io.questdb.std.FilesFacade in project questdb by bluestreak01.

the class O3CopyJob method closeColumnIdleQuick.

static void closeColumnIdleQuick(long timestampMergeIndexAddr, long srcTimestampFd, long srcTimestampAddr, long srcTimestampSize, TableWriter tableWriter) {
    try {
        final FilesFacade ff = tableWriter.getFilesFacade();
        O3Utils.unmap(ff, srcTimestampAddr, srcTimestampSize);
        O3Utils.close(ff, srcTimestampFd);
        if (timestampMergeIndexAddr != 0) {
            Vect.freeMergedIndex(timestampMergeIndexAddr);
        }
    } finally {
        tableWriter.o3ClockDownPartitionUpdateCount();
        tableWriter.o3CountDownDoneLatch();
    }
}
Also used : FilesFacade(io.questdb.std.FilesFacade)

Aggregations

FilesFacade (io.questdb.std.FilesFacade)29 FilesFacadeImpl (io.questdb.std.FilesFacadeImpl)14 Test (org.junit.Test)14 Path (io.questdb.std.str.Path)13 MemoryMARW (io.questdb.cairo.vm.api.MemoryMARW)6 AbstractGriffinTest (io.questdb.griffin.AbstractGriffinTest)4 RecordCursorFactory (io.questdb.cairo.sql.RecordCursorFactory)3 SqlCompiler (io.questdb.griffin.SqlCompiler)3 LPSZ (io.questdb.std.str.LPSZ)3 MemoryCMARWImpl (io.questdb.cairo.vm.MemoryCMARWImpl)2 Rnd (io.questdb.std.Rnd)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 TableModel (io.questdb.cairo.TableModel)1 MemoryARW (io.questdb.cairo.vm.api.MemoryARW)1 LineTcpSender (io.questdb.cutlass.line.LineTcpSender)1 SqlException (io.questdb.griffin.SqlException)1 BindVariableServiceImpl (io.questdb.griffin.engine.functions.bind.BindVariableServiceImpl)1 DateFormat (io.questdb.std.datetime.DateFormat)1 TimestampFormatCompiler (io.questdb.std.datetime.microtime.TimestampFormatCompiler)1 File (java.io.File)1