Search in sources :

Example 1 with INCMessageBroker

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);
    }
}
Also used : ResourceIdRequestMessage(org.apache.asterix.runtime.message.ResourceIdRequestMessage) INCMessageBroker(org.apache.asterix.common.messaging.api.INCMessageBroker) ResourceIdRequestResponseMessage(org.apache.asterix.runtime.message.ResourceIdRequestResponseMessage) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Example 2 with INCMessageBroker

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;
    }
}
Also used : IOException(java.io.IOException) INCMessageBroker(org.apache.asterix.common.messaging.api.INCMessageBroker) IRemoteRecoveryManager(org.apache.asterix.common.replication.IRemoteRecoveryManager) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) IOException(java.io.IOException)

Example 3 with INCMessageBroker

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);
    }
}
Also used : PersistentLocalResourceRepository(org.apache.asterix.transaction.management.resource.PersistentLocalResourceRepository) INCMessageBroker(org.apache.asterix.common.messaging.api.INCMessageBroker) RemoteException(java.rmi.RemoteException) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) RemoteException(java.rmi.RemoteException)

Example 4 with INCMessageBroker

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);
    }
}
Also used : NodeControllerService(org.apache.hyracks.control.nc.NodeControllerService) INCMessageBroker(org.apache.asterix.common.messaging.api.INCMessageBroker) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Example 5 with INCMessageBroker

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());
    }
}
Also used : ResultReader(org.apache.asterix.app.result.ResultReader) ExecuteStatementResponseMessage(org.apache.asterix.app.message.ExecuteStatementResponseMessage) INCMessageBroker(org.apache.asterix.common.messaging.api.INCMessageBroker) ExecuteStatementRequestMessage(org.apache.asterix.app.message.ExecuteStatementRequestMessage) IStatementExecutor(org.apache.asterix.translator.IStatementExecutor) INCServiceContext(org.apache.hyracks.api.application.INCServiceContext) ResultSetId(org.apache.hyracks.api.dataset.ResultSetId) MessageFuture(org.apache.asterix.common.messaging.api.MessageFuture) ARecordType(org.apache.asterix.om.types.ARecordType) JobId(org.apache.hyracks.api.job.JobId)

Aggregations

INCMessageBroker (org.apache.asterix.common.messaging.api.INCMessageBroker)9 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)8 IOException (java.io.IOException)2 IRemoteRecoveryManager (org.apache.asterix.common.replication.IRemoteRecoveryManager)2 NodeControllerService (org.apache.hyracks.control.nc.NodeControllerService)2 RemoteException (java.rmi.RemoteException)1 ExecuteStatementRequestMessage (org.apache.asterix.app.message.ExecuteStatementRequestMessage)1 ExecuteStatementResponseMessage (org.apache.asterix.app.message.ExecuteStatementResponseMessage)1 ResultReader (org.apache.asterix.app.result.ResultReader)1 INCLifecycleTask (org.apache.asterix.common.api.INCLifecycleTask)1 INcApplicationContext (org.apache.asterix.common.api.INcApplicationContext)1 ACIDException (org.apache.asterix.common.exceptions.ACIDException)1 MessageFuture (org.apache.asterix.common.messaging.api.MessageFuture)1 ARecordType (org.apache.asterix.om.types.ARecordType)1 ResourceIdRequestMessage (org.apache.asterix.runtime.message.ResourceIdRequestMessage)1 ResourceIdRequestResponseMessage (org.apache.asterix.runtime.message.ResourceIdRequestResponseMessage)1 PersistentLocalResourceRepository (org.apache.asterix.transaction.management.resource.PersistentLocalResourceRepository)1 IStatementExecutor (org.apache.asterix.translator.IStatementExecutor)1 INCServiceContext (org.apache.hyracks.api.application.INCServiceContext)1 ResultSetId (org.apache.hyracks.api.dataset.ResultSetId)1