ijuma commented on code in PR #12837: URL: https://github.com/apache/kafka/pull/12837#discussion_r1037363599
########## core/src/main/scala/kafka/server/JointServer.scala: ########## @@ -0,0 +1,246 @@ +/** + * 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 kafka.server + +import kafka.raft.KafkaRaftManager +import kafka.server.KafkaRaftServer.{BrokerRole, ControllerRole} +import kafka.server.metadata.BrokerServerMetrics +import kafka.utils.{CoreUtils, Logging} +import org.apache.kafka.common.metrics.Metrics +import org.apache.kafka.common.utils.{LogContext, Time} +import org.apache.kafka.controller.QuorumControllerMetrics +import org.apache.kafka.metadata.MetadataRecordSerde +import org.apache.kafka.raft.RaftConfig.AddressSpec +import org.apache.kafka.server.common.ApiMessageAndVersion +import org.apache.kafka.server.fault.{FaultHandler, LoggingFaultHandler, ProcessExitingFaultHandler} +import org.apache.kafka.server.metrics.KafkaYammerMetrics + +import java.util +import java.util.concurrent.CompletableFuture +import java.util.concurrent.atomic.AtomicBoolean + + +/** + * Creates a fault handler. + */ +trait FaultHandlerFactory { + def build( + name: String, + fatal: Boolean, + action: Runnable + ): FaultHandler +} + +/** + * The standard FaultHandlerFactory which is used when we're not in a junit test. + */ +class StandardFaultHandlerFactory extends FaultHandlerFactory { + override def build( + name: String, + fatal: Boolean, + action: Runnable + ): FaultHandler = { + if (fatal) { + new ProcessExitingFaultHandler(action) + } else { + new LoggingFaultHandler(name, action) + } + } +} + +/** + * The JointServer manages the components which are shared between the BrokerServer and + * ControllerServer. These shared components include the Raft manager, snapshot generator, + * and metadata loader. A KRaft server running in combined mode as both a broker and a controller + * will still contain only a single JointServer instance. + * + * The JointServer will be started as soon as either the broker or the controller needs it, + * via the appropriate function (startForBroker or startForController). Similarly, it will be + * stopped as soon as neither the broker nor the controller need it, via stopForBroker or + * stopForController. One way of thinking about this is that both the broker and the controller + * could hold a "reference" to this class, and we don't truly stop it until both have dropped + * their reference. We opted to use two booleans here rather than a reference count in order to + * make debugging easier and reduce the chance of resource leaks. + */ +class JointServer( Review Comment: Would `SharedServer` be a better name? -- 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