Search in sources :

Example 1 with JournalConfigurationBuilder

use of com.questdb.store.factory.configuration.JournalConfigurationBuilder in project questdb by bluestreak01.

the class AppendObjectBlobs method main.

public static void main(String[] args) throws JournalException, IOException {
    final String dirToIndex = args[1];
    JournalConfiguration configuration = new JournalConfigurationBuilder().build(args[0]);
    try (Factory factory = new Factory(configuration, 1000, 1, 0)) {
        try (JournalWriter writer = factory.writer(new JournalStructure("files") {

            {
                $sym("name").index();
                $bin("data");
                $ts();
            }
        })) {
            long t = System.currentTimeMillis();
            int count = processDir(writer, new File(dirToIndex));
            System.out.println("Added " + count + " files in " + (System.currentTimeMillis() - t) + " ms.");
        }
    }
}
Also used : JournalConfiguration(com.questdb.store.factory.configuration.JournalConfiguration) JournalWriter(com.questdb.store.JournalWriter) JournalStructure(com.questdb.store.factory.configuration.JournalStructure) Factory(com.questdb.store.factory.Factory) JournalConfigurationBuilder(com.questdb.store.factory.configuration.JournalConfigurationBuilder)

Example 2 with JournalConfigurationBuilder

use of com.questdb.store.factory.configuration.JournalConfigurationBuilder in project questdb by bluestreak01.

the class AppendObjectSortMerge method main.

/**
 * For cases where incoming data feed is not in chronological order but you would like your journal to be in chronological order.
 * This is a lossy way to append data as journal would only be merging a slice of data as specified by "lag" attribute.
 */
public static void main(String[] args) throws JournalException {
    if (args.length != 1) {
        System.out.println("Usage: " + AppendObjectSortMerge.class.getName() + " <path>");
        System.exit(1);
    }
    String journalLocation = args[0];
    try (Factory writerFactory = new Factory(new JournalConfigurationBuilder() {

        {
            $(Quote.class, "quote-lag").lag(24, // enable lag
            TimeUnit.HOURS).$ts();
        }
    }.build(journalLocation), 1000, 1, 0)) {
        // delete existing quote journal
        Files.delete(new File(writerFactory.getConfiguration().getJournalBase(), "quote-lag"));
        try (JournalWriter<Quote> writer = writerFactory.writer(Quote.class)) {
            final String[] symbols = { "AGK.L", "BP.L", "TLW.L", "ABF.L", "LLOY.L", "BT-A.L", "WTB.L", "RRS.L", "ADM.L", "GKN.L", "HSBA.L" };
            final Random r = new Random(System.currentTimeMillis());
            // 20 batches of 50,000 quotes, total 1,000,000
            final int batchCount = 20;
            final int batchSize = 50000;
            final ArrayList<Quote> batch = new ArrayList<>(batchSize);
            // have pre-initialized array to reduce GC overhead
            for (int i = 0; i < batchSize; i++) {
                batch.add(new Quote());
            }
            long utc = System.currentTimeMillis();
            long t = System.nanoTime();
            for (int i = 0; i < batchCount; i++) {
                // populate batch in-memory
                for (int k = 0; k < batchSize; k++) {
                    Quote q = batch.get(k);
                    q.clear();
                    // generate some data
                    q.setSym(symbols[Math.abs(r.nextInt() % (symbols.length - 1))]);
                    q.setAsk(Math.abs(r.nextDouble()));
                    q.setBid(Math.abs(r.nextDouble()));
                    q.setAskSize(Math.abs(r.nextInt() % 10000));
                    q.setBidSize(Math.abs(r.nextInt() % 10000));
                    q.setEx("LXE");
                    q.setMode("Fast trading");
                    long timestamp = utc + (i * batchSize + (batchSize - k)) * 1000L;
                    // make batches overlap (subtract 10 seconds)
                    timestamp -= 100000000L;
                    q.setTimestamp(timestamp);
                }
                // batch must be sorted before being presented to writer
                batch.sort(writer.getTimestampComparator());
                // append batch and have journal merge data
                writer.mergeAppend(batch);
            }
            // commit is necessary
            writer.commit();
            System.out.println("Journal size: " + writer.size());
            System.out.println("Generated " + batchCount * batchSize + " objects in " + TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - t) + "ms.");
        }
    }
}
Also used : ArrayList(java.util.ArrayList) Factory(com.questdb.store.factory.Factory) JournalConfigurationBuilder(com.questdb.store.factory.configuration.JournalConfigurationBuilder) Quote(org.questdb.examples.support.Quote) Random(java.util.Random) File(java.io.File)

Example 3 with JournalConfigurationBuilder

use of com.questdb.store.factory.configuration.JournalConfigurationBuilder in project questdb by bluestreak01.

the class SQLParameters method main.

