Search in sources :

Example 6 with RetryRequestException

use of herddb.client.impl.RetryRequestException in project herddb by diennea.

the class RoutedClientSideConnection method rollbackTransaction.

void rollbackTransaction(String tableSpace, long tx) throws HDBException, ClientSideMetadataProviderException {
    Channel _channel = ensureOpen();
    try {
        Message message = Message.EXECUTE_STATEMENT(clientId, tableSpace, "ROLLBACK TRANSACTION '" + tableSpace + "'," + tx, 0, false, null);
        Message reply = _channel.sendMessageWithReply(message, timeout);
        if (reply.type == Message.TYPE_ERROR) {
            boolean notLeader = reply.parameters.get("notLeader") != null;
            if (notLeader) {
                this.connection.requestMetadataRefresh();
                throw new RetryRequestException(reply + "");
            }
            throw new HDBException(reply);
        }
    } catch (InterruptedException | TimeoutException err) {
        throw new HDBException(err);
    }
}
Also used : RetryRequestException(herddb.client.impl.RetryRequestException) Message(herddb.network.Message) Channel(herddb.network.Channel) TimeoutException(java.util.concurrent.TimeoutException)

Example 7 with RetryRequestException

use of herddb.client.impl.RetryRequestException in project herddb by diennea.

the class RoutedClientSideConnection method executeUpdate.

DMLResult executeUpdate(String tableSpace, String query, long tx, boolean returnValues, List<Object> params) throws HDBException, ClientSideMetadataProviderException {
    Channel _channel = ensureOpen();
    try {
        Message message = Message.EXECUTE_STATEMENT(clientId, tableSpace, query, tx, returnValues, params);
        Message reply = _channel.sendMessageWithReply(message, timeout);
        if (reply.type == Message.TYPE_ERROR) {
            boolean notLeader = reply.parameters.get("notLeader") != null;
            if (notLeader) {
                this.connection.requestMetadataRefresh();
                throw new RetryRequestException(reply + "");
            }
            throw new HDBException(reply);
        }
        long updateCount = (Long) reply.parameters.get("updateCount");
        long transactionId = (Long) reply.parameters.get("tx");
        Object key = null;
        Map<String, Object> newvalue = null;
        Map<String, Object> data = (Map<String, Object>) reply.parameters.get("data");
        if (data != null) {
            key = data.get("key");
            newvalue = (Map<String, Object>) data.get("newvalue");
        }
        return new DMLResult(updateCount, key, newvalue, transactionId);
    } catch (InterruptedException | TimeoutException err) {
        throw new HDBException(err);
    }
}
Also used : Message(herddb.network.Message) Channel(herddb.network.Channel) RetryRequestException(herddb.client.impl.RetryRequestException) AtomicLong(java.util.concurrent.atomic.AtomicLong) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) TimeoutException(java.util.concurrent.TimeoutException)

Example 8 with RetryRequestException

use of herddb.client.impl.RetryRequestException in project herddb by diennea.

the class RoutedClientSideConnection method dumpTableSpace.

void dumpTableSpace(String tableSpace, int fetchSize, boolean includeTransactionLog, TableSpaceDumpReceiver receiver) throws HDBException, ClientSideMetadataProviderException {
    Channel _channel = ensureOpen();
    try {
        String dumpId = this.clientId + ":" + SCANNERID_GENERATOR.incrementAndGet();
        Message message = Message.REQUEST_TABLESPACE_DUMP(clientId, tableSpace, dumpId, fetchSize, includeTransactionLog);
        LOGGER.log(Level.SEVERE, "dumpTableSpace id " + dumpId + " for tablespace " + tableSpace);
        dumpReceivers.put(dumpId, receiver);
        Message reply = _channel.sendMessageWithReply(message, timeout);
        LOGGER.log(Level.SEVERE, "dumpTableSpace id " + dumpId + " for tablespace " + tableSpace + ": first reply " + reply.parameters);
        if (reply.type == Message.TYPE_ERROR) {
            boolean notLeader = reply.parameters.get("notLeader") != null;
            if (notLeader) {
                this.connection.requestMetadataRefresh();
                throw new RetryRequestException(reply + "");
            }
            throw new HDBException(reply);
        }
    } catch (InterruptedException | TimeoutException err) {
        throw new HDBException(err);
    }
}
Also used : RetryRequestException(herddb.client.impl.RetryRequestException) Message(herddb.network.Message) Channel(herddb.network.Channel) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

RetryRequestException (herddb.client.impl.RetryRequestException)8 Channel (herddb.network.Channel)8 Message (herddb.network.Message)8 TimeoutException (java.util.concurrent.TimeoutException)8 AtomicLong (java.util.concurrent.atomic.AtomicLong)5 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 TuplesList (herddb.utils.TuplesList)2 DataAccessor (herddb.utils.DataAccessor)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1