use of com.questdb.store.factory.configuration.JournalConfiguration 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.");
}
}
}
use of com.questdb.store.factory.configuration.JournalConfiguration in project questdb by bluestreak01.
the class AppendObjectConcurrent method main.
/**
* Multiple threads append to same journal concurrently.
* <p>
* Single append thread receives data from multiple publishers via circular queue using QuestDB's thread messaging mechanism.
* Please refer to my blog post: http://blog.questdb.org/2016/08/the-art-of-thread-messaging.html for more details.
*/
public static void main(String[] args) throws JournalException, InterruptedException {
if (args.length != 1) {
System.out.println("Usage: " + AppendObjectConcurrent.class.getName() + " <path>");
System.exit(1);
}
//
RingQueue<Quote> queue = new RingQueue<>(Quote::new, 4096);
// publisher sequence
final MPSequence pubSequence = new MPSequence(queue.getCapacity());
final SCSequence subSequence = new SCSequence();
// create circular dependency between sequences
pubSequence.then(subSequence).then(pubSequence);
// run configuration
int nThreads = 2;
int nMessages = 1000000;
JournalConfiguration configuration = ModelConfiguration.CONFIG.build(args[0]);
try (Factory factory = new Factory(configuration, 1000, 1, 0)) {
// start publishing threads
for (int i = 0; i < nThreads; i++) {
new Thread(new Publisher(queue, pubSequence, nMessages)).start();
}
// consume messages in main thread
int count = 0;
int deadline = nMessages * nThreads;
try (JournalWriter<Quote> writer = factory.writer(Quote.class)) {
while (count < deadline) {
long cursor = subSequence.next();
if (cursor < 0) {
LockSupport.parkNanos(1);
continue;
}
long available = subSequence.available();
while (cursor < available) {
Quote q = queue.get(cursor++);
q.setTimestamp(System.currentTimeMillis());
try {
writer.append(q);
} catch (JournalException e) {
// append may fail, log and continue
// N.B. this logging uses builder pattern to construct message. Building finishes with $() call.
LOG.error().$("Sequence failed: ").$(cursor - 1).$(e).$();
}
count++;
}
subSequence.done(available - 1);
try {
writer.commit();
} catch (JournalException e) {
// something serious, attempt to rollback
LOG.error().$("Batch commit() failed [").$(available - 1).$(']').$(e).$();
}
}
}
LOG.info().$("Writer done").$();
}
}
use of com.questdb.store.factory.configuration.JournalConfiguration 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);
}
}
}
use of com.questdb.store.factory.configuration.JournalConfiguration 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");
}
use of com.questdb.store.factory.configuration.JournalConfiguration 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));
}
Aggregations