use of org.apache.asterix.common.messaging.api.INCMessageBroker in project asterixdb by apache.
the class GlobalResourceIdFactory method createId.
@Override
public long createId() throws HyracksDataException {
try {
ResourceIdRequestResponseMessage reponse = null;
//if there already exists a response, use it
if (!resourceIdResponseQ.isEmpty()) {
synchronized (resourceIdResponseQ) {
if (!resourceIdResponseQ.isEmpty()) {
reponse = resourceIdResponseQ.take();
}
}
}
//if no response available or it has an exception, request a new one
if (reponse == null || reponse.getException() != null) {
ResourceIdRequestMessage msg = new ResourceIdRequestMessage(nodeId);
((INCMessageBroker) serviceCtx.getMessageBroker()).sendMessageToCC(msg);
reponse = resourceIdResponseQ.take();
if (reponse.getException() != null) {
throw new HyracksDataException(reponse.getException().getMessage());
}
}
return reponse.getResourceId();
} catch (Exception e) {
throw new HyracksDataException(e);
}
}
use of org.apache.asterix.common.messaging.api.INCMessageBroker in project asterixdb by apache.
the class CompleteFailbackRequestMessage method handle.
@Override
public void handle(INcApplicationContext appContext) throws HyracksDataException, InterruptedException {
INCMessageBroker broker = (INCMessageBroker) appContext.getServiceContext().getMessageBroker();
HyracksDataException hde = null;
try {
IRemoteRecoveryManager remoteRecoeryManager = appContext.getRemoteRecoveryManager();
remoteRecoeryManager.completeFailbackProcess();
} catch (IOException | InterruptedException e) {
LOGGER.log(Level.SEVERE, "Failure during completion of failback process", e);
hde = HyracksDataException.create(e);
} finally {
CompleteFailbackResponseMessage reponse = new CompleteFailbackResponseMessage(planId, requestId, partitions);
try {
broker.sendMessageToCC(reponse);
} catch (Exception e) {
LOGGER.log(Level.SEVERE, "Failure sending message to CC", e);
hde = HyracksDataException.suppress(hde, e);
}
}
if (hde != null) {
throw hde;
}
}
use of org.apache.asterix.common.messaging.api.INCMessageBroker in project asterixdb by apache.
the class PreparePartitionsFailbackRequestMessage method handle.
@Override
public void handle(INcApplicationContext appContext) throws HyracksDataException, InterruptedException {
INCMessageBroker broker = (INCMessageBroker) appContext.getServiceContext().getMessageBroker();
/**
* if the metadata partition will be failed back
* we need to flush and close all datasets including metadata datasets
* otherwise we need to close all non-metadata datasets and flush metadata datasets
* so that their memory components will be copied to the failing back node
*/
if (releaseMetadataNode) {
appContext.getDatasetLifecycleManager().closeAllDatasets();
//remove the metadata node stub from RMI registry
try {
appContext.unexportMetadataNodeStub();
} catch (RemoteException e) {
LOGGER.log(Level.SEVERE, "Failed unexporting metadata stub", e);
throw HyracksDataException.create(e);
}
} else {
//close all non-metadata datasets
appContext.getDatasetLifecycleManager().closeUserDatasets();
//flush the remaining metadata datasets that were not closed
appContext.getDatasetLifecycleManager().flushAllDatasets();
}
//mark the partitions to be closed as inactive
PersistentLocalResourceRepository localResourceRepo = (PersistentLocalResourceRepository) appContext.getLocalResourceRepository();
for (Integer partitionId : partitions) {
localResourceRepo.addInactivePartition(partitionId);
}
//send response after partitions prepared for failback
PreparePartitionsFailbackResponseMessage reponse = new PreparePartitionsFailbackResponseMessage(planId, requestId, partitions);
try {
broker.sendMessageToCC(reponse);
} catch (Exception e) {
LOGGER.log(Level.SEVERE, "Failed sending message to cc", e);
throw HyracksDataException.create(e);
}
}
use of org.apache.asterix.common.messaging.api.INCMessageBroker in project asterixdb by apache.
the class ReplayPartitionLogsRequestMessage method handle.
@Override
public void handle(INcApplicationContext appContext) throws HyracksDataException, InterruptedException {
NodeControllerService ncs = (NodeControllerService) appContext.getServiceContext().getControllerService();
// Replay the logs for these partitions and flush any impacted dataset
appContext.getRemoteRecoveryManager().replayReplicaPartitionLogs(partitions, true);
INCMessageBroker broker = (INCMessageBroker) ncs.getContext().getMessageBroker();
ReplayPartitionLogsResponseMessage reponse = new ReplayPartitionLogsResponseMessage(ncs.getId(), partitions);
try {
broker.sendMessageToCC(reponse);
} catch (Exception e) {
LOGGER.log(Level.SEVERE, "Failed sending message to cc", e);
throw HyracksDataException.create(e);
}
}
use of org.apache.asterix.common.messaging.api.INCMessageBroker in project asterixdb by apache.
the class NCQueryServiceServlet method executeStatement.
@Override
protected void executeStatement(String statementsText, SessionOutput sessionOutput, IStatementExecutor.ResultDelivery delivery, IStatementExecutor.Stats stats, RequestParameters param, String handleUrl, long[] outExecStartEnd) throws Exception {
// Running on NC -> send 'execute' message to CC
INCServiceContext ncCtx = (INCServiceContext) serviceCtx;
INCMessageBroker ncMb = (INCMessageBroker) ncCtx.getMessageBroker();
IStatementExecutor.ResultDelivery ccDelivery = delivery == IStatementExecutor.ResultDelivery.IMMEDIATE ? IStatementExecutor.ResultDelivery.DEFERRED : delivery;
ExecuteStatementResponseMessage responseMsg;
MessageFuture responseFuture = ncMb.registerMessageFuture();
try {
ExecuteStatementRequestMessage requestMsg = new ExecuteStatementRequestMessage(ncCtx.getNodeId(), responseFuture.getFutureId(), queryLanguage, statementsText, sessionOutput.config(), ccDelivery, param.clientContextID, handleUrl);
outExecStartEnd[0] = System.nanoTime();
ncMb.sendMessageToCC(requestMsg);
responseMsg = (ExecuteStatementResponseMessage) responseFuture.get(ExecuteStatementResponseMessage.DEFAULT_TIMEOUT_MILLIS, java.util.concurrent.TimeUnit.MILLISECONDS);
outExecStartEnd[1] = System.nanoTime();
} finally {
ncMb.deregisterMessageFuture(responseFuture.getFutureId());
}
Throwable err = responseMsg.getError();
if (err != null) {
if (err instanceof Error) {
throw (Error) err;
} else if (err instanceof Exception) {
throw (Exception) err;
} else {
throw new Exception(err.toString(), err);
}
}
IStatementExecutor.ResultMetadata resultMetadata = responseMsg.getMetadata();
if (delivery == IStatementExecutor.ResultDelivery.IMMEDIATE && !resultMetadata.getResultSets().isEmpty()) {
for (Triple<JobId, ResultSetId, ARecordType> rsmd : resultMetadata.getResultSets()) {
ResultReader resultReader = new ResultReader(getHyracksDataset(), rsmd.getLeft(), rsmd.getMiddle());
ResultUtil.printResults(appCtx, resultReader, sessionOutput, stats, rsmd.getRight());
}
} else {
sessionOutput.out().append(responseMsg.getResult());
}
}
Aggregations