Search in sources :

Example 1 with RetryRequestException

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

the class RoutedClientSideConnection method executeGet.

GetResult executeGet(String tableSpace, String query, long tx, List<Object> params) throws HDBException, ClientSideMetadataProviderException {
    Channel _channel = ensureOpen();
    try {
        Message message = Message.EXECUTE_STATEMENT(clientId, tableSpace, query, tx, false, 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 found = (Long) reply.parameters.get("updateCount");
        long transactionId = (Long) reply.parameters.get("tx");
        if (found <= 0) {
            return new GetResult(null, transactionId);
        } else {
            return new GetResult((Map<String, Object>) reply.parameters.get("data"), 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) TimeoutException(java.util.concurrent.TimeoutException)

Example 2 with RetryRequestException

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

the class RoutedClientSideConnection method executeScan.

ScanResultSet executeScan(String tableSpace, String query, List<Object> params, long tx, int maxRows, int fetchSize) throws HDBException, ClientSideMetadataProviderException {
    Channel _channel = ensureOpen();
    try {
        String scannerId = this.clientId + ":" + SCANNERID_GENERATOR.incrementAndGet();
        Message message = Message.OPEN_SCANNER(clientId, tableSpace, query, scannerId, tx, params, fetchSize, maxRows);
        LOGGER.log(Level.FINEST, "open scanner {0} for query {1}, params {2}", new Object[] { scannerId, query, 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);
        }
        TuplesList data = (TuplesList) reply.parameters.get("data");
        List<DataAccessor> initialFetchBuffer = data.tuples;
        String[] columnNames = data.columnNames;
        boolean last = (Boolean) reply.parameters.get("last");
        long transactionId = (Long) reply.parameters.get("tx");
        // LOGGER.log(Level.SEVERE, "received first " + initialFetchBuffer.size() + " records for query " + query);
        ScanResultSetImpl impl = new ScanResultSetImpl(scannerId, columnNames, initialFetchBuffer, fetchSize, last, transactionId);
        return impl;
    } catch (InterruptedException | TimeoutException err) {
        throw new HDBException(err);
    }
}
Also used : Message(herddb.network.Message) DataAccessor(herddb.utils.DataAccessor) Channel(herddb.network.Channel) RetryRequestException(herddb.client.impl.RetryRequestException) AtomicLong(java.util.concurrent.atomic.AtomicLong) TuplesList(herddb.utils.TuplesList) TimeoutException(java.util.concurrent.TimeoutException)

Example 3 with RetryRequestException

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

the class RoutedClientSideConnection method commitTransaction.

void commitTransaction(String tableSpace, long tx) throws HDBException, ClientSideMetadataProviderException {
    Channel _channel = ensureOpen();
    try {
        Message message = Message.EXECUTE_STATEMENT(clientId, tableSpace, "COMMIT 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 4 with RetryRequestException

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

the class RoutedClientSideConnection method executeUpdates.

List<DMLResult> executeUpdates(String tableSpace, String query, long tx, boolean returnValues, List<List<Object>> batch) throws HDBException, ClientSideMetadataProviderException {
    Channel _channel = ensureOpen();
    try {
        Message message = Message.EXECUTE_STATEMENTS(clientId, tableSpace, query, tx, returnValues, batch);
        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 transactionId = (Long) reply.parameters.get("tx");
        List<Map<String, Object>> data = (List<Map<String, Object>>) reply.parameters.get("data");
        List<Long> updateCounts = (List<Long>) reply.parameters.get("updateCount");
        List<DMLResult> results = new ArrayList<>();
        for (int i = 0; i < updateCounts.size(); i++) {
            Object key = data.get(0).get("key");
            Map<String, Object> newvalue = (Map<String, Object>) data.get(i).get("newvalue");
            DMLResult res = new DMLResult(updateCounts.get(i), key, newvalue, transactionId);
            results.add(res);
        }
        return results;
    } catch (InterruptedException | TimeoutException err) {
        throw new HDBException(err);
    }
}
Also used : Message(herddb.network.Message) Channel(herddb.network.Channel) ArrayList(java.util.ArrayList) RetryRequestException(herddb.client.impl.RetryRequestException) AtomicLong(java.util.concurrent.atomic.AtomicLong) ArrayList(java.util.ArrayList) List(java.util.List) TuplesList(herddb.utils.TuplesList) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) TimeoutException(java.util.concurrent.TimeoutException)

Example 5 with RetryRequestException

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

the class RoutedClientSideConnection method beginTransaction.

long beginTransaction(String tableSpace) throws HDBException, ClientSideMetadataProviderException {
    Channel _channel = ensureOpen();
    try {
        Message message = Message.EXECUTE_STATEMENT(clientId, tableSpace, "BEGIN TRANSACTION '" + tableSpace + "'", 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);
        }
        Map<String, Object> data = (Map<String, Object>) reply.parameters.get("data");
        return (Long) data.get("tx");
    } 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)

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