Search in sources :

Example 1 with ReplicaMovementStrategy

use of com.linkedin.kafka.cruisecontrol.executor.strategy.ReplicaMovementStrategy in project cruise-control by linkedin.

the class ParameterUtils method getReplicaMovementStrategy.

/**
 * Get a composite replica movement strategy for {@link com.linkedin.kafka.cruisecontrol.executor.ExecutionTaskPlanner}.
 *
 * @param request The http request.
 * @param config The configuration of Cruise Control.
 * @return A composite strategy generated by chaining all the strategies specified by the http request.
 */
static ReplicaMovementStrategy getReplicaMovementStrategy(HttpServletRequest request, KafkaCruiseControlConfig config) throws UnsupportedEncodingException {
    if (getDryRun(request)) {
        return null;
    }
    List<String> strategies = getListParam(request, REPLICA_MOVEMENT_STRATEGIES_PARAM);
    if (strategies.isEmpty()) {
        return null;
    }
    List<ReplicaMovementStrategy> supportedStrategies = config.getConfiguredInstances(ExecutorConfig.REPLICA_MOVEMENT_STRATEGIES_CONFIG, ReplicaMovementStrategy.class);
    Map<String, ReplicaMovementStrategy> supportedStrategiesByName = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
    for (ReplicaMovementStrategy strategy : supportedStrategies) {
        supportedStrategiesByName.put(strategy.name(), strategy);
    }
    ReplicaMovementStrategy strategy = null;
    for (String strategyName : strategies) {
        if (supportedStrategiesByName.containsKey(strategyName)) {
            strategy = strategy == null ? supportedStrategiesByName.get(strategyName) : strategy.chain(supportedStrategiesByName.get(strategyName));
        } else {
            throw new UserRequestException("Strategy " + strategyName + " is not supported. Supported: " + supportedStrategiesByName.keySet());
        }
    }
    return strategy.chainBaseReplicaMovementStrategyIfAbsent();
}
Also used : ReplicaMovementStrategy(com.linkedin.kafka.cruisecontrol.executor.strategy.ReplicaMovementStrategy) TreeMap(java.util.TreeMap) UserRequestException(com.linkedin.kafka.cruisecontrol.servlet.UserRequestException)

Example 2 with ReplicaMovementStrategy

use of com.linkedin.kafka.cruisecontrol.executor.strategy.ReplicaMovementStrategy in project cruise-control by linkedin.

the class ExecutionTaskPlanner method maybeAddInterBrokerReplicaMovementTasks.

/**
 * For each proposal, create a replica action task if there is a need for moving replica(s) between brokers to reach
 * expected final proposal state.
 *
 * @param proposals Execution proposals.
 * @param strategyOptions Strategy options to be used during application of a replica movement strategy.
 * @param replicaMovementStrategy The strategy used to determine the execution order of generated replica movement tasks.
 */
private void maybeAddInterBrokerReplicaMovementTasks(Collection<ExecutionProposal> proposals, StrategyOptions strategyOptions, ReplicaMovementStrategy replicaMovementStrategy) {
    for (ExecutionProposal proposal : proposals) {
        TopicPartition tp = proposal.topicPartition();
        PartitionInfo partitionInfo = strategyOptions.cluster().partition(tp);
        if (partitionInfo == null) {
            LOG.trace("Ignored the attempt to move non-existing partition for topic partition: {}", tp);
            continue;
        }
        if (!proposal.isInterBrokerMovementCompleted(partitionInfo)) {
            long replicaActionExecutionId = _executionId++;
            long executionAlertingThresholdMs = Math.max(Math.round(proposal.dataToMoveInMB() / _interBrokerReplicaMovementRateAlertingThreshold), _taskExecutionAlertingThresholdMs);
            ExecutionTask executionTask = new ExecutionTask(replicaActionExecutionId, proposal, INTER_BROKER_REPLICA_ACTION, executionAlertingThresholdMs);
            _remainingInterBrokerReplicaMovements.add(executionTask);
            LOG.trace("Added action {} as replica proposal {}", replicaActionExecutionId, proposal);
        }
    }
    ReplicaMovementStrategy chosenReplicaMovementTaskStrategy = replicaMovementStrategy == null ? _defaultReplicaMovementTaskStrategy : replicaMovementStrategy.chainBaseReplicaMovementStrategyIfAbsent();
    _interPartMoveTasksByBrokerId = chosenReplicaMovementTaskStrategy.applyStrategy(_remainingInterBrokerReplicaMovements, strategyOptions);
    _interPartMoveBrokerComparator = brokerComparator(strategyOptions, chosenReplicaMovementTaskStrategy);
}
Also used : BaseReplicaMovementStrategy(com.linkedin.kafka.cruisecontrol.executor.strategy.BaseReplicaMovementStrategy) ReplicaMovementStrategy(com.linkedin.kafka.cruisecontrol.executor.strategy.ReplicaMovementStrategy) TopicPartition(org.apache.kafka.common.TopicPartition) PartitionInfo(org.apache.kafka.common.PartitionInfo)

Aggregations

ReplicaMovementStrategy (com.linkedin.kafka.cruisecontrol.executor.strategy.ReplicaMovementStrategy)2 BaseReplicaMovementStrategy (com.linkedin.kafka.cruisecontrol.executor.strategy.BaseReplicaMovementStrategy)1 UserRequestException (com.linkedin.kafka.cruisecontrol.servlet.UserRequestException)1 TreeMap (java.util.TreeMap)1 PartitionInfo (org.apache.kafka.common.PartitionInfo)1 TopicPartition (org.apache.kafka.common.TopicPartition)1