Search in sources :

Example 41 with LPSZ

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

the class AlterTableCommitLagTest method setMaxUncommittedRowsFailsToSwapMetadataUntilWriterReopen.

@Test
public void setMaxUncommittedRowsFailsToSwapMetadataUntilWriterReopen() 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() {

                @Override
                public boolean rename(LPSZ from, LPSZ to) {
                    if (Chars.endsWith(to, TableUtils.META_FILE_NAME)) {
                        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 (CairoError e) {
                TestUtils.assertContains(e.getFlyweightMessage(), "could not rename");
            }
            try (TableReader ignored = engine.getReader(AllowAllCairoSecurityContext.INSTANCE, "X")) {
                Assert.fail();
            } catch (CairoException ignored) {
            }
            // Now try with success.
            engine.releaseAllWriters();
            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 42 with LPSZ

use of io.questdb.std.str.LPSZ 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 43 with LPSZ

use of io.questdb.std.str.LPSZ 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 44 with LPSZ

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

the class AlterTableAttachPartitionTest method testCannotMapTimestampColumn.

@Test
public void testCannotMapTimestampColumn() throws Exception {
    AtomicInteger counter = new AtomicInteger(1);
    FilesFacadeImpl ff = new FilesFacadeImpl() {

        private long tsdFd;

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

        @Override
        public long openRO(LPSZ name) {
            long fd = super.openRO(name);
            if (Chars.endsWith(name, "ts.d") && counter.decrementAndGet() == 0) {
                this.tsdFd = fd;
            }
            return fd;
        }
    };
    testSqlFailedOnFsOperation(ff, "could not mmap");
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) LPSZ(io.questdb.std.str.LPSZ) Test(org.junit.Test)

Example 45 with LPSZ

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

the class AlterTableAttachPartitionTest method testCannotReadTimestampColumn.

@Test
public void testCannotReadTimestampColumn() throws Exception {
    AtomicInteger counter = new AtomicInteger(1);
    FilesFacadeImpl ff = new FilesFacadeImpl() {

        @Override
        public long openRO(LPSZ name) {
            if (Chars.endsWith(name, "ts.d") && counter.decrementAndGet() == 0) {
                return -1;
            }
            return super.openRO(name);
        }
    };
    testSqlFailedOnFsOperation(ff, "table 'dst' could not be altered: [", "]: could not open");
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) LPSZ(io.questdb.std.str.LPSZ) Test(org.junit.Test)

Aggregations

LPSZ (io.questdb.std.str.LPSZ)50 Test (org.junit.Test)49 FilesFacadeImpl (io.questdb.std.FilesFacadeImpl)35 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)11 RecordCursor (io.questdb.cairo.sql.RecordCursor)8 Record (io.questdb.cairo.sql.Record)7 Path (io.questdb.std.str.Path)5 FilesFacade (io.questdb.std.FilesFacade)3 RecordCursorFactory (io.questdb.cairo.sql.RecordCursorFactory)1 MemoryCMARW (io.questdb.cairo.vm.api.MemoryCMARW)1 MemoryMA (io.questdb.cairo.vm.api.MemoryMA)1 TestMicroClock (io.questdb.test.tools.TestMicroClock)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1