Search in sources :

Example 1 with MicrosecondClock

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();
}
Also used : MicrosecondClock(io.questdb.std.datetime.microtime.MicrosecondClock) TableWriter(io.questdb.cairo.TableWriter) NanosecondClock(io.questdb.std.NanosecondClock)

Example 2 with MicrosecondClock

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);
        }
    }
}
Also used : MicrosecondClock(io.questdb.std.datetime.microtime.MicrosecondClock) Sequence(io.questdb.mp.Sequence)

Example 3 with MicrosecondClock

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");
}
Also used : Path(io.questdb.std.str.Path) RingQueue(io.questdb.mp.RingQueue) SPSequence(io.questdb.mp.SPSequence) SOCountDownLatch(io.questdb.mp.SOCountDownLatch) MicrosecondClock(io.questdb.std.datetime.microtime.MicrosecondClock) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SCSequence(io.questdb.mp.SCSequence) Test(org.junit.Test)

Example 4 with MicrosecondClock

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);
}
Also used : SOCountDownLatch(io.questdb.mp.SOCountDownLatch) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test) File(java.io.File) RingQueue(io.questdb.mp.RingQueue) LockSupport(java.util.concurrent.locks.LockSupport) MicrosecondClock(io.questdb.std.datetime.microtime.MicrosecondClock) Rule(org.junit.Rule) SCSequence(io.questdb.mp.SCSequence) Path(io.questdb.std.str.Path) TestUtils(io.questdb.test.tools.TestUtils) NativeLPSZ(io.questdb.std.str.NativeLPSZ) TimestampFormatUtils(io.questdb.std.datetime.microtime.TimestampFormatUtils) Assert(org.junit.Assert) io.questdb.std(io.questdb.std) TemporaryFolder(org.junit.rules.TemporaryFolder) SPSequence(io.questdb.mp.SPSequence) MicrosecondClock(io.questdb.std.datetime.microtime.MicrosecondClock) File(java.io.File) Test(org.junit.Test)

Example 5 with MicrosecondClock

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());
}
Also used : SOCountDownLatch(io.questdb.mp.SOCountDownLatch) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test) File(java.io.File) RingQueue(io.questdb.mp.RingQueue) LockSupport(java.util.concurrent.locks.LockSupport) MicrosecondClock(io.questdb.std.datetime.microtime.MicrosecondClock) Rule(org.junit.Rule) SCSequence(io.questdb.mp.SCSequence) Path(io.questdb.std.str.Path) TestUtils(io.questdb.test.tools.TestUtils) NativeLPSZ(io.questdb.std.str.NativeLPSZ) TimestampFormatUtils(io.questdb.std.datetime.microtime.TimestampFormatUtils) Assert(org.junit.Assert) io.questdb.std(io.questdb.std) TemporaryFolder(org.junit.rules.TemporaryFolder) SPSequence(io.questdb.mp.SPSequence) Path(io.questdb.std.str.Path) MicrosecondClock(io.questdb.std.datetime.microtime.MicrosecondClock) NativeLPSZ(io.questdb.std.str.NativeLPSZ)

Aggregations

MicrosecondClock (io.questdb.std.datetime.microtime.MicrosecondClock)6 RingQueue (io.questdb.mp.RingQueue)4 SCSequence (io.questdb.mp.SCSequence)4 SOCountDownLatch (io.questdb.mp.SOCountDownLatch)4 SPSequence (io.questdb.mp.SPSequence)4 Path (io.questdb.std.str.Path)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 Test (org.junit.Test)4 io.questdb.std (io.questdb.std)3 TimestampFormatUtils (io.questdb.std.datetime.microtime.TimestampFormatUtils)3 NativeLPSZ (io.questdb.std.str.NativeLPSZ)3 TestUtils (io.questdb.test.tools.TestUtils)3 File (java.io.File)3 LockSupport (java.util.concurrent.locks.LockSupport)3 Assert (org.junit.Assert)3 Rule (org.junit.Rule)3 TemporaryFolder (org.junit.rules.TemporaryFolder)3 TableWriter (io.questdb.cairo.TableWriter)1 Sequence (io.questdb.mp.Sequence)1 NanosecondClock (io.questdb.std.NanosecondClock)1