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