Search in sources :

Example 1 with CairoConfiguration

use of io.questdb.cairo.CairoConfiguration in project questdb by bluestreak01.

the class TelemetryTest method testTelemetryUpdatesVersion.

@Test
public void testTelemetryUpdatesVersion() throws Exception {
    final AtomicReference<String> refVersion = new AtomicReference<>();
    BuildInformation buildInformation = new BuildInformation() {

        @Override
        public CharSequence getQuestDbVersion() {
            return refVersion.get();
        }

        @Override
        public CharSequence getJdkVersion() {
            return null;
        }

        @Override
        public CharSequence getCommitHash() {
            return null;
        }
    };
    CairoConfiguration configuration = new DefaultCairoConfiguration(root) {

        @Override
        public BuildInformation getBuildInformation() {
            return buildInformation;
        }
    };
    TestUtils.assertMemoryLeak(() -> {
        try (CairoEngine engine = new CairoEngine(configuration);
            SqlCompiler compiler = new SqlCompiler(engine, null);
            SqlExecutionContext sqlExecutionContext = new SqlExecutionContextImpl(engine, 1)) {
            refVersion.set("1.0");
            TelemetryJob telemetryJob = new TelemetryJob(engine, null);
            String os = System.getProperty(TelemetryJob.OS_NAME);
            String expectedSql = "count\n1\n";
            TestUtils.assertSql(compiler, sqlExecutionContext, "SELECT count(*) FROM " + TelemetryJob.configTableName, sink, expectedSql);
            expectedSql = "version\tos\n" + "1.0\t" + os + "\n";
            TestUtils.assertSql(compiler, sqlExecutionContext, "SELECT version, os FROM " + TelemetryJob.configTableName, sink, expectedSql);
            Misc.free(telemetryJob);
            telemetryJob = new TelemetryJob(engine, null);
            expectedSql = "count\n1\n";
            TestUtils.assertSql(compiler, sqlExecutionContext, "SELECT count(*) FROM " + TelemetryJob.configTableName, sink, expectedSql);
            Misc.free(telemetryJob);
            refVersion.set("1.1");
            telemetryJob = new TelemetryJob(engine, null);
            expectedSql = "count\n2\n";
            TestUtils.assertSql(compiler, sqlExecutionContext, "SELECT count(*) FROM " + TelemetryJob.configTableName, sink, expectedSql);
            expectedSql = "version\tos\n" + "1.1\t" + os + "\n";
            TestUtils.assertSql(compiler, sqlExecutionContext, "SELECT version, os FROM " + TelemetryJob.configTableName + " LIMIT -1", sink, expectedSql);
            Misc.free(telemetryJob);
        }
    });
}
Also used : SqlExecutionContextImpl(io.questdb.griffin.SqlExecutionContextImpl) SqlCompiler(io.questdb.griffin.SqlCompiler) SqlExecutionContext(io.questdb.griffin.SqlExecutionContext) AtomicReference(java.util.concurrent.atomic.AtomicReference) DefaultCairoConfiguration(io.questdb.cairo.DefaultCairoConfiguration) CairoEngine(io.questdb.cairo.CairoEngine) DefaultCairoConfiguration(io.questdb.cairo.DefaultCairoConfiguration) CairoConfiguration(io.questdb.cairo.CairoConfiguration) Test(org.junit.Test) AbstractCairoTest(io.questdb.cairo.AbstractCairoTest)

Example 2 with CairoConfiguration

use of io.questdb.cairo.CairoConfiguration in project questdb by bluestreak01.

the class EmbeddedApiTest method testReadWrite.

