use of io.questdb.std.str.Path in project questdb by bluestreak01.
the class TableReaderMetadataCorruptionTest method assertTransitionIndexValidation.
private void assertTransitionIndexValidation(int columnCount) throws Exception {
TestUtils.assertMemoryLeak(() -> {
try (Path path = new Path()) {
CairoTestUtils.createAllTable(configuration, PartitionBy.NONE);
path.of(root).concat("all").concat(TableUtils.META_FILE_NAME).$();
long len = FilesFacadeImpl.INSTANCE.length(path);
try (TableReaderMetadata metadata = new TableReaderMetadata(FilesFacadeImpl.INSTANCE, path)) {
try (MemoryCMARW mem = Vm.getCMARWInstance()) {
mem.smallFile(FilesFacadeImpl.INSTANCE, path, MemoryTag.MMAP_DEFAULT);
mem.jumpTo(0);
mem.putInt(columnCount);
mem.skip(len - 4);
}
try {
metadata.createTransitionIndex();
} catch (CairoException e) {
TestUtils.assertContains(e.getFlyweightMessage(), "Invalid metadata at ");
}
}
}
});
}
use of io.questdb.std.str.Path in project questdb by bluestreak01.
the class TableReaderMetadataCorruptionTest method assertMetaConstructorFailure.
private void assertMetaConstructorFailure(String[] names, int[] types, int columnCount, int timestampIndex, String contains, long pageSize) throws Exception {
TestUtils.assertMemoryLeak(() -> {
try (Path path = new Path()) {
path.of(root).concat("x");
final int rootLen = path.length();
if (FilesFacadeImpl.INSTANCE.mkdirs(path.slash$(), configuration.getMkDirMode()) == -1) {
throw CairoException.instance(FilesFacadeImpl.INSTANCE.errno()).put("Cannot create dir: ").put(path);
}
try (MemoryMA mem = Vm.getMAInstance()) {
mem.of(FilesFacadeImpl.INSTANCE, path.trimTo(rootLen).concat(TableUtils.META_FILE_NAME).$(), pageSize, MemoryTag.MMAP_DEFAULT);
mem.putInt(columnCount);
mem.putInt(PartitionBy.NONE);
mem.putInt(timestampIndex);
mem.putInt(ColumnType.VERSION);
mem.jumpTo(TableUtils.META_OFFSET_COLUMN_TYPES);
for (int i = 0; i < names.length; i++) {
mem.putInt(types[i]);
mem.putLong(0);
mem.putInt(0);
mem.skip(16);
}
for (int i = 0; i < names.length; i++) {
mem.putStr(names[i]);
}
}
try {
new TableReaderMetadata(FilesFacadeImpl.INSTANCE, path);
Assert.fail();
} catch (CairoException e) {
TestUtils.assertContains(e.getFlyweightMessage(), contains);
}
}
});
}
use of io.questdb.std.str.Path in project questdb by bluestreak01.
the class TableReaderMetadataTimestampTest method assertThat.
private void assertThat(String expected, int expectedInitialTimestampIndex) throws Exception {
int columnCount = 11;
TestUtils.assertMemoryLeak(() -> {
try (Path path = new Path().of(root).concat("all")) {
try (TableReaderMetadata metadata = new TableReaderMetadata(FilesFacadeImpl.INSTANCE, path.concat(TableUtils.META_FILE_NAME).$())) {
Assert.assertEquals(12, metadata.getColumnCount());
Assert.assertEquals(expectedInitialTimestampIndex, metadata.getTimestampIndex());
try (TableWriter writer = new TableWriter(configuration, "all")) {
writer.removeColumn("timestamp");
}
long pTransitionIndex = metadata.createTransitionIndex();
StringSink sink = new StringSink();
try {
metadata.applyTransitionIndex(pTransitionIndex);
Assert.assertEquals(columnCount, metadata.getColumnCount());
for (int i = 0; i < columnCount; i++) {
sink.put(metadata.getColumnName(i)).put(':').put(ColumnType.nameOf(metadata.getColumnType(i))).put('\n');
}
TestUtils.assertEquals(expected, sink);
Assert.assertEquals(-1, metadata.getTimestampIndex());
} finally {
TableUtils.freeTransitionIndex(pTransitionIndex);
}
}
}
});
}
use of io.questdb.std.str.Path in project questdb by bluestreak01.
the class TableWriterTest method testCancelRowRecoveryFromAppendPosErrors.
@Test
public void testCancelRowRecoveryFromAppendPosErrors() throws Exception {
TestUtils.assertMemoryLeak(() -> {
final Rnd rnd = new Rnd();
class X extends FilesFacadeImpl {
boolean fail = false;
@Override
public int rmdir(Path name) {
if (fail) {
return -1;
}
return super.rmdir(name);
}
}
X ff = new X();
final int N = 10000;
create(ff, PartitionBy.DAY, N);
// supposed to be stored have matching partitions
try (MemoryARW vmem = Vm.getARWInstance(ff.getPageSize(), Integer.MAX_VALUE, MemoryTag.NATIVE_DEFAULT)) {
try (TableWriter writer = new TableWriter(new DefaultCairoConfiguration(root) {
@Override
public FilesFacade getFilesFacade() {
return ff;
}
}, PRODUCT)) {
long ts = TimestampFormatUtils.parseTimestamp("2013-03-04T00:00:00.000Z");
int i = 0;
int cancelCount = 0;
int failCount = 0;
while (i < N) {
TableWriter.Row r = writer.newRow(ts += 60000 * 1000L);
r.putInt(0, rnd.nextPositiveInt());
r.putStr(1, rnd.nextString(7));
r.putSym(2, rnd.nextString(4));
r.putSym(3, rnd.nextString(11));
r.putDouble(4, rnd.nextDouble());
if (rnd.nextPositiveInt() % 50 == 0) {
ff.fail = true;
try {
r.cancel();
} catch (CairoException ignored) {
failCount++;
ff.fail = false;
r.cancel();
} finally {
ff.fail = false;
}
cancelCount++;
} else {
r.append();
// second append() is expected to be a NOOP
r.append();
vmem.putLong(ts);
i++;
}
}
writer.commit();
Assert.assertEquals(N, writer.size());
Assert.assertTrue(cancelCount > 0);
Assert.assertTrue(failCount > 0);
verifyTimestampPartitions(vmem);
}
}
});
}
use of io.questdb.std.str.Path in project questdb by bluestreak01.
the class TableWriterTest method verifyTimestampPartitions.
void verifyTimestampPartitions(MemoryARW vmem) {
int i;
TimestampFormatCompiler compiler = new TimestampFormatCompiler();
DateFormat fmt = compiler.compile("yyyy-MM-dd");
DateLocale enGb = DateLocaleFactory.INSTANCE.getLocale("en-gb");
try (Path vp = new Path()) {
for (i = 0; i < 10000; i++) {
vp.of(root).concat(PRODUCT).slash();
fmt.format(vmem.getLong(i * 8L), enGb, "UTC", vp);
if (!FF.exists(vp.$())) {
Assert.fail();
}
}
}
}
Aggregations