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");
}
});
}
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();
});
}
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");
}
});
}
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");
}
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");
}
Aggregations