jolshan commented on code in PR #13812: URL: https://github.com/apache/kafka/pull/13812#discussion_r1235651106
########## group-coordinator/src/main/java/org/apache/kafka/coordinator/group/GroupCoordinatorService.java: ########## @@ -0,0 +1,581 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.kafka.coordinator.group; + +import org.apache.kafka.common.TopicPartition; +import org.apache.kafka.common.config.TopicConfig; +import org.apache.kafka.common.errors.InvalidFetchSizeException; +import org.apache.kafka.common.errors.KafkaStorageException; +import org.apache.kafka.common.errors.NotEnoughReplicasException; +import org.apache.kafka.common.errors.NotLeaderOrFollowerException; +import org.apache.kafka.common.errors.RecordBatchTooLargeException; +import org.apache.kafka.common.errors.RecordTooLargeException; +import org.apache.kafka.common.errors.UnknownTopicOrPartitionException; +import org.apache.kafka.common.internals.Topic; +import org.apache.kafka.common.message.ConsumerGroupHeartbeatRequestData; +import org.apache.kafka.common.message.ConsumerGroupHeartbeatResponseData; +import org.apache.kafka.common.message.DeleteGroupsResponseData; +import org.apache.kafka.common.message.DescribeGroupsResponseData; +import org.apache.kafka.common.message.HeartbeatRequestData; +import org.apache.kafka.common.message.HeartbeatResponseData; +import org.apache.kafka.common.message.JoinGroupRequestData; +import org.apache.kafka.common.message.JoinGroupResponseData; +import org.apache.kafka.common.message.LeaveGroupRequestData; +import org.apache.kafka.common.message.LeaveGroupResponseData; +import org.apache.kafka.common.message.ListGroupsRequestData; +import org.apache.kafka.common.message.ListGroupsResponseData; +import org.apache.kafka.common.message.OffsetCommitRequestData; +import org.apache.kafka.common.message.OffsetCommitResponseData; +import org.apache.kafka.common.message.OffsetDeleteRequestData; +import org.apache.kafka.common.message.OffsetDeleteResponseData; +import org.apache.kafka.common.message.OffsetFetchRequestData; +import org.apache.kafka.common.message.OffsetFetchResponseData; +import org.apache.kafka.common.message.SyncGroupRequestData; +import org.apache.kafka.common.message.SyncGroupResponseData; +import org.apache.kafka.common.message.TxnOffsetCommitRequestData; +import org.apache.kafka.common.message.TxnOffsetCommitResponseData; +import org.apache.kafka.common.protocol.Errors; +import org.apache.kafka.common.requests.RequestContext; +import org.apache.kafka.common.requests.TransactionResult; +import org.apache.kafka.common.utils.BufferSupplier; +import org.apache.kafka.common.utils.LogContext; +import org.apache.kafka.common.utils.Utils; +import org.apache.kafka.coordinator.group.runtime.CoordinatorBuilderSupplier; +import org.apache.kafka.coordinator.group.runtime.CoordinatorEventProcessor; +import org.apache.kafka.coordinator.group.runtime.CoordinatorLoader; +import org.apache.kafka.coordinator.group.runtime.CoordinatorRuntime; +import org.apache.kafka.coordinator.group.runtime.MultiThreadedEventProcessor; +import org.apache.kafka.coordinator.group.runtime.PartitionWriter; +import org.apache.kafka.image.MetadataDelta; +import org.apache.kafka.image.MetadataImage; +import org.apache.kafka.server.record.BrokerCompressionType; +import org.apache.kafka.server.util.FutureUtils; +import org.slf4j.Logger; + +import java.util.List; +import java.util.OptionalInt; +import java.util.Properties; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.function.IntSupplier; + +/** + * The group coordinator service. + */ +public class GroupCoordinatorService implements GroupCoordinator { + + public static class Builder { + private final int nodeId; + private final GroupCoordinatorConfig config; + private PartitionWriter<Record> writer; + private CoordinatorLoader<Record> loader; + + public Builder( + int nodeId, + GroupCoordinatorConfig config + ) { + this.nodeId = nodeId; + this.config = config; + } + + public Builder withWriter(PartitionWriter<Record> writer) { + this.writer = writer; + return this; + } + + public Builder withLoader(CoordinatorLoader<Record> loader) { + this.loader = loader; + return this; + } + + public GroupCoordinatorService build() { + if (config == null) + throw new IllegalArgumentException("Config must be set."); + if (writer == null) + throw new IllegalArgumentException("Writer must be set."); + if (loader == null) + throw new IllegalArgumentException("Loader must be set."); + + String logPrefix = String.format("GroupCoordinator id=%d ", nodeId); + LogContext logContext = new LogContext(String.format("[%s ]", logPrefix)); + + CoordinatorBuilderSupplier<ReplicatedGroupCoordinator, Record> supplier = () -> + new ReplicatedGroupCoordinator.Builder(config); + + CoordinatorEventProcessor processor = new MultiThreadedEventProcessor( + logContext, + "group-coordinator-event-processor-", + config.numThreads + ); + + CoordinatorRuntime<ReplicatedGroupCoordinator, Record> runtime = + new CoordinatorRuntime.Builder<ReplicatedGroupCoordinator, Record>() + .withLogPrefix(logPrefix) + .withLogContext(logContext) + .withEventProcessor(processor) + .withPartitionWriter(writer) + .withLoader(loader) + .withCoordinatorBuilderSupplier(supplier) + .build(); + + return new GroupCoordinatorService( + logContext, + config, + runtime + ); + } + } + + /** + * The logger. + */ + private final Logger log; + + /** + * The group coordinator configurations. + */ + private final GroupCoordinatorConfig config; + + /** + * The coordinator runtime. + */ + private final CoordinatorRuntime<ReplicatedGroupCoordinator, Record> runtime; + + /** + * Boolean indicating whether the coordinator is active or not. + */ + private final AtomicBoolean isActive = new AtomicBoolean(false); + + /** + * The number of partitions of the __consumer_offsets topics. This is provided + * when the component is started. + */ + private volatile int numPartitions = -1; Review Comment: It should only be done manually via the tests right? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org