Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejava
titleReplicaAssignor
package org.apache.kafka.server;

@InterfaceStability.Evolving
public interface ReplicaAssignor extends Configurable, Closeable {

    /**
     * Computes replica assignments for the specified partitions
     * 
     * If an assignment can't be computed, for example if the state of the cluster does not satisfy a requirement,
     * implementations can throw ReplicaAssignorException to prevent the topic/partition creation.
     * @param partitions The partitions being created
     * @param principal The principal of the user initiating the request
     * @return The computed replica assignments
     * @throw ReplicaAssignorException
     */
    public ReplicaAssignment computeAssignment(
            NewPartitions partitions,
            KafkaPrincipal principal) throws ReplicaAssignorException;

    /**
     * Metadata update callback that is invoked whenever UpdateMetadata request is received from
     * the controller. This is useful if quota computation takes partitions into account.
     * Topics that are being deleted will not be included in `cluster`.
     *
     * @param cluster Cluster metadata including brokers, partitions and their leaders if known
     * @return true if quotas have changed and metric configs may need to be updated
     */
    public void updateClusterMetadata(Cluster cluster);

    /**
     * Computed replica assignments for the specified partitions
     */
    public class ReplicaAssignment {

        private final Map<Integer, List<Integer>> assignment;

        public ReplicaAssignment(Map<Integer, List<Integer>> assignment) {
            this.assignment = assignment;
        }

        /**
         * @return a Map with the list of replicas for each partition
         */
        Map<Integer, List<Integer>> assignment() {
            return assignment;
        }
    }

    /**
     * Partitions which require an assignment to be computed
     */
    public interface NewPartitions {

        /**
         * The name of the topic for these partitions
         */
        String topicName();

        /**
         * The list of partition ids
         */
        List<Integer> partitionIds();

        /**
         * The replication factor of the topic
         */
        short replicationFactor();

        /**
         * The configuration of the topic
         */
        Map<String, String> configs();
    }

}

...