use of io.questdb.std.datetime.microtime.MicrosecondClock in project questdb by bluestreak01.
the class TelemetryJob method appendConfigRow.
private void appendConfigRow(SqlCompiler compiler, TableWriter configWriter, Long256 id, boolean enabled) {
TableWriter.Row row = configWriter.newRow();
if (null == id) {
final MicrosecondClock clock = compiler.getEngine().getConfiguration().getMicrosecondClock();
final NanosecondClock nanosecondClock = compiler.getEngine().getConfiguration().getNanosecondClock();
final long a = nanosecondClock.getTicks();
final long b = clock.getTicks();
row.putLong256(0, a, b, 0, 0);
LOG.info().$("new instance [id=").$256(a, b, 0, 0).$(", enabled=").$(enabled).$(']').$();
} else {
row.putLong256(0, id);
}
row.putBool(1, enabled);
row.putSym(2, configuration.getBuildInformation().getQuestDbVersion());
row.putSym(3, System.getProperty(OS_NAME));
String packageStr = System.getenv().get(QDB_PACKAGE);
if (null != packageStr) {
row.putSym(4, packageStr);
}
row.append();
configWriter.commit();
}
use of io.questdb.std.datetime.microtime.MicrosecondClock in project questdb by bluestreak01.
the class TelemetryTask method doStoreTelemetry.
public static void doStoreTelemetry(CairoEngine engine, short event, short origin) {
Sequence telemetryPubSeq = engine.getTelemetryPubSequence();
if (null != telemetryPubSeq) {
MicrosecondClock clock = engine.getConfiguration().getMicrosecondClock();
RingQueue<TelemetryTask> telemetryQueue = engine.getTelemetryQueue();
long cursor = telemetryPubSeq.next();
while (cursor == -2) {
cursor = telemetryPubSeq.next();
}
if (cursor > -1) {
TelemetryTask row = telemetryQueue.get(cursor);
row.created = clock.getTicks();
row.event = event;
row.origin = origin;
telemetryPubSeq.done(cursor);
}
}
}
use of io.questdb.std.datetime.microtime.MicrosecondClock in project questdb by bluestreak01.
the class LogFactoryTest method testRollingFileWriterBySize.
@Test
public void testRollingFileWriterBySize() throws Exception {
String base = temp.getRoot().getAbsolutePath() + Files.SEPARATOR;
String logFile = base + "mylog-${date:yyyy-MM-dd}.log";
String expectedLogFile = base + "mylog-2015-05-03.log";
final MicrosecondClock clock = new TestMicrosecondClock(TimestampFormatUtils.parseTimestamp("2015-05-03T10:35:00.000Z"), 1);
try (Path path = new Path()) {
// create rogue file that would be in a way of logger rolling existing files
path.of(base);
Assert.assertTrue(Files.touch(path.concat("mylog-2015-05-03.log.2").$()));
}
RingQueue<LogRecordSink> queue = new RingQueue<>(LogRecordSink::new, 1024, 1024, MemoryTag.NATIVE_DEFAULT);
SPSequence pubSeq = new SPSequence(queue.getCycle());
SCSequence subSeq = new SCSequence();
pubSeq.then(subSeq).then(pubSeq);
try (final LogRollingFileWriter writer = new LogRollingFileWriter(FilesFacadeImpl.INSTANCE, clock, queue, subSeq, LogLevel.LOG_LEVEL_INFO)) {
writer.setLocation(logFile);
writer.setRollSize("1m");
writer.setBufferSize("64k");
writer.bindProperties();
AtomicBoolean running = new AtomicBoolean(true);
SOCountDownLatch halted = new SOCountDownLatch();
halted.setCount(1);
new Thread(() -> {
while (running.get()) {
writer.runSerially();
}
// noinspection StatementWithEmptyBody
while (writer.runSerially()) ;
halted.countDown();
}).start();
// now publish
int published = 0;
int toPublish = 100_000;
while (published < toPublish) {
long cursor = pubSeq.next();
if (cursor < 0) {
LockSupport.parkNanos(1);
continue;
}
final long available = pubSeq.available();
while (cursor < available && published < toPublish) {
LogRecordSink sink = queue.get(cursor++);
sink.setLevel(LogLevel.LOG_LEVEL_INFO);
sink.put("test");
published++;
}
pubSeq.done(cursor - 1);
}
running.set(false);
halted.await();
}
assertFileLength(expectedLogFile);
assertFileLength(expectedLogFile + ".1");
}
use of io.questdb.std.datetime.microtime.MicrosecondClock in project questdb by bluestreak01.
the class LogFactoryTest method testRollingFileWriterDateParse.
@Test
public void testRollingFileWriterDateParse() throws Exception {
String base = temp.getRoot().getAbsolutePath() + Files.SEPARATOR;
String logFile = base + "mylog-${date:yyyy-MM-dd}.log";
String expectedLogFile = base + "mylog-2015-05-03.log";
try (LogFactory factory = new LogFactory()) {
final MicrosecondClock clock = new TestMicrosecondClock(TimestampFormatUtils.parseTimestamp("2015-05-03T11:35:00.000Z"), 1);
factory.add(new LogWriterConfig(LogLevel.LOG_LEVEL_INFO, (ring, seq, level) -> {
LogRollingFileWriter w = new LogRollingFileWriter(FilesFacadeImpl.INSTANCE, clock, ring, seq, level);
w.setLocation(logFile);
return w;
}));
factory.bind();
factory.startThread();
try {
Log logger = factory.create("x");
for (int i = 0; i < 100000; i++) {
logger.xinfo().$("test ").$(' ').$(i).$();
}
Os.sleep(100);
} finally {
factory.haltThread();
}
}
Assert.assertTrue(new File(expectedLogFile).length() > 0);
}
use of io.questdb.std.datetime.microtime.MicrosecondClock 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