use of io.questdb.std.str.NativeLPSZ in project questdb by bluestreak01.
the class TableWriterTest method testRemoveColumn.
private void testRemoveColumn(TableModel model) throws Exception {
TestUtils.assertMemoryLeak(() -> {
CairoTestUtils.create(model);
long ts = TimestampFormatUtils.parseTimestamp("2013-03-04T00:00:00.000Z");
Rnd rnd = new Rnd();
try (TableWriter writer = new TableWriter(configuration, model.getName())) {
// optional
writer.warmUp();
ts = append10KProducts(ts, rnd, writer);
writer.removeColumn("supplier");
final NativeLPSZ lpsz = new NativeLPSZ();
try (Path path = new Path()) {
path.of(root).concat(model.getName());
final int plen = path.length();
FF.iterateDir(path.$(), (file, type) -> {
lpsz.of(file);
if (type == Files.DT_DIR && !Files.isDots(lpsz)) {
Assert.assertFalse(FF.exists(path.trimTo(plen).concat(lpsz).concat("supplier.i").$()));
Assert.assertFalse(FF.exists(path.trimTo(plen).concat(lpsz).concat("supplier.d").$()));
Assert.assertFalse(FF.exists(path.trimTo(plen).concat(lpsz).concat("supplier.top").$()));
}
});
}
ts = append10KNoSupplier(ts, rnd, writer);
writer.commit();
Assert.assertEquals(20000, writer.size());
}
try (TableWriter writer = new TableWriter(configuration, model.getName())) {
append10KNoSupplier(ts, rnd, writer);
writer.commit();
Assert.assertEquals(30000, writer.size());
}
});
}
use of io.questdb.std.str.NativeLPSZ in project questdb by bluestreak01.
the class FilesTest method testListDir.
@Test
public void testListDir() {
String temp = temporaryFolder.getRoot().getAbsolutePath();
ObjList<String> names = new ObjList<>();
try (Path path = new Path().of(temp).$()) {
try (Path cp = new Path()) {
Assert.assertTrue(Files.touch(cp.of(temp).concat("a.txt").$()));
NativeLPSZ name = new NativeLPSZ();
long pFind = Files.findFirst(path);
Assert.assertTrue(pFind != 0);
try {
do {
names.add(name.of(Files.findName(pFind)).toString());
} while (Files.findNext(pFind) > 0);
} finally {
Files.findClose(pFind);
}
}
}
names.sort(Chars::compare);
Assert.assertEquals("[.,..,a.txt]", names.toString());
}
use of io.questdb.std.str.NativeLPSZ in project questdb by bluestreak01.
the class EngineMigration method upgradeTables.
private static boolean upgradeTables(MigrationContext context, int latestVersion) {
final FilesFacade ff = context.getFf();
final CharSequence root = context.getConfiguration().getRoot();
long mem = context.getTempMemory(8);
final AtomicBoolean updateSuccess = new AtomicBoolean(true);
try (Path path = new Path();
Path copyPath = new Path()) {
path.of(root);
copyPath.of(root);
final int rootLen = path.length();
final NativeLPSZ nativeLPSZ = new NativeLPSZ();
ff.iterateDir(path.$(), (name, type) -> {
if (type == Files.DT_DIR) {
nativeLPSZ.of(name);
if (Chars.notDots(nativeLPSZ)) {
path.trimTo(rootLen);
path.concat(nativeLPSZ);
copyPath.trimTo(rootLen);
copyPath.concat(nativeLPSZ);
final int plen = path.length();
path.concat(TableUtils.META_FILE_NAME);
if (ff.exists(path.$())) {
final long fd = openFileRWOrFail(ff, path);
try {
int currentTableVersion = TableUtils.readIntOrFail(ff, fd, META_OFFSET_VERSION, mem, path);
if (currentTableVersion < latestVersion) {
LOG.info().$("upgrading [path=").$(path).$(",fromVersion=").$(currentTableVersion).$(",toVersion=").$(latestVersion).I$();
copyPath.trimTo(plen);
backupFile(ff, path, copyPath, TableUtils.META_FILE_NAME, currentTableVersion);
path.trimTo(plen);
context.of(path, copyPath, fd);
for (int ver = currentTableVersion + 1; ver <= latestVersion; ver++) {
final MigrationAction migration = getMigrationToVersion(ver);
if (migration != null) {
try {
LOG.info().$("upgrading table [path=").$(path).$(",toVersion=").$(ver).I$();
migration.migrate(context);
path.trimTo(plen);
} catch (Throwable e) {
LOG.error().$("failed to upgrade table path=").$(path.trimTo(plen)).$(", exception: ").$(e).$();
throw e;
}
}
TableUtils.writeIntOrFail(ff, fd, META_OFFSET_VERSION, ver, mem, path.trimTo(plen));
}
}
} finally {
ff.close(fd);
path.trimTo(plen);
copyPath.trimTo(plen);
}
}
}
}
});
LOG.info().$("upgraded tables to ").$(latestVersion).$();
}
return updateSuccess.get();
}
use of io.questdb.std.str.NativeLPSZ in project questdb by bluestreak01.
the class TableWriterTest method testRenameColumn.
private void testRenameColumn(TableModel model) throws Exception {
TestUtils.assertMemoryLeak(() -> {
CairoTestUtils.create(model);
long ts = TimestampFormatUtils.parseTimestamp("2013-03-04T00:00:00.000Z");
Rnd rnd = new Rnd();
try (TableWriter writer = new TableWriter(configuration, model.getName())) {
// optional
writer.warmUp();
ts = append10KProducts(ts, rnd, writer);
int columnTypeTag = ColumnType.tagOf(writer.getMetadata().getColumnType("supplier"));
writer.renameColumn("supplier", "sup");
final NativeLPSZ lpsz = new NativeLPSZ();
try (Path path = new Path()) {
path.of(root).concat(model.getName());
final int plen = path.length();
if (columnTypeTag == ColumnType.SYMBOL) {
Assert.assertFalse(FF.exists(path.trimTo(plen).concat(lpsz).concat("supplier.v").$()));
Assert.assertFalse(FF.exists(path.trimTo(plen).concat(lpsz).concat("supplier.o").$()));
Assert.assertFalse(FF.exists(path.trimTo(plen).concat(lpsz).concat("supplier.c").$()));
Assert.assertFalse(FF.exists(path.trimTo(plen).concat(lpsz).concat("supplier.k").$()));
Assert.assertTrue(FF.exists(path.trimTo(plen).concat(lpsz).concat("sup.v").$()));
Assert.assertTrue(FF.exists(path.trimTo(plen).concat(lpsz).concat("sup.o").$()));
Assert.assertTrue(FF.exists(path.trimTo(plen).concat(lpsz).concat("sup.c").$()));
Assert.assertTrue(FF.exists(path.trimTo(plen).concat(lpsz).concat("sup.k").$()));
}
path.trimTo(plen);
FF.iterateDir(path.$(), (file, type) -> {
lpsz.of(file);
if (type == Files.DT_DIR && !Files.isDots(lpsz)) {
Assert.assertFalse(FF.exists(path.trimTo(plen).concat(lpsz).concat("supplier.i").$()));
Assert.assertFalse(FF.exists(path.trimTo(plen).concat(lpsz).concat("supplier.d").$()));
Assert.assertFalse(FF.exists(path.trimTo(plen).concat(lpsz).concat("supplier.top").$()));
Assert.assertTrue(FF.exists(path.trimTo(plen).concat(lpsz).concat("sup.d").$()));
if (columnTypeTag == ColumnType.BINARY || columnTypeTag == ColumnType.STRING) {
Assert.assertTrue(FF.exists(path.trimTo(plen).concat(lpsz).concat("sup.i").$()));
}
}
});
}
ts = append10KWithNewName(ts, rnd, writer);
writer.commit();
Assert.assertEquals(20000, writer.size());
}
try (TableWriter writer = new TableWriter(configuration, model.getName())) {
append10KWithNewName(ts, rnd, writer);
writer.commit();
Assert.assertEquals(30000, writer.size());
}
});
}
use of io.questdb.std.str.NativeLPSZ in project questdb by bluestreak01.
the class LogFactoryTest method testRollOnDate.
private void testRollOnDate(String fileTemplate, long speed, String rollEvery, String mustContain) throws NumericException {
final MicrosecondClock clock = new TestMicrosecondClock(TimestampFormatUtils.parseTimestamp("2015-05-03T10:35:00.000Z"), speed);
long expectedFileCount = Files.getOpenFileCount();
long expectedMemUsage = Unsafe.getMemUsed();
String base = temp.getRoot().getAbsolutePath() + Files.SEPARATOR;
String logFile = base + fileTemplate;
try (LogFactory factory = new LogFactory()) {
factory.add(new LogWriterConfig(LogLevel.LOG_LEVEL_INFO, (ring, seq, level) -> {
LogRollingFileWriter w = new LogRollingFileWriter(FilesFacadeImpl.INSTANCE, clock, ring, seq, level);
w.setLocation(logFile);
// 1Mb log file limit, we will create 4 of them
w.setBufferSize("4k");
w.setRollEvery(rollEvery);
return w;
}));
factory.bind();
factory.startThread();
try {
Log logger = factory.create("x");
for (int i = 0; i < 10000; i++) {
logger.xinfo().$("test ").$(' ').$(i).$();
}
} finally {
factory.haltThread();
}
}
int fileCount = 0;
try (Path path = new Path()) {
NativeLPSZ lpsz = new NativeLPSZ();
path.of(base).$();
long pFind = Files.findFirst(path);
try {
Assert.assertTrue(pFind != 0);
do {
lpsz.of(Files.findName(pFind));
if (Files.isDots(lpsz)) {
continue;
}
// don't hardcode hour, it is liable to vary
// because of different default timezones
TestUtils.assertContains(lpsz, mustContain);
Assert.assertFalse(Chars.contains(lpsz, ".1"));
fileCount++;
} while (Files.findNext(pFind) > 0);
} finally {
Files.findClose(pFind);
}
}
// this is a very weak assertion but we have to live with it
// logger runs asynchronously, it doesn't offer any synchronisation
// support right now, which leaves tests at a mercy of the hardware/OS/other things
// consuming CPU and potentially starving logger of execution time
// when this happens there is no guarantees on how many files it will create
Assert.assertTrue(fileCount > 0);
Assert.assertEquals(expectedFileCount, Files.getOpenFileCount());
Assert.assertEquals(expectedMemUsage, Unsafe.getMemUsed());
}
Aggregations