use of com.questdb.std.ex.JournalException in project questdb by bluestreak01.
the class ReconnectTest method testServerRestart.
@Test
@Ignore
public void testServerRestart() throws Exception {
final int size = 10000;
try (JournalWriter<Quote> remote = getFactory().writer(Quote.class, "remote", 2 * size)) {
// start server #1
JournalServer server = newServer();
server.publish(remote);
server.start();
final CountDownLatch connectedLatch = new CountDownLatch(1);
JournalClient client = new JournalClient(new ClientConfig("localhost") {
{
getReconnectPolicy().setLoginRetryCount(3);
getReconnectPolicy().setRetryCount(5);
getReconnectPolicy().setSleepBetweenRetriesMillis(TimeUnit.SECONDS.toMillis(1));
}
}, getFactory(), null, evt -> {
if (evt == JournalClientEvents.EVT_CONNECTED) {
connectedLatch.countDown();
}
});
// subscribe client, waiting for complete set of data
// when data arrives client triggers latch
final CountDownLatch latch = new CountDownLatch(1);
// create empty "local"
getFactory().writer(Quote.class, "local").close();
try (final Journal<Quote> local = getFactory().reader(Quote.class, "local")) {
client.subscribe(Quote.class, "remote", "local", 2 * size, new JournalListener() {
@Override
public void onCommit() {
try {
if (local.refresh() && local.size() == 2 * size) {
latch.countDown();
}
} catch (JournalException e) {
throw new JournalRuntimeException(e);
}
}
@Override
public void onEvent(int event) {
}
});
client.start();
Assert.assertTrue(connectedLatch.await(5, TimeUnit.SECONDS));
// generate first batch
TestUtils.generateQuoteData(remote, size, System.currentTimeMillis(), 1);
remote.commit();
// stop server
server.halt();
// start server #2
server = newServer();
server.publish(remote);
server.start();
// generate second batch
TestUtils.generateQuoteData(remote, size, System.currentTimeMillis() + 2 * size, 1);
remote.commit();
// wait for client to get full set
latch.await();
// stop client and server
client.halt();
server.halt();
// assert client state
TestUtils.assertDataEquals(remote, local);
}
}
}
use of com.questdb.std.ex.JournalException in project questdb by bluestreak01.
the class ScenarioTest method testLagTrickle.
@Test
public void testLagTrickle() throws Exception {
// prepare test data
try (JournalWriter<Quote> origin = getFactory().writer(Quote.class, "origin")) {
TestData.appendQuoteData2(origin);
try (final JournalWriter<Quote> randomOrigin = getFactory().writer(new JournalKey<>(Quote.class, "origin-rnd", PartitionBy.NONE, Constants.NULL_RECORD_HINT, false))) {
randomOrigin.append(origin.query().all().asResultSet().shuffle(new Rnd()));
try (final JournalWriter<Quote> remote = getFactory().writer(Quote.class, "remote")) {
try (final Journal<Quote> remoteReader = getFactory().reader(Quote.class, "remote")) {
// create empty journal
getFactory().writer(Quote.class, "local").close();
// setup local where data should be trickling from client
try (final Journal<Quote> local = getFactory().reader(Quote.class, "local")) {
Assert.assertEquals(0, local.size());
JournalServer server = new JournalServer(serverConfig, getFactory());
JournalClient client = new JournalClient(clientConfig, getFactory());
server.publish(remote);
server.start();
final AtomicInteger errors = new AtomicInteger();
final CountDownLatch ready = new CountDownLatch(1);
client.subscribe(Quote.class, "remote", "local", new JournalListener() {
@Override
public void onCommit() {
try {
if (local.refresh() && local.size() == 33) {
ready.countDown();
}
} catch (JournalException e) {
errors.incrementAndGet();
e.printStackTrace();
}
}
@Override
public void onEvent(int event) {
if (event != JournalEvents.EVT_JNL_SUBSCRIBED) {
errors.incrementAndGet();
}
}
});
client.start();
int n = 0;
while (n < 400) {
lagIteration(randomOrigin, remote, n, n + 10);
n += 10;
}
Assert.assertTrue(ready.await(10, TimeUnit.SECONDS));
server.halt();
client.halt();
local.refresh();
remoteReader.refresh();
TestUtils.assertEquals(remoteReader, local);
Assert.assertEquals(0, errors.get());
}
}
}
}
}
}
use of com.questdb.std.ex.JournalException in project questdb by bluestreak01.
the class AbstractQueryContext method executeQuery.
private RecordSource executeQuery(ChunkedResponse r, Factory factory) throws ParserException, DisconnectedChannelException, SlowWritableChannelException {
QueryCompiler compiler = COMPILER.get();
ParsedModel model = compiler.parse(query);
switch(model.getModelType()) {
case ParsedModel.QUERY:
return compiler.compile(factory, model);
default:
try {
compiler.execute(factory, model);
} catch (JournalException e) {
error().$("Server error executing statement ").$(query).$(e).$();
sendException(r, 0, e.getMessage(), 500);
}
return null;
}
}
use of com.questdb.std.ex.JournalException in project questdb by bluestreak01.
the class PlainTextStoringParser method onMetadata.
@Override
public void onMetadata(ObjList<ImportedColumnMetadata> metadata, boolean header) {
if (writer == null) {
this.metadata = metadata;
this.header = header;
try {
switch(factory.getConfiguration().exists(name)) {
case DOES_NOT_EXIST:
writer = factory.writer(createStructure());
break;
case EXISTS:
if (overwrite) {
factory.delete(name);
writer = factory.writer(createStructure());
} else {
writer = mapColumnsAndOpenWriter();
}
break;
default:
throw ImportNameException.INSTANCE;
}
writer.setSequentialAccess(true);
_size = writer.size();
errors.seed(writer.getMetadata().getColumnCount(), 0);
} catch (JournalException e) {
throw new JournalRuntimeException(e);
}
}
}
use of com.questdb.std.ex.JournalException in project questdb by bluestreak01.
the class PlainTextStoringParser method onFields.
@Override
public void onFields(int line, ObjList<DirectByteCharSequence> values, int hi) {
boolean append = true;
try {
JournalEntryWriter w = writer.entryWriter();
for (int i = 0; i < hi; i++) {
if (values.getQuick(i).length() == 0) {
continue;
}
try {
DirectByteCharSequence charField;
ImportedColumnMetadata m = metadata.getQuick(i);
switch(m.importedColumnType) {
case ColumnType.STRING:
utf8Sink.clear();
charField = values.getQuick(i);
Chars.utf8Decode(charField.getLo(), charField.getHi(), utf8Sink);
w.putStr(i, (DirectBytes) utf8Sink);
break;
case ColumnType.DOUBLE:
w.putDouble(i, Numbers.parseDouble(values.getQuick(i)));
break;
case ColumnType.INT:
w.putInt(i, Numbers.parseInt(values.getQuick(i)));
break;
case ColumnType.FLOAT:
w.putFloat(i, Numbers.parseFloat(values.getQuick(i)));
break;
case ColumnType.DATE:
if (m.dateFormat != null && m.dateLocale != null) {
w.putDate(i, m.dateFormat.parse(values.getQuick(i), m.dateLocale));
} else {
throw NumericException.INSTANCE;
}
break;
case ColumnType.SYMBOL:
utf8Sink.clear();
charField = values.getQuick(i);
Chars.utf8Decode(charField.getLo(), charField.getHi(), utf8Sink);
w.putSym(i, utf8Sink);
break;
case ColumnType.LONG:
w.putLong(i, Numbers.parseLong(values.getQuick(i)));
break;
case ColumnType.BOOLEAN:
w.putBool(i, Chars.equalsIgnoreCase(values.getQuick(i), "true"));
break;
default:
break;
}
} catch (Exception e) {
switch(atomicity) {
case ATOMICITY_STRICT:
LOG.info().$("Error at (").$(line).$(',').$(i).$(')').$();
throw new JournalRuntimeException("Error on line: " + line + ", col: " + i);
default:
errors.increment(i);
LOG.debug().$("Error at (").$(line).$(',').$(i).$(") as ").$(metadata.getQuick(i).importedColumnType).$(": ").$(e.getMessage()).$();
append = false;
}
break;
}
}
if (append) {
w.append();
}
} catch (JournalException e) {
throw new JournalRuntimeException(e);
}
}
Aggregations