ControllerResult<List<CreatePartitionsTopicResult>> createPartitions(
        ControllerRequestContext context,
        List<CreatePartitionsTopic> topics
    ) {
        List<ApiMessageAndVersion> records = BoundedList.newArrayBacked(MAX_RECORDS_PER_USER_OP);
        List<CreatePartitionsTopicResult> results = BoundedList.newArrayBacked(MAX_RECORDS_PER_USER_OP);

        // AutoMQ inject start
        checkPartitionQuota(topics, results);
        if (!results.isEmpty()) {
            return ControllerResult.of(records, results);
        }
        // AutoMQ inject end

        for (CreatePartitionsTopic topic : topics) {
            ApiError apiError = ApiError.NONE;
            try {
                createPartitions(context, topic, records);
            } catch (ApiException e) {
                apiError = ApiError.fromThrowable(e);
            } catch (Exception e) {
                log.error("Unexpected createPartitions error for {}", topic, e);
                apiError = ApiError.fromThrowable(e);
            }
            results.add(new CreatePartitionsTopicResult().
                setName(topic.name()).
                setErrorCode(apiError.error().code()).
                setErrorMessage(apiError.message()));
        }
        return ControllerResult.atomicOf(records, results);
    }
Attempt to elect a preferred leader for all topic partitions which have a leader that is not the preferred replica.

The response() method in the return object is true if this method returned without electing all possible preferred replicas.
The quorum controller should reschedule this operation immediately if it is true.

@return All of the election records and if there may be more available preferred replicas to elect as leader
metadata/src/main/java/org/apache/kafka/controller/ReplicationControlManager.java