Search in sources :

Example 6 with ICcApplicationContext

use of org.apache.asterix.common.dataflow.ICcApplicationContext in project asterixdb by apache.

the class VersionApiServlet method get.

@Override
protected void get(IServletRequest request, IServletResponse response) {
    response.setStatus(HttpResponseStatus.OK);
    ICcApplicationContext props = (ICcApplicationContext) ctx.get(ASTERIX_APP_CONTEXT_INFO_ATTR);
    Map<String, String> buildProperties = props.getBuildProperties().getAllProps();
    ObjectMapper om = new ObjectMapper();
    ObjectNode responseObject = om.createObjectNode();
    for (Map.Entry<String, String> e : buildProperties.entrySet()) {
        responseObject.put(e.getKey(), e.getValue());
    }
    try {
        HttpUtil.setContentType(response, HttpUtil.ContentType.TEXT_PLAIN, HttpUtil.Encoding.UTF8);
    } catch (IOException e) {
        LOGGER.log(Level.WARNING, "Failure handling request", e);
        response.setStatus(HttpResponseStatus.INTERNAL_SERVER_ERROR);
        return;
    }
    PrintWriter responseWriter = response.writer();
    responseWriter.write(responseObject.toString());
    responseWriter.flush();
}
Also used : ICcApplicationContext(org.apache.asterix.common.dataflow.ICcApplicationContext) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) IOException(java.io.IOException) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) PrintWriter(java.io.PrintWriter)

Example 7 with ICcApplicationContext

use of org.apache.asterix.common.dataflow.ICcApplicationContext in project asterixdb by apache.

the class AutoFaultToleranceStrategy method processPendingFailbackPlans.

private synchronized void processPendingFailbackPlans() {
    ClusterState state = clusterManager.getState();
    /*
         * if the cluster state is not ACTIVE, then failbacks should not be processed
         * since some partitions are not active
         */
    if (state == ClusterState.ACTIVE) {
        while (!pendingProcessingFailbackPlans.isEmpty()) {
            //take the first pending failback plan
            NodeFailbackPlan plan = pendingProcessingFailbackPlans.pop();
            /*
                 * A plan at this stage will be in one of two states:
                 * 1. PREPARING -> the participants were selected but we haven't sent any request.
                 * 2. PENDING_ROLLBACK -> a participant failed before we send any requests
                 */
            if (plan.getState() == FailbackPlanState.PREPARING) {
                //set the partitions that will be failed back as inactive
                String failbackNode = plan.getNodeId();
                for (Integer partitionId : plan.getPartitionsToFailback()) {
                    //partition expected to be returned to the failing back node
                    clusterManager.updateClusterPartition(partitionId, failbackNode, false);
                }
                /*
                     * if the returning node is the original metadata node,
                     * then metadata node will change after the failback completes
                     */
                ICcApplicationContext appCtx = (ICcApplicationContext) serviceCtx.getApplicationContext();
                String originalMetadataNode = appCtx.getMetadataProperties().getMetadataNodeName();
                if (originalMetadataNode.equals(failbackNode)) {
                    plan.setNodeToReleaseMetadataManager(currentMetadataNode);
                    currentMetadataNode = "";
                    metadataNodeActive = false;
                    clusterManager.updateMetadataNode(currentMetadataNode, metadataNodeActive);
                }
                //force new jobs to wait
                clusterManager.setState(ClusterState.REBALANCING);
                handleFailbackRequests(plan, messageBroker);
                /*
                     * wait until the current plan is completed before processing the next plan.
                     * when the current one completes or is reverted, the cluster state will be
                     * ACTIVE again, and the next failback plan (if any) will be processed.
                     */
                break;
            } else if (plan.getState() == FailbackPlanState.PENDING_ROLLBACK) {
                //this plan failed before sending any requests -> nothing to rollback
                planId2FailbackPlanMap.remove(plan.getPlanId());
            }
        }
    }
}
Also used : ClusterState(org.apache.asterix.common.api.IClusterManagementWork.ClusterState) ICcApplicationContext(org.apache.asterix.common.dataflow.ICcApplicationContext)

Example 8 with ICcApplicationContext

use of org.apache.asterix.common.dataflow.ICcApplicationContext in project asterixdb by apache.

the class AutoFaultToleranceStrategy method requestPartitionsTakeover.

