Search in sources :

Example 1 with FilesFacadeImpl

use of io.questdb.std.FilesFacadeImpl 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 2 with FilesFacadeImpl

use of io.questdb.std.FilesFacadeImpl 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 3 with FilesFacadeImpl

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

the class O3FailureTest method testPartitionedOOPrefixesExistingPartitionsCreateDirs.

@Test
public void testPartitionedOOPrefixesExistingPartitionsCreateDirs() throws Exception {
    counter.set(2);
    executeWithoutPool(O3FailureTest::testPartitionedOOPrefixesExistingPartitionsFailRetry0, new FilesFacadeImpl() {

        @Override
        public int mkdirs(LPSZ path, int mode) {
            if (Chars.contains(path, "1970-01-01") && counter.decrementAndGet() == 0) {
                return -1;
            }
            return super.mkdirs(path, mode);
        }
    });
}
Also used : LPSZ(io.questdb.std.str.LPSZ) FilesFacadeImpl(io.questdb.std.FilesFacadeImpl) Test(org.junit.Test)

Example 4 with FilesFacadeImpl

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

the class O3FailureTest method testColumnTopMidMergeBlankFailRetryOpenRw.

@Test
public void testColumnTopMidMergeBlankFailRetryOpenRw() throws Exception {
    counter.set(3);
    executeWithoutPool(O3FailureTest::testColumnTopMidMergeBlankColumnFailRetry0, new FilesFacadeImpl() {

        @Override
        public long openRW(LPSZ name) {
            if (Chars.endsWith(name, "1970-01-06" + Files.SEPARATOR + "m.d") && counter.decrementAndGet() == 0) {
                return -1;
            }
            return super.openRW(name);
        }
    });
}
Also used : LPSZ(io.questdb.std.str.LPSZ) FilesFacadeImpl(io.questdb.std.FilesFacadeImpl) Test(org.junit.Test)

Example 5 with FilesFacadeImpl

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

the class O3FailureTest method testFailOnTruncateKeyValueContended.

@Test
public void testFailOnTruncateKeyValueContended() throws Exception {
    counter.set(97);
    executeWithPool(0, (compiler, sqlExecutionContext, sqlExecutionContext2) -> testColumnTopLastOOOPrefixFailRetry0(sqlExecutionContext, sqlExecutionContext2), new FilesFacadeImpl() {

        @Override
        public boolean truncate(long fd, long size) {
            if (counter.decrementAndGet() == 0) {
                return false;
            }
            return super.truncate(fd, size);
        }
    });
}
Also used : FilesFacadeImpl(io.questdb.std.FilesFacadeImpl) Test(org.junit.Test)

Aggregations

FilesFacadeImpl (io.questdb.std.FilesFacadeImpl)48 Test (org.junit.Test)46 LPSZ (io.questdb.std.str.LPSZ)35 FilesFacade (io.questdb.std.FilesFacade)14 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 Path (io.questdb.std.str.Path)4 RecordCursorFactory (io.questdb.cairo.sql.RecordCursorFactory)3 AbstractGriffinTest (io.questdb.griffin.AbstractGriffinTest)3 SqlCompiler (io.questdb.griffin.SqlCompiler)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 MemoryMARW (io.questdb.cairo.vm.api.MemoryMARW)1 LineTcpSender (io.questdb.cutlass.line.LineTcpSender)1 SqlException (io.questdb.griffin.SqlException)1 BindVariableServiceImpl (io.questdb.griffin.engine.functions.bind.BindVariableServiceImpl)1 Rnd (io.questdb.std.Rnd)1 DateFormat (io.questdb.std.datetime.DateFormat)1 TimestampFormatCompiler (io.questdb.std.datetime.microtime.TimestampFormatCompiler)1 File (java.io.File)1