Search in sources :

Example 41 with FilesFacadeImpl

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

the class AlterTableCommitLagTest method setMaxUncommittedRowsFailsToReopenBackMetaFile.

@Test
public void setMaxUncommittedRowsFailsToReopenBackMetaFile() throws Exception {
    assertMemoryLeak(() -> {
        try (TableModel tbl = new TableModel(configuration, "X", PartitionBy.DAY)) {
            createX(tbl);
        }
        engine.releaseAllWriters();
        ff = new FilesFacadeImpl() {

            int attempt = 0;

            @Override
            public long openRO(LPSZ path) {
                if (Chars.endsWith(path, TableUtils.META_FILE_NAME) && attempt++ == 1) {
                    return -1;
                }
                return super.openRO(path);
            }
        };
        String alterCommand = "ALTER TABLE X SET PARAM maxUncommittedRows = 11111";
        try {
            compiler.compile(alterCommand, sqlExecutionContext);
            Assert.fail("Alter table should fail");
        } catch (CairoError e) {
            TestUtils.assertContains(e.getFlyweightMessage(), "could not open read-only");
        }
        try (TableReader rdr = engine.getReader(AllowAllCairoSecurityContext.INSTANCE, "X")) {
            Assert.assertEquals(11111, rdr.getMetadata().getMaxUncommittedRows());
        }
        engine.releaseAllReaders();
        engine.releaseAllWriters();
    });
}
Also used : LPSZ(io.questdb.std.str.LPSZ) FilesFacadeImpl(io.questdb.std.FilesFacadeImpl) Test(org.junit.Test)

Example 42 with FilesFacadeImpl

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

the class AlterTableCommitLagTest method setMaxUncommittedRowsFailsToSwapMetadataOnce.

@Test
public void setMaxUncommittedRowsFailsToSwapMetadataOnce() throws Exception {
    assertMemoryLeak(() -> {
        try (TableModel tbl = new TableModel(configuration, "X", PartitionBy.DAY)) {
            CairoTestUtils.create(tbl.timestamp("ts").col("i", ColumnType.INT).col("l", ColumnType.LONG));
            ff = new FilesFacadeImpl() {

                int attempt = 0;

                @Override
                public boolean rename(LPSZ from, LPSZ to) {
                    if (Chars.endsWith(to, TableUtils.META_FILE_NAME) && attempt++ == 0) {
                        return false;
                    }
                    return super.rename(from, to);
                }
            };
            String alterCommand = "ALTER TABLE X SET PARAM maxUncommittedRows = 11111";
            try {
                compiler.compile(alterCommand, sqlExecutionContext);
                Assert.fail("Alter table should fail");
            } catch (SqlException e) {
                TestUtils.assertContains(e.getFlyweightMessage(), "table 'X' could not be altered");
            }
            try (TableReader rdr = engine.getReader(AllowAllCairoSecurityContext.INSTANCE, "X")) {
                Assert.assertEquals(configuration.getMaxUncommittedRows(), rdr.getMetadata().getMaxUncommittedRows());
            }
            // Now try with success.
            ff = new FilesFacadeImpl();
            compiler.compile(alterCommand, sqlExecutionContext);
            assertSql("SELECT maxUncommittedRows FROM tables() WHERE name = 'X'", "maxUncommittedRows\n11111\n");
        }
    });
}
Also used : LPSZ(io.questdb.std.str.LPSZ) FilesFacadeImpl(io.questdb.std.FilesFacadeImpl) Test(org.junit.Test)

Example 43 with FilesFacadeImpl

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

the class O3FailureTest method testColumnTopMidMergeBlankFailRetryOpenRw2.

@Test
public void testColumnTopMidMergeBlankFailRetryOpenRw2() 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 + "b.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 44 with FilesFacadeImpl

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

the class O3FailureTest method testPartitionedDataAppendOOPrependOODataMapVar.

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

        private long theFd = 0;

        @Override
        public long mmap(long fd, long len, long offset, int flags, int memoryTag) {
            if (theFd == fd) {
                theFd = 0;
                return -1;
            }
            return super.mmap(fd, len, offset, flags, memoryTag);
        }

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

Example 45 with FilesFacadeImpl

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

the class O3FailureTest method testPartitionedDataAppendOODataIndexedContended.

@Test
public void testPartitionedDataAppendOODataIndexedContended() throws Exception {
    counter.set(3);
    executeWithPool(0, O3FailureTest::testPartitionedDataAppendOODataIndexedFailRetry0, new FilesFacadeImpl() {

        @Override
        public long openRW(LPSZ name) {
            if (Chars.endsWith(name, "1970-01-06" + Files.SEPARATOR + "timestamp.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)

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