Search in sources :

Example 26 with ClientResponseImpl

use of org.voltdb.ClientResponseImpl in project voltdb by VoltDB.

the class ReplaySequencer method dedupe.

/**
     * Dedupe initiate task messages. Check if the initiate task message is seen before.
     *
     * @param inUniqueId The uniqueId of the message
     * @param in The initiate task message
     * @return A client response to return if it's a duplicate, otherwise null.
     */
public InitiateResponseMessage dedupe(long inUniqueId, TransactionInfoBaseMessage in) {
    if (in instanceof Iv2InitiateTaskMessage) {
        final Iv2InitiateTaskMessage init = (Iv2InitiateTaskMessage) in;
        final StoredProcedureInvocation invocation = init.getStoredProcedureInvocation();
        final String procName = invocation.getProcName();
        /*
             * Ning - @LoadSinglepartTable and @LoadMultipartTable always have the same txnId
             * which is the txnId of the snapshot.
             */
        if (!(procName.equalsIgnoreCase("@LoadSinglepartitionTable") || procName.equalsIgnoreCase("@LoadMultipartitionTable")) && inUniqueId <= m_lastSeenUniqueId) {
            // already sequenced
            final InitiateResponseMessage resp = new InitiateResponseMessage(init);
            resp.setResults(new ClientResponseImpl(ClientResponseImpl.UNEXPECTED_FAILURE, new VoltTable[0], ClientResponseImpl.IGNORED_TRANSACTION));
            return resp;
        }
    }
    return null;
}
Also used : StoredProcedureInvocation(org.voltdb.StoredProcedureInvocation) Iv2InitiateTaskMessage(org.voltdb.messaging.Iv2InitiateTaskMessage) InitiateResponseMessage(org.voltdb.messaging.InitiateResponseMessage) ClientResponseImpl(org.voltdb.ClientResponseImpl) VoltTable(org.voltdb.VoltTable)

Example 27 with ClientResponseImpl

use of org.voltdb.ClientResponseImpl in project voltdb by VoltDB.

the class CSVTupleDataLoader method insertRow.

@Override
public void insertRow(RowWithMetaData metaData, Object[] values) throws InterruptedException {
    try {
        PartitionSingleExecuteProcedureCallback cbmt = new PartitionSingleExecuteProcedureCallback(metaData);
        if (!m_client.callProcedure(cbmt, m_insertProcedure, values)) {
            m_log.fatal("Failed to send CSV insert to VoltDB cluster.");
            ClientResponse response = new ClientResponseImpl(ClientResponseImpl.SERVER_UNAVAILABLE, new VoltTable[0], "Failed to call procedure.", 0);
            m_errHandler.handleError(metaData, response, "Failed to call procedure.");
        }
    } catch (NoConnectionsException ex) {
        ClientResponse response = new ClientResponseImpl(ClientResponseImpl.SERVER_UNAVAILABLE, new VoltTable[0], "Failed to call procedure.", 0);
        m_errHandler.handleError(metaData, response, "Failed to call procedure.");
    } catch (IOException ex) {
        ClientResponse response = new ClientResponseImpl(ClientResponseImpl.SERVER_UNAVAILABLE, new VoltTable[0], "Failed to call procedure.", 0);
        m_errHandler.handleError(metaData, response, "Failed to call procedure.");
    } catch (Exception ex) {
        m_errHandler.handleError(metaData, null, ex.toString());
    }
}
Also used : ClientResponse(org.voltdb.client.ClientResponse) NoConnectionsException(org.voltdb.client.NoConnectionsException) ClientResponseImpl(org.voltdb.ClientResponseImpl) IOException(java.io.IOException) VoltTable(org.voltdb.VoltTable) IOException(java.io.IOException) ProcCallException(org.voltdb.client.ProcCallException) NoConnectionsException(org.voltdb.client.NoConnectionsException)

Example 28 with ClientResponseImpl

use of org.voltdb.ClientResponseImpl in project voltdb by VoltDB.

the class Distributer method refreshPartitionKeys.

/**
     * Set up partitions.
     * @param topologyUpdate  if true, it is called from topology update
     * @throws ProcCallException on any VoltDB specific failure.
     * @throws NoConnectionsException if this {@link Client} instance is not connected to any servers.
     * @throws IOException if there is a Java network or connection problem.
     */
private void refreshPartitionKeys(boolean topologyUpdate) {
    long interval = System.currentTimeMillis() - m_lastPartitionKeyFetched.get();
    if (!m_useClientAffinity && interval < PARTITION_KEYS_INFO_REFRESH_FREQUENCY) {
        return;
    }
    try {
        ProcedureInvocation invocation = new ProcedureInvocation(m_sysHandle.getAndDecrement(), "@GetPartitionKeys", "INTEGER");
        CountDownLatch latch = null;
        if (!topologyUpdate) {
            latch = new CountDownLatch(1);
        }
        PartitionUpdateCallback cb = new PartitionUpdateCallback(latch);
        if (!queue(invocation, cb, true, System.nanoTime(), USE_DEFAULT_CLIENT_TIMEOUT)) {
            m_partitionUpdateStatus.set(new ClientResponseImpl(ClientResponseImpl.SERVER_UNAVAILABLE, new VoltTable[0], "Fails to queue the partition update query, please try later."));
        }
        if (!topologyUpdate) {
            latch.await();
        }
        m_lastPartitionKeyFetched.set(System.currentTimeMillis());
    } catch (InterruptedException | IOException e) {
        m_partitionUpdateStatus.set(new ClientResponseImpl(ClientResponseImpl.SERVER_UNAVAILABLE, new VoltTable[0], "Fails to fetch partition keys from server:" + e.getMessage()));
    }
}
Also used : ClientResponseImpl(org.voltdb.ClientResponseImpl) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch) VoltTable(org.voltdb.VoltTable)