private synchronized void requestPartitionsTakeover(String failedNodeId) {
    //replica -> list of partitions to takeover
    Map<String, List<Integer>> partitionRecoveryPlan = new HashMap<>();
    ICcApplicationContext appCtx = (ICcApplicationContext) serviceCtx.getApplicationContext();
    ReplicationProperties replicationProperties = appCtx.getReplicationProperties();
    //collect the partitions of the failed NC
    List<ClusterPartition> lostPartitions = getNodeAssignedPartitions(failedNodeId);
    if (!lostPartitions.isEmpty()) {
        for (ClusterPartition partition : lostPartitions) {
            //find replicas for this partitions
            Set<String> partitionReplicas = replicationProperties.getNodeReplicasIds(partition.getNodeId());
            //find a replica that is still active
            for (String replica : partitionReplicas) {
                //It needs to be modified to consider load balancing.
                if (addActiveReplica(replica, partition, partitionRecoveryPlan)) {
                    break;
                }
            }
        }
        if (partitionRecoveryPlan.size() == 0) {
            //no active replicas were found for the failed node
            LOGGER.severe("Could not find active replicas for the partitions " + lostPartitions);
            return;
        } else {
            LOGGER.info("Partitions to recover: " + lostPartitions);
        }
        //For each replica, send a request to takeover the assigned partitions
        for (Entry<String, List<Integer>> entry : partitionRecoveryPlan.entrySet()) {
            String replica = entry.getKey();
            Integer[] partitionsToTakeover = entry.getValue().toArray(new Integer[entry.getValue().size()]);
            long requestId = clusterRequestId++;
            TakeoverPartitionsRequestMessage takeoverRequest = new TakeoverPartitionsRequestMessage(requestId, replica, partitionsToTakeover);
            pendingTakeoverRequests.put(requestId, takeoverRequest);
            try {
                messageBroker.sendApplicationMessageToNC(takeoverRequest, replica);
            } catch (Exception e) {
                /*
                     * if we fail to send the request, it means the NC we tried to send the request to
                     * has failed. When the failure notification arrives, we will send any pending request
                     * that belongs to the failed NC to a different active replica.
                     */
                LOGGER.log(Level.WARNING, "Failed to send takeover request: " + takeoverRequest, e);
            }
        }
    }
}
Also used : TakeoverPartitionsRequestMessage(org.apache.asterix.app.replication.message.TakeoverPartitionsRequestMessage) ICcApplicationContext(org.apache.asterix.common.dataflow.ICcApplicationContext) HashMap(java.util.HashMap) RuntimeDataException(org.apache.asterix.common.exceptions.RuntimeDataException) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) ReplicationProperties(org.apache.asterix.common.config.ReplicationProperties) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) ClusterPartition(org.apache.asterix.common.cluster.ClusterPartition)

Example 9 with ICcApplicationContext

use of org.apache.asterix.common.dataflow.ICcApplicationContext in project asterixdb by apache.

the class MetadataNodeFaultToleranceStrategy method getMetadataPartitionRecoveryPlan.

private RemoteRecoveryTask getMetadataPartitionRecoveryPlan() {
    if (hotStandbyMetadataReplica.isEmpty()) {
        throw new IllegalStateException("No metadata replicas to recover from");
    }
    // Construct recovery plan: Node => Set of partitions to recover from it
    Map<String, Set<Integer>> recoveryPlan = new HashMap<>();
    // Recover metadata partition from any metadata hot standby replica
    ICcApplicationContext appCtx = (ICcApplicationContext) serviceCtx.getApplicationContext();
    int metadataPartitionId = appCtx.getMetadataProperties().getMetadataPartition().getPartitionId();
    Set<Integer> metadataPartition = new HashSet<>(Arrays.asList(metadataPartitionId));
    recoveryPlan.put(hotStandbyMetadataReplica.iterator().next(), metadataPartition);
    return new RemoteRecoveryTask(recoveryPlan);
}
Also used : ICcApplicationContext(org.apache.asterix.common.dataflow.ICcApplicationContext) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) RemoteRecoveryTask(org.apache.asterix.app.nc.task.RemoteRecoveryTask) HashSet(java.util.HashSet)

Example 10 with ICcApplicationContext

use of org.apache.asterix.common.dataflow.ICcApplicationContext in project asterixdb by apache.

the class MetadataNodeFaultToleranceStrategy method notifyNodeFailure.

