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;
}
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());
}
}
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()));
}
}
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();
}
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;
}
Aggregations