Search in sources :

Example 26 with Pdu

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);
    }
}
Also used : Pdu(herddb.proto.Pdu) Channel(herddb.network.Channel) RawString(herddb.utils.RawString) ByteBuf(io.netty.buffer.ByteBuf) HDBOperationTimeoutException(herddb.client.impl.HDBOperationTimeoutException) TimeoutException(java.util.concurrent.TimeoutException)

Example 27 with Pdu

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);
    }
}
Also used : Pdu(herddb.proto.Pdu) Channel(herddb.network.Channel) ByteBuf(io.netty.buffer.ByteBuf) RecordsBatch(herddb.utils.RecordsBatch) HDBOperationTimeoutException(herddb.client.impl.HDBOperationTimeoutException) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

Pdu (herddb.proto.Pdu)27 Channel (herddb.network.Channel)19 ByteBuf (io.netty.buffer.ByteBuf)17 TimeoutException (java.util.concurrent.TimeoutException)16 HDBOperationTimeoutException (herddb.client.impl.HDBOperationTimeoutException)11 RawString (herddb.utils.RawString)7 Test (org.junit.Test)7 PduCodec (herddb.proto.PduCodec)6 ExecutorService (java.util.concurrent.ExecutorService)6 ChannelEventListener (herddb.network.ChannelEventListener)5 ServerSideConnection (herddb.network.ServerSideConnection)5 ArrayList (java.util.ArrayList)5 Random (java.util.Random)5 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)5 CompletableFuture (java.util.concurrent.CompletableFuture)4 DumpedLogEntry (herddb.backup.DumpedLogEntry)3 ServerConfiguration (herddb.server.ServerConfiguration)3 DataStorageManagerException (herddb.storage.DataStorageManagerException)3 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)3 IOException (java.io.IOException)3