use of herddb.proto.Pdu in project herddb by diennea.
the class RoutedClientSideConnection method dumpTableSpace.
@Override
public void dumpTableSpace(String tableSpace, int fetchSize, boolean includeTransactionLog, TableSpaceDumpReceiver receiver) throws HDBException, ClientSideMetadataProviderException {
Channel channel = ensureOpen();
try {
String dumpId = this.clientId + ":" + scannerIdGenerator.incrementAndGet();
long requestId = channel.generateRequestId();
ByteBuf message = PduCodec.RequestTablespaceDump.write(requestId, tableSpace, dumpId, fetchSize, includeTransactionLog);
LOGGER.log(Level.SEVERE, "dumpTableSpace id {0} for tablespace {1}", new Object[] { dumpId, tableSpace });
dumpReceivers.put(dumpId, receiver);
try (Pdu reply = channel.sendMessageWithPduReply(requestId, message, timeout)) {
LOGGER.log(Level.SEVERE, "dumpTableSpace id {0} for tablespace {1}: first reply {2}", new Object[] { dumpId, tableSpace, reply });
if (reply.type == Pdu.TYPE_ERROR) {
handleGenericError(reply, 0);
} else if (reply.type != Pdu.TYPE_ACK) {
throw new HDBException(reply);
}
}
} catch (InterruptedException err) {
Thread.currentThread().interrupt();
throw new HDBException(err);
} catch (TimeoutException err) {
throw new HDBException(err);
}
}
use of herddb.proto.Pdu in project herddb by diennea.
the class RoutedClientSideConnection method executeScan.
@Override
public ScanResultSet executeScan(String tableSpace, String query, boolean usePreparedStatement, List<Object> params, long tx, int maxRows, int fetchSize, boolean keepReadLocks) throws HDBException, ClientSideMetadataProviderException {
Channel channel = ensureOpen();
Pdu reply = null;
try {
long scannerId = scannerIdGenerator.incrementAndGet();
long requestId = channel.generateRequestId();
long statementId = usePreparedStatement ? prepareQuery(tableSpace, query) : 0;
query = statementId > 0 ? "" : query;
ByteBuf message = PduCodec.OpenScanner.write(requestId, tableSpace, query, scannerId, tx, params, statementId, fetchSize, maxRows, keepReadLocks);
LOGGER.log(Level.FINEST, "open scanner {0} for query {1}, params {2}", new Object[] { scannerId, query, params });
reply = channel.sendMessageWithPduReply(requestId, message, timeout);
if (reply.type == Pdu.TYPE_ERROR) {
handleGenericError(reply, statementId, true);
// not possible
return null;
} else if (reply.type != Pdu.TYPE_RESULTSET_CHUNK) {
HDBException err = new HDBException(reply);
reply.close();
throw err;
}
boolean last = PduCodec.ResultSetChunk.readIsLast(reply);
long transactionId = PduCodec.ResultSetChunk.readTx(reply);
RecordsBatch data = PduCodec.ResultSetChunk.startReadingData(reply);
// LOGGER.log(Level.SEVERE, "received first " + initialFetchBuffer.size() + " records for query " + query);
ScanResultSetImpl impl = new ScanResultSetImpl(scannerId, data, fetchSize, last, transactionId, channel);
return impl;
} catch (InterruptedException err) {
if (reply != null) {
reply.close();
}
Thread.currentThread().interrupt();
throw new HDBException(err);
} catch (TimeoutException err) {
if (reply != null) {
reply.close();
}
throw new HDBException(err);
}
}
Aggregations