Example 29 with ClientResponseImpl

use of org.voltdb.ClientResponseImpl in project voltdb by VoltDB.

the class ClientImpl method internalSyncCallProcedure.

private final ClientResponse internalSyncCallProcedure(long clientTimeoutNanos, ProcedureInvocation invocation) throws ProcCallException, IOException {
    if (m_isShutdown) {
        throw new NoConnectionsException("Client instance is shutdown");
    }
    if (m_blessedThreadIds.contains(Thread.currentThread().getId())) {
        throw new IOException("Can't invoke a procedure synchronously from with the client callback thread " + " without deadlocking the client library");
    }
    SyncCallbackLight cb = new SyncCallbackLight();
    boolean success = internalAsyncCallProcedure(cb, clientTimeoutNanos, invocation);
    if (!success) {
        final ClientResponseImpl r = new ClientResponseImpl(ClientResponse.GRACEFUL_FAILURE, ClientResponse.UNINITIALIZED_APP_STATUS_CODE, "", new VoltTable[0], String.format("Unable to queue client request."));
        throw new ProcCallException(r, "Unable to queue client request.", null);
    }
    try {
        cb.waitForResponse();
    } catch (final InterruptedException e) {
        throw new java.io.InterruptedIOException("Interrupted while waiting for response");
    }
    if (cb.getResponse().getStatus() != ClientResponse.SUCCESS) {
        throw new ProcCallException(cb.getResponse(), cb.getResponse().getStatusString(), null);
    }
    return cb.getResponse();
}
Also used : IOException(java.io.IOException) ClientResponseImpl(org.voltdb.ClientResponseImpl)

Example 30 with ClientResponseImpl

use of org.voltdb.ClientResponseImpl in project voltdb by VoltDB.

the class ClientImpl method callAllPartitionProcedure.

@Override
public boolean callAllPartitionProcedure(AllPartitionProcedureCallback callback, String procedureName, Object... params) throws IOException, NoConnectionsException, ProcCallException {
    if (callback == null) {
        throw new IllegalArgumentException("AllPartitionProcedureCallback can not be null");
    }
    Object[] args = new Object[params.length + 1];
    System.arraycopy(params, 0, args, 1, params.length);
    final ImmutableSet<Integer> partitionSet = m_distributer.getPartitionKeys();
    int partitionCount = partitionSet.size();
    AtomicInteger counter = new AtomicInteger(partitionCount);
    assert (partitionCount > 0);
    ClientResponseWithPartitionKey[] responses = new ClientResponseWithPartitionKey[partitionCount];
    for (Integer key : partitionSet) {
        args[0] = key;
        partitionCount--;
        OnePartitionProcedureCallback cb = new OnePartitionProcedureCallback(counter, key, partitionCount, responses, callback);
        try {
            // set to true. This gives a nice error message if the target procedure is incompatible.
            if (!callProcedureWithClientTimeout(cb, BatchTimeoutOverrideType.NO_TIMEOUT, true, procedureName, Distributer.USE_DEFAULT_CLIENT_TIMEOUT, TimeUnit.NANOSECONDS, args)) {
                final ClientResponse r = new ClientResponseImpl(ClientResponse.GRACEFUL_FAILURE, new VoltTable[0], "The procedure is not queued for execution.");
                throw new ProcCallException(r, null, null);
            }
        } catch (Exception ex) {
            try {
                cb.exceptionCallback(ex);
            } catch (Exception e) {
                throw new IOException(e);
            }
        }
    }
    return true;
}
Also used : IOException(java.io.IOException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ClientResponseImpl(org.voltdb.ClientResponseImpl)

Aggregations

ClientResponseImpl (org.voltdb.ClientResponseImpl)32 VoltTable (org.voltdb.VoltTable)20 IOException (java.io.IOException)10 ClientResponse (org.voltdb.client.ClientResponse)10 InitiateResponseMessage (org.voltdb.messaging.InitiateResponseMessage)7 CompletableFuture (java.util.concurrent.CompletableFuture)5 StoredProcedureInvocation (org.voltdb.StoredProcedureInvocation)4 ProcCallException (org.voltdb.client.ProcCallException)4 Client (org.voltdb.client.Client)3 NoConnectionsException (org.voltdb.client.NoConnectionsException)3 Iv2InitiateTaskMessage (org.voltdb.messaging.Iv2InitiateTaskMessage)3 File (java.io.File)2 ArrayList (java.util.ArrayList)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 CatalogContext (org.voltdb.CatalogContext)2 ServerThread (org.voltdb.ServerThread)2 TableHelper (org.voltdb.TableHelper)2 VoltDB (org.voltdb.VoltDB)2 Configuration (org.voltdb.VoltDB.Configuration)2 Database (org.voltdb.catalog.Database)2