public static void main(String[] args) throws JournalException, ParserException, IOException {
    if (args.length < 1) {
        System.out.println("Usage: SQLParameters <path>");
        System.exit(1);
    }
    JournalConfiguration configuration = new JournalConfigurationBuilder().build(args[0]);
    try (Factory factory = new Factory(configuration, 1000, 1, 0)) {
        // import movies data to query
        ImportManager.importFile(factory, SQLParameters.class.getResource("/movies.csv").getFile(), ',', null, false);
        // Create SQL engine instance.
        QueryCompiler compiler = new QueryCompiler();
        try (RecordSource rs = compiler.compile(factory, "'movies.csv' where movieId = :id")) {
            RecordSourcePrinter printer = new RecordSourcePrinter(new StdoutSink());
            // use of parameters avoids expensive query compilation
            rs.getParam(":id").set(62198);
            printer.print(rs, factory);
            System.out.println("----------------");
            rs.getParam(":id").set(125);
            printer.print(rs, factory);
        }
    }
}
Also used : JournalConfiguration(com.questdb.store.factory.configuration.JournalConfiguration) RecordSource(com.questdb.ql.RecordSource) StdoutSink(com.questdb.std.str.StdoutSink) RecordSourcePrinter(com.questdb.ql.RecordSourcePrinter) Factory(com.questdb.store.factory.Factory) JournalConfigurationBuilder(com.questdb.store.factory.configuration.JournalConfigurationBuilder) QueryCompiler(com.questdb.parser.sql.QueryCompiler)

Example 4 with JournalConfigurationBuilder

use of com.questdb.store.factory.configuration.JournalConfigurationBuilder in project questdb by bluestreak01.

the class AuthReplicationClientMain method main.

public static void main(String[] args) throws Exception {
    JournalConfiguration configuration = new JournalConfigurationBuilder().build(args[0]);
    Factory factory = new Factory(configuration);
    final JournalClient client = new JournalClient(factory, () -> "MY SECRET".getBytes("UTF8"));
    final Journal<Price> reader = factory.reader(Price.class, "price-copy");
    reader.setSequentialAccess(true);
    client.subscribe(Price.class, null, "price-copy", new JournalListener() {

        @Override
        public void onCommit() {
            int count = 0;
            long t = 0;
            for (Price p : JournalIterators.incrementBufferedIterator(reader)) {
                if (count == 0) {
                    t = p.getNanos();
                }
                count++;
            }
            System.out.println("took: " + (System.nanoTime() - t) + ", count=" + count);
        }

        @Override
        public void onEvent(int event) {
            System.out.println("There was an error");
        }
    });
    client.start();
    System.out.println("Client started");
}
Also used : JournalClient(com.questdb.net.ha.JournalClient) JournalConfiguration(com.questdb.store.factory.configuration.JournalConfiguration) Price(org.questdb.examples.support.Price) JournalListener(com.questdb.store.JournalListener) Factory(com.questdb.store.factory.Factory) JournalConfigurationBuilder(com.questdb.store.factory.configuration.JournalConfigurationBuilder)

Example 5 with JournalConfigurationBuilder

use of com.questdb.store.factory.configuration.JournalConfigurationBuilder in project questdb by bluestreak01.

the class ClusteredProducerMain method main.

public static void main(String[] args) throws JournalException, IOException, JournalNetworkException, NumericException {
    final String pathToDatabase = args[0];
    final int instance = Numbers.parseInt(args[1]);
    final JournalConfiguration configuration = new JournalConfigurationBuilder() {

        {
            $(Price.class).$ts();
        }
    }.build(pathToDatabase);
    final Factory factory = new Factory(configuration, 1000, 1, 0);
    final JournalWriter<Price> writer = factory.writer(new JournalKey<>(Price.class, null, PartitionBy.DEFAULT, 1000000000));
    final WorkerController wc = new WorkerController(writer);
    final ClusterController cc = new ClusterController(new ServerConfig() {

        {
            addNode(new ServerNode(1, "127.0.0.1:7080"));
            addNode(new ServerNode(2, "127.0.0.1:7090"));
        }
    }, new ClientConfig(), factory, instance, new ArrayList<JournalWriter>() {

        {
            add(writer);
        }
    }, wc);
    cc.start();
    Runtime.getRuntime().addShutdownHook(new Thread(cc::halt));
}
Also used : JournalWriter(com.questdb.store.JournalWriter) Factory(com.questdb.store.factory.Factory) JournalConfigurationBuilder(com.questdb.store.factory.configuration.JournalConfigurationBuilder) ServerConfig(com.questdb.net.ha.config.ServerConfig) JournalConfiguration(com.questdb.store.factory.configuration.JournalConfiguration) ClusterController(com.questdb.net.ha.ClusterController) Price(org.questdb.examples.support.Price) ServerNode(com.questdb.net.ha.config.ServerNode) ClientConfig(com.questdb.net.ha.config.ClientConfig)

Aggregations

JournalConfigurationBuilder (com.questdb.store.factory.configuration.JournalConfigurationBuilder)16 Factory (com.questdb.store.factory.Factory)13 JournalConfiguration (com.questdb.store.factory.configuration.JournalConfiguration)10 Price (org.questdb.examples.support.Price)7 ClientConfig (com.questdb.net.ha.config.ClientConfig)6 Quote (com.questdb.model.Quote)4 JournalClient (com.questdb.net.ha.JournalClient)4 JournalListener (com.questdb.store.JournalListener)4 AbstractTest (com.questdb.test.tools.AbstractTest)4 Test (org.junit.Test)4 File (java.io.File)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 Quote (org.questdb.examples.support.Quote)3 JournalServer (com.questdb.net.ha.JournalServer)2 JournalWriter (com.questdb.store.JournalWriter)2 Random (java.util.Random)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 ClusterController (com.questdb.net.ha.ClusterController)1 ServerConfig (com.questdb.net.ha.config.ServerConfig)1 ServerNode (com.questdb.net.ha.config.ServerNode)1