use of io.questdb.std.str.LPSZ in project questdb by bluestreak01.
the class TableReaderTest method testUnsuccessfulRemoveLastSym.
@Test
public void testUnsuccessfulRemoveLastSym() throws Exception {
TestUtils.assertMemoryLeak(() -> {
// create table with two string columns
try (TableModel model = new TableModel(configuration, "x", PartitionBy.NONE).col("a", ColumnType.SYMBOL).col("b", ColumnType.SYMBOL)) {
CairoTestUtils.create(model);
}
Rnd rnd = new Rnd();
final int N = 1000;
// make sure we forbid deleting column "b" files
TestFilesFacade ff = new TestFilesFacade() {
int counter = 5;
@Override
public boolean remove(LPSZ name) {
if (counter > 0 && ((Chars.endsWith(name, "b.i") || Chars.endsWith(name, "b.d") || Chars.endsWith(name, "b.o") || Chars.endsWith(name, "b.k") || Chars.endsWith(name, "b.c") || Chars.endsWith(name, "b.v")))) {
counter--;
return false;
}
return super.remove(name);
}
@Override
public boolean wasCalled() {
return counter < 1;
}
};
CairoConfiguration configuration = new DefaultCairoConfiguration(root) {
@Override
public FilesFacade getFilesFacade() {
return ff;
}
};
// populate table and delete column
try (TableWriter writer = new TableWriter(configuration, "x")) {
appendTwoSymbols(writer, rnd);
writer.commit();
try (TableReader reader = new TableReader(configuration, "x")) {
long counter = 0;
rnd.reset();
RecordCursor cursor = reader.getCursor();
final Record record = cursor.getRecord();
while (cursor.hasNext()) {
Assert.assertEquals(rnd.nextChars(10), record.getSym(0));
Assert.assertEquals(rnd.nextChars(15), record.getSym(1));
counter++;
}
Assert.assertEquals(N, counter);
// this should write metadata without column "b" but will ignore
// file delete failures
writer.removeColumn("b");
Assert.assertTrue(reader.reload());
Assert.assertEquals(N, reader.size());
rnd.reset();
cursor.toTop();
counter = 0;
while (cursor.hasNext()) {
Assert.assertEquals(rnd.nextChars(10), record.getSym(0));
// roll random generator to make sure it returns same values
rnd.nextChars(15);
counter++;
}
Assert.assertEquals(N, counter);
}
}
Assert.assertTrue(ff.wasCalled());
});
}
use of io.questdb.std.str.LPSZ in project questdb by bluestreak01.
the class TableReaderTest method testUnsuccessfulRemoveExplicitColCloseAndReloadSym.
@Test
public void testUnsuccessfulRemoveExplicitColCloseAndReloadSym() throws Exception {
TestUtils.assertMemoryLeak(() -> {
// create table with two string columns
try (TableModel model = new TableModel(configuration, "x", PartitionBy.NONE).col("a", ColumnType.SYMBOL).col("b", ColumnType.SYMBOL)) {
CairoTestUtils.create(model);
}
Rnd rnd = new Rnd();
final int N = 1000;
// make sure we forbid deleting column "b" files
TestFilesFacade ff = new TestFilesFacade() {
int counter = 5;
@Override
public boolean remove(LPSZ name) {
if (counter > 0 && ((Chars.endsWith(name, "b.i") || Chars.endsWith(name, "b.d") || Chars.endsWith(name, "b.o") || Chars.endsWith(name, "b.k") || Chars.endsWith(name, "b.c") || Chars.endsWith(name, "b.v")))) {
counter--;
return false;
}
return super.remove(name);
}
@Override
public boolean wasCalled() {
return counter < 1;
}
};
CairoConfiguration configuration = new DefaultCairoConfiguration(root) {
@Override
public FilesFacade getFilesFacade() {
return ff;
}
};
// populate table and delete column
try (TableWriter writer = new TableWriter(configuration, "x")) {
appendTwoSymbols(writer, rnd);
writer.commit();
try (TableReader reader = new TableReader(configuration, "x")) {
long counter = 0;
rnd.reset();
RecordCursor cursor = reader.getCursor();
final Record record = cursor.getRecord();
while (cursor.hasNext()) {
Assert.assertEquals(rnd.nextChars(10), record.getSym(0));
Assert.assertEquals(rnd.nextChars(15), record.getSym(1));
counter++;
}
Assert.assertEquals(N, counter);
// this should write metadata without column "b" but will ignore
// file delete failures
writer.removeColumn("b");
reader.closeColumnForRemove("b");
// now when we add new column by same name it must not pick up files we failed to delete previously
writer.addColumn("b", ColumnType.SYMBOL);
// SymbolMap must be cleared when we try to do add values to new column
appendTwoSymbols(writer, rnd);
writer.commit();
// now assert what reader sees
Assert.assertTrue(reader.reload());
Assert.assertEquals(N * 2, reader.size());
rnd.reset();
cursor.toTop();
counter = 0;
while (cursor.hasNext()) {
Assert.assertEquals(rnd.nextChars(10), record.getSym(0));
if (counter < N) {
// roll random generator to make sure it returns same values
rnd.nextChars(15);
Assert.assertNull(record.getSym(1));
} else {
Assert.assertEquals(rnd.nextChars(15), record.getSym(1));
}
counter++;
}
Assert.assertEquals(N * 2, counter);
}
}
Assert.assertTrue(ff.wasCalled());
});
}
use of io.questdb.std.str.LPSZ in project questdb by bluestreak01.
the class TableReaderTest method testCloseColumn.
private void testCloseColumn(int partitionBy, int count, long increment, String column, RecordAssert assertAfter) throws Exception {
final Rnd rnd = new Rnd();
final LongList fds = new LongList();
String dcol = column + ".d";
String icol = column + ".i";
TestFilesFacade ff = new TestFilesFacade() {
boolean called = false;
@Override
public boolean close(long fd) {
fds.remove(fd);
return super.close(fd);
}
@Override
public long openRO(LPSZ name) {
long fd = super.openRO(name);
if (Chars.endsWith(name, dcol) || Chars.endsWith(name, icol)) {
fds.add(fd);
called = true;
}
return fd;
}
@Override
public boolean wasCalled() {
return called;
}
};
long blob = allocBlob();
try {
TestUtils.assertMemoryLeak(() -> {
CairoTestUtils.createAllTable(configuration, partitionBy);
long ts = TimestampFormatUtils.parseTimestamp("2013-03-04T00:00:00.000Z");
CairoConfiguration configuration = new DefaultCairoConfiguration(root) {
@Override
public FilesFacade getFilesFacade() {
return ff;
}
};
testAppend(rnd, configuration, ts, count, increment, blob, 0);
try (TableReader reader = new TableReader(configuration, "all")) {
RecordCursor cursor = reader.getCursor();
assertCursor(cursor, ts, increment, blob, count, BATCH1_ASSERTER);
reader.closeColumnForRemove(column);
assertCursor(cursor, ts, increment, blob, count, assertAfter);
}
Assert.assertTrue(ff.wasCalled());
Assert.assertEquals(0, fds.size());
});
} finally {
freeBlob(blob);
}
}
use of io.questdb.std.str.LPSZ in project questdb by bluestreak01.
the class TxnScoreboardTest method testCleanFailsNoResourceLeak.
@Test
public void testCleanFailsNoResourceLeak() throws Exception {
TestUtils.assertMemoryLeak(() -> {
FilesFacade ff = new FilesFacadeImpl() {
@Override
public long openCleanRW(LPSZ name, long fd) {
return -1;
}
};
assertMemoryLeak(() -> {
try (final Path shmPath = new Path()) {
try (TxnScoreboard ignored = new TxnScoreboard(ff, shmPath.of(root), 2048)) {
Assert.fail();
} catch (CairoException ex) {
TestUtils.assertContains(ex.getFlyweightMessage(), "could not open read-write with clean allocation");
}
}
});
});
}
use of io.questdb.std.str.LPSZ in project questdb by bluestreak01.
the class O3FailureTest method testPartitionedOOPrefixesExistingPartitionsCreateDirsContended.
@Test
public void testPartitionedOOPrefixesExistingPartitionsCreateDirsContended() throws Exception {
counter.set(2);
executeWithPool(0, 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);
}
});
}
Aggregations