@Override
public synchronized void notifyNodeFailure(String nodeId) throws HyracksDataException {
    failedNodes.add(nodeId);
    hotStandbyMetadataReplica.remove(nodeId);
    clusterManager.updateNodePartitions(nodeId, false);
    if (nodeId.equals(metadataNodeId)) {
        clusterManager.updateMetadataNode(metadataNodeId, false);
    }
    clusterManager.refreshState();
    if (replicationStrategy.isParticipant(nodeId)) {
        // Notify impacted replica
        FaultToleranceUtil.notifyImpactedReplicas(nodeId, ClusterEventType.NODE_FAILURE, clusterManager, messageBroker, replicationStrategy);
    }
    // If the failed node is the metadata node, ask its replicas to replay any committed jobs
    if (nodeId.equals(metadataNodeId)) {
        ICcApplicationContext appCtx = (ICcApplicationContext) serviceCtx.getApplicationContext();
        int metadataPartitionId = appCtx.getMetadataProperties().getMetadataPartition().getPartitionId();
        Set<Integer> metadataPartition = new HashSet<>(Arrays.asList(metadataPartitionId));
        Set<Replica> activeRemoteReplicas = replicationStrategy.getRemoteReplicas(metadataNodeId).stream().filter(replica -> !failedNodes.contains(replica.getId())).collect(Collectors.toSet());
        //TODO Do election to identity the node with latest state
        for (Replica replica : activeRemoteReplicas) {
            ReplayPartitionLogsRequestMessage msg = new ReplayPartitionLogsRequestMessage(metadataPartition);
            try {
                messageBroker.sendApplicationMessageToNC(msg, replica.getId());
            } catch (Exception e) {
                LOGGER.log(Level.WARNING, "Failed sending an application message to an NC", e);
                continue;
            }
        }
    }
}
Also used : ReportMaxResourceIdTask(org.apache.asterix.app.nc.task.ReportMaxResourceIdTask) IFaultToleranceStrategy(org.apache.asterix.common.replication.IFaultToleranceStrategy) Arrays(java.util.Arrays) ICCMessageBroker(org.apache.asterix.common.messaging.api.ICCMessageBroker) NCLifecycleTaskReportMessage(org.apache.asterix.app.replication.message.NCLifecycleTaskReportMessage) INCLifecycleTask(org.apache.asterix.common.api.INCLifecycleTask) ClusterPartition(org.apache.asterix.common.cluster.ClusterPartition) RuntimeDataException(org.apache.asterix.common.exceptions.RuntimeDataException) INCLifecycleMessage(org.apache.asterix.common.replication.INCLifecycleMessage) CheckpointTask(org.apache.asterix.app.nc.task.CheckpointTask) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) HashMap(java.util.HashMap) ErrorCode(org.apache.asterix.common.exceptions.ErrorCode) ReplayPartitionLogsResponseMessage(org.apache.asterix.app.replication.message.ReplayPartitionLogsResponseMessage) ICCServiceContext(org.apache.hyracks.api.application.ICCServiceContext) ICcApplicationContext(org.apache.asterix.common.dataflow.ICcApplicationContext) IReplicationStrategy(org.apache.asterix.common.replication.IReplicationStrategy) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) HashSet(java.util.HashSet) Map(java.util.Map) RemoteRecoveryTask(org.apache.asterix.app.nc.task.RemoteRecoveryTask) FaultToleranceUtil(org.apache.asterix.util.FaultToleranceUtil) ExternalLibrarySetupTask(org.apache.asterix.app.nc.task.ExternalLibrarySetupTask) Replica(org.apache.asterix.common.replication.Replica) ClusterEventType(org.apache.hyracks.api.application.IClusterLifecycleListener.ClusterEventType) Set(java.util.Set) StartLifecycleComponentsTask(org.apache.asterix.app.nc.task.StartLifecycleComponentsTask) StartupTaskRequestMessage(org.apache.asterix.app.replication.message.StartupTaskRequestMessage) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) LocalRecoveryTask(org.apache.asterix.app.nc.task.LocalRecoveryTask) StartReplicationServiceTask(org.apache.asterix.app.nc.task.StartReplicationServiceTask) List(java.util.List) BindMetadataNodeTask(org.apache.asterix.app.nc.task.BindMetadataNodeTask) MetadataBootstrapTask(org.apache.asterix.app.nc.task.MetadataBootstrapTask) ReplayPartitionLogsRequestMessage(org.apache.asterix.app.replication.message.ReplayPartitionLogsRequestMessage) StartupTaskResponseMessage(org.apache.asterix.app.replication.message.StartupTaskResponseMessage) IClusterStateManager(org.apache.asterix.common.cluster.IClusterStateManager) SystemState(org.apache.asterix.common.transactions.IRecoveryManager.SystemState) ICcApplicationContext(org.apache.asterix.common.dataflow.ICcApplicationContext) ReplayPartitionLogsRequestMessage(org.apache.asterix.app.replication.message.ReplayPartitionLogsRequestMessage) Replica(org.apache.asterix.common.replication.Replica) RuntimeDataException(org.apache.asterix.common.exceptions.RuntimeDataException) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) HashSet(java.util.HashSet)

Aggregations

ICcApplicationContext (org.apache.asterix.common.dataflow.ICcApplicationContext)10 ClusterPartition (org.apache.asterix.common.cluster.ClusterPartition)4 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)4 HashMap (java.util.HashMap)3 Set (java.util.Set)3 RuntimeDataException (org.apache.asterix.common.exceptions.RuntimeDataException)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Map (java.util.Map)2 RemoteRecoveryTask (org.apache.asterix.app.nc.task.RemoteRecoveryTask)2 ReplicationProperties (org.apache.asterix.common.config.ReplicationProperties)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 PrintWriter (java.io.PrintWriter)1 InetAddress (java.net.InetAddress)1 UnknownHostException (java.net.UnknownHostException)1 Arrays (java.util.Arrays)1 LinkedList (java.util.LinkedList)1