@Test
public void testReadWrite() throws Exception {
    final CairoConfiguration configuration = new DefaultCairoConfiguration(temp.getRoot().getAbsolutePath());
    TestUtils.assertMemoryLeak(() -> {
        // write part
        try (final CairoEngine engine = new CairoEngine(configuration);
            final SqlExecutionContextImpl ctx = new SqlExecutionContextImpl(engine, 1);
            final SqlCompiler compiler = new SqlCompiler(engine)) {
            compiler.compile("create table abc (a int, b byte, c short, d long, e float, g double, h date, i symbol, j string, k boolean, ts timestamp) timestamp(ts)", ctx);
            try (TableWriter writer = engine.getWriter(ctx.getCairoSecurityContext(), "abc", "testing")) {
                for (int i = 0; i < 10; i++) {
                    TableWriter.Row row = writer.newRow(Os.currentTimeMicros());
                    row.putInt(0, 123);
                    row.putByte(1, (byte) 1111);
                    row.putShort(2, (short) 222);
                    row.putLong(3, 333);
                    row.putFloat(4, 4.44f);
                    row.putDouble(5, 5.55);
                    row.putDate(6, System.currentTimeMillis());
                    row.putSym(7, "xyz");
                    row.putStr(8, "abc");
                    row.putBool(9, true);
                    row.append();
                }
                writer.commit();
            }
            try (RecordCursorFactory factory = compiler.compile("abc", ctx).getRecordCursorFactory()) {
                try (RecordCursor cursor = factory.getCursor(ctx)) {
                    final Record record = cursor.getRecord();
                    // noinspection StatementWithEmptyBody
                    while (cursor.hasNext()) {
                    // access 'record' instance for field values
                    }
                }
            }
        }
    });
}
Also used : SqlExecutionContextImpl(io.questdb.griffin.SqlExecutionContextImpl) SqlCompiler(io.questdb.griffin.SqlCompiler) TableWriter(io.questdb.cairo.TableWriter) RecordCursorFactory(io.questdb.cairo.sql.RecordCursorFactory) RecordCursor(io.questdb.cairo.sql.RecordCursor) DefaultCairoConfiguration(io.questdb.cairo.DefaultCairoConfiguration) Record(io.questdb.cairo.sql.Record) CairoEngine(io.questdb.cairo.CairoEngine) DefaultCairoConfiguration(io.questdb.cairo.DefaultCairoConfiguration) CairoConfiguration(io.questdb.cairo.CairoConfiguration) Test(org.junit.Test)

Example 3 with CairoConfiguration

use of io.questdb.cairo.CairoConfiguration in project questdb by bluestreak01.

the class EmbeddedApiTest method testConcurrentSQLExec.

@Test
public void testConcurrentSQLExec() throws Exception {
    final CairoConfiguration configuration = new DefaultCairoConfiguration(temp.getRoot().getAbsolutePath());
    final Log log = LogFactory.getLog("testConcurrentSQLExec");
    TestUtils.assertMemoryLeak(() -> {
        WorkerPool workerPool = new WorkerPool(new WorkerPoolConfiguration() {

            @Override
            public int[] getWorkerAffinity() {
                return new int[] { -1, -1 };
            }

            @Override
            public int getWorkerCount() {
                return 2;
            }

            @Override
            public boolean haltOnError() {
                return false;
            }
        });
        Rnd rnd = new Rnd();
        try (final CairoEngine engine = new CairoEngine(configuration)) {
            workerPool.assign(new GroupByJob(engine.getMessageBus()));
            workerPool.start(log);
            try {
                // number of cores is current thread + workers in the pool
                final SqlExecutionContextImpl ctx = new SqlExecutionContextImpl(engine, 2);
                try (SqlCompiler compiler = new SqlCompiler(engine)) {
                    compiler.compile("create table abc (g double, ts timestamp) timestamp(ts) partition by DAY", ctx);
                    long timestamp = 0;
                    try (TableWriter writer = engine.getWriter(ctx.getCairoSecurityContext(), "abc", "testing")) {
                        for (int i = 0; i < 10_000_000; i++) {
                            TableWriter.Row row = writer.newRow(timestamp);
                            row.putDouble(0, rnd.nextDouble());
                            row.append();
                            timestamp += 1_000_000;
                        }
                        writer.commit();
                    }
                    try (RecordCursorFactory factory = compiler.compile("select sum(g) from abc", ctx).getRecordCursorFactory()) {
                        try (RecordCursor cursor = factory.getCursor(ctx)) {
                            final Record ignored = cursor.getRecord();
                            // noinspection StatementWithEmptyBody
                            while (cursor.hasNext()) {
                            // access 'record' instance for field values
                            }
                        }
                    }
                }
            } finally {
                workerPool.halt();
            }
        }
    });
}
Also used : SqlCompiler(io.questdb.griffin.SqlCompiler) RecordCursor(io.questdb.cairo.sql.RecordCursor) Log(io.questdb.log.Log) Rnd(io.questdb.std.Rnd) GroupByJob(io.questdb.griffin.engine.groupby.vect.GroupByJob) SqlExecutionContextImpl(io.questdb.griffin.SqlExecutionContextImpl) WorkerPool(io.questdb.mp.WorkerPool) TableWriter(io.questdb.cairo.TableWriter) RecordCursorFactory(io.questdb.cairo.sql.RecordCursorFactory) DefaultCairoConfiguration(io.questdb.cairo.DefaultCairoConfiguration) Record(io.questdb.cairo.sql.Record) CairoEngine(io.questdb.cairo.CairoEngine) DefaultCairoConfiguration(io.questdb.cairo.DefaultCairoConfiguration) CairoConfiguration(io.questdb.cairo.CairoConfiguration) WorkerPoolConfiguration(io.questdb.mp.WorkerPoolConfiguration) Test(org.junit.Test)

Example 4 with CairoConfiguration

use of io.questdb.cairo.CairoConfiguration in project questdb by bluestreak01.

the class LatestByParallelTest method executeWithPool.

protected static void executeWithPool(int workerCount, int queueCapacity, LatestByRunnable runnable) throws Exception {
    executeVanilla(() -> {
        if (workerCount > 0) {
            int[] affinity = new int[workerCount];
            for (int i = 0; i < workerCount; i++) {
                affinity[i] = -1;
            }
            WorkerPool pool = new WorkerPool(new WorkerPoolAwareConfiguration() {

                @Override
                public int[] getWorkerAffinity() {
                    return affinity;
                }

                @Override
                public int getWorkerCount() {
                    return workerCount;
                }

                @Override
                public boolean haltOnError() {
                    return false;
                }

                @Override
                public boolean isEnabled() {
                    return true;
                }
            });
            final CairoConfiguration configuration = new DefaultCairoConfiguration(root) {

                @Override
                public FilesFacade getFilesFacade() {
                    return FilesFacadeImpl.INSTANCE;
                }
            };
            execute(pool, runnable, configuration);
        } else {
            // we need to create entire engine
            final CairoConfiguration configuration = new DefaultCairoConfiguration(root) {

                @Override
                public FilesFacade getFilesFacade() {
                    return FilesFacadeImpl.INSTANCE;
                }

                @Override
                public int getLatestByQueueCapacity() {
                    return queueCapacity;
                }
            };
            execute(null, runnable, configuration);
        }
    });
}
Also used : WorkerPoolAwareConfiguration(io.questdb.WorkerPoolAwareConfiguration) WorkerPool(io.questdb.mp.WorkerPool) DefaultCairoConfiguration(io.questdb.cairo.DefaultCairoConfiguration) DefaultCairoConfiguration(io.questdb.cairo.DefaultCairoConfiguration) CairoConfiguration(io.questdb.cairo.CairoConfiguration)

Example 5 with CairoConfiguration

use of io.questdb.cairo.CairoConfiguration in project invesdwin-context-persistence by subes.

the class QuestDBPerformanceTest method testQuestDbPerformance.

@Test
public void testQuestDbPerformance() throws InterruptedException, SqlException, IOException {
    final File directory = new File(ContextProperties.getCacheDirectory(), QuestDBPerformanceTest.class.getSimpleName());
    Files.deleteNative(directory);
    Files.forceMkdir(directory);
    final CairoConfiguration configuration = new DefaultCairoConfiguration(directory.getAbsolutePath());
    final Instant writesStart = new Instant();
    int i = 0;
    final CairoEngine engine = new CairoEngine(configuration);
    final SqlExecutionContextImpl ctx = new SqlExecutionContextImpl(engine, 1);
    final LoopInterruptedCheck loopCheck = new LoopInterruptedCheck(Duration.ONE_SECOND);
    try (SqlCompiler compiler = new SqlCompiler(engine)) {
        compiler.compile("create table abc (value long, key timestamp) timestamp(key)", ctx);
        try (TableWriter writer = engine.getWriter(ctx.getCairoSecurityContext(), "abc", "insert")) {
            for (final FDate date : newValues()) {
                final TableWriter.Row row = writer.newRow(date.millisValue());
                row.putLong(0, date.millisValue());
                row.append();
                i++;
                if (i % FLUSH_INTERVAL == 0) {
                    if (loopCheck.check()) {
                        printProgress("Writes", writesStart, i, VALUES);
                    }
                    writer.commit();
                }
            }
            writer.commit();
        }
        printProgress("WritesFinished", writesStart, VALUES, VALUES);
    }
    readIterator(engine);
    readGet(engine);
    readGetLatest(engine);
    try (SqlCompiler compiler = new SqlCompiler(engine)) {
        compiler.compile("dtop table 'abc';", ctx);
    }
    engine.close();
    Files.deleteNative(directory);
}
Also used : SqlCompiler(io.questdb.griffin.SqlCompiler) Instant(de.invesdwin.util.time.Instant) LoopInterruptedCheck(de.invesdwin.util.concurrent.loop.LoopInterruptedCheck) FDate(de.invesdwin.util.time.date.FDate) SqlExecutionContextImpl(io.questdb.griffin.SqlExecutionContextImpl) TableWriter(io.questdb.cairo.TableWriter) DefaultCairoConfiguration(io.questdb.cairo.DefaultCairoConfiguration) CairoEngine(io.questdb.cairo.CairoEngine) File(java.io.File) DefaultCairoConfiguration(io.questdb.cairo.DefaultCairoConfiguration) CairoConfiguration(io.questdb.cairo.CairoConfiguration) Test(org.junit.jupiter.api.Test)

Aggregations

CairoConfiguration (io.questdb.cairo.CairoConfiguration)9 DefaultCairoConfiguration (io.questdb.cairo.DefaultCairoConfiguration)8 CairoEngine (io.questdb.cairo.CairoEngine)7 SqlCompiler (io.questdb.griffin.SqlCompiler)5 SqlExecutionContextImpl (io.questdb.griffin.SqlExecutionContextImpl)5 Test (org.junit.Test)4 TableWriter (io.questdb.cairo.TableWriter)3 SqlExecutionContext (io.questdb.griffin.SqlExecutionContext)3 WorkerPool (io.questdb.mp.WorkerPool)3 AbstractCairoTest (io.questdb.cairo.AbstractCairoTest)2 Record (io.questdb.cairo.sql.Record)2 RecordCursor (io.questdb.cairo.sql.RecordCursor)2 RecordCursorFactory (io.questdb.cairo.sql.RecordCursorFactory)2 SqlException (io.questdb.griffin.SqlException)2 WorkerPoolConfiguration (io.questdb.mp.WorkerPoolConfiguration)2 LoopInterruptedCheck (de.invesdwin.util.concurrent.loop.LoopInterruptedCheck)1 Instant (de.invesdwin.util.time.Instant)1 FDate (de.invesdwin.util.time.date.FDate)1 TelemetryJob (io.questdb.TelemetryJob)1 WorkerPoolAwareConfiguration (io.questdb.WorkerPoolAwareConfiguration)1