ruanwenjun commented on code in PR #16352: URL: https://github.com/apache/dolphinscheduler/pull/16352#discussion_r1721277554
########## dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-raft/src/main/java/org/apache/dolphinscheduler/plugin/registry/raft/RaftRegistryProperties.java: ########## @@ -0,0 +1,51 @@ +/* + * 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.dolphinscheduler.plugin.registry.raft; + +import java.time.Duration; + +import lombok.Data; + +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +@Data +@Configuration +@ConditionalOnProperty(prefix = "registry", name = "type", havingValue = "raft") +@ConfigurationProperties(prefix = "registry") +public class RaftRegistryProperties { + + private String clusterName; + private String serverAddressList; + private String serverAddress; + private int serverPort; + private String logStorageDir; + private Duration distributedLockTimeout = Duration.ofSeconds(3); + private Duration distributedLockRetryInterval = Duration.ofSeconds(5); + private String module = "master"; + private Duration listenerCheckInterval = Duration.ofSeconds(3); + private int cliMaxRetries = 3; + private Duration cliTimeout = Duration.ofSeconds(5); + private Duration refreshLeaderTimeout = Duration.ofSeconds(2); + private Duration connectStateCheckInterval = Duration.ofSeconds(2); + private Duration heartBeatTimeOut = Duration.ofSeconds(20); + private int subscribeListenerThreadPoolSize = 1; + private int connectionListenerThreadPoolSize = 1; Review Comment: Why we need to exposed so many configurations to user. Is there any doc related to these config? ########## dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-raft/src/main/java/org/apache/dolphinscheduler/plugin/registry/raft/RaftRegistryAutoConfiguration.java: ########## @@ -0,0 +1,72 @@ +/* + * 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.dolphinscheduler.plugin.registry.raft; + +import org.apache.dolphinscheduler.plugin.registry.raft.server.RaftRegistryServer; + +import lombok.extern.slf4j.Slf4j; + +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.DependsOn; + +@Slf4j +@Configuration(proxyBeanMethods = false) +@ConditionalOnProperty(prefix = "registry", name = "type", havingValue = "raft") +@EnableConfigurationProperties(RaftRegistryProperties.class) +public class RaftRegistryAutoConfiguration { + + public RaftRegistryAutoConfiguration() { + log.info("Load RaftRegistryAutoConfiguration"); + } + + @Bean + @ConditionalOnProperty(prefix = "registry", name = "module", havingValue = "master") + public RaftRegistryServer raftRegistryServer(RaftRegistryProperties raftRegistryProperties) { + RaftRegistryServer raftRegistryServer = new RaftRegistryServer(raftRegistryProperties); + raftRegistryServer.start(); + return raftRegistryServer; + } + + @Bean + @DependsOn("raftRegistryServer") + @ConditionalOnProperty(prefix = "registry", name = "module", havingValue = "master") + public RaftRegistry masterRaftRegistryClient(RaftRegistryProperties raftRegistryProperties) { + RaftRegistry raftRegistry = new RaftRegistry(raftRegistryProperties); + raftRegistry.start(); + return raftRegistry; + } + + @Bean + @ConditionalOnProperty(prefix = "registry", name = "module", havingValue = "worker") + public RaftRegistry workerRaftRegistryClient(RaftRegistryProperties raftRegistryProperties) { + RaftRegistry raftRegistry = new RaftRegistry(raftRegistryProperties); + raftRegistry.start(); + return raftRegistry; + } + + @Bean + @ConditionalOnProperty(prefix = "registry", name = "module", havingValue = "api") + public RaftRegistry apiRaftRegistryClient(RaftRegistryProperties raftRegistryProperties) { + RaftRegistry raftRegistry = new RaftRegistry(raftRegistryProperties); + raftRegistry.start(); + return raftRegistry; + } Review Comment: The plugin shouldn't care about the server type. ########## dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-raft/src/main/java/org/apache/dolphinscheduler/plugin/registry/raft/client/RaftRegistryClient.java: ########## @@ -0,0 +1,221 @@ +/* + * 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.dolphinscheduler.plugin.registry.raft.client; + +import static com.alipay.sofa.jraft.util.BytesUtil.readUtf8; +import static com.alipay.sofa.jraft.util.BytesUtil.writeUtf8; + +import org.apache.dolphinscheduler.common.constants.Constants; +import org.apache.dolphinscheduler.plugin.registry.raft.RaftRegistryProperties; +import org.apache.dolphinscheduler.plugin.registry.raft.manage.IRaftConnectionStateManager; +import org.apache.dolphinscheduler.plugin.registry.raft.manage.IRaftLockManager; +import org.apache.dolphinscheduler.plugin.registry.raft.manage.IRaftSubscribeDataManager; +import org.apache.dolphinscheduler.plugin.registry.raft.manage.RaftConnectionStateManager; +import org.apache.dolphinscheduler.plugin.registry.raft.manage.RaftLockManager; +import org.apache.dolphinscheduler.plugin.registry.raft.manage.RaftSubscribeDataManager; +import org.apache.dolphinscheduler.plugin.registry.raft.model.NodeType; +import org.apache.dolphinscheduler.registry.api.ConnectionListener; +import org.apache.dolphinscheduler.registry.api.ConnectionState; +import org.apache.dolphinscheduler.registry.api.RegistryException; +import org.apache.dolphinscheduler.registry.api.SubscribeListener; +import org.apache.dolphinscheduler.registry.api.enums.RegistryNodeType; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import lombok.extern.slf4j.Slf4j; + +import com.alipay.sofa.jraft.rhea.client.DefaultRheaKVStore; +import com.alipay.sofa.jraft.rhea.client.RheaKVStore; +import com.alipay.sofa.jraft.rhea.options.PlacementDriverOptions; +import com.alipay.sofa.jraft.rhea.options.RegionRouteTableOptions; +import com.alipay.sofa.jraft.rhea.options.RheaKVStoreOptions; +import com.alipay.sofa.jraft.rhea.options.configured.MultiRegionRouteTableOptionsConfigured; +import com.alipay.sofa.jraft.rhea.options.configured.PlacementDriverOptionsConfigured; +import com.alipay.sofa.jraft.rhea.options.configured.RheaKVStoreOptionsConfigured; +import com.alipay.sofa.jraft.rhea.storage.KVEntry; + +@Slf4j +public class RaftRegistryClient implements IRaftRegistryClient { + + private final RheaKVStore rheaKvStore; + private final RaftRegistryProperties raftRegistryProperties; + private final IRaftConnectionStateManager raftConnectionStateManager; + private final IRaftSubscribeDataManager raftSubscribeDataManager; + private final IRaftLockManager raftLockManager; + private volatile boolean started; + private static final String MASTER_MODULE = "master"; + public RaftRegistryClient(RaftRegistryProperties raftRegistryProperties) { + this.raftRegistryProperties = raftRegistryProperties; + this.rheaKvStore = new DefaultRheaKVStore(); + this.raftConnectionStateManager = new RaftConnectionStateManager(raftRegistryProperties); + this.raftSubscribeDataManager = new RaftSubscribeDataManager(raftRegistryProperties, rheaKvStore); + this.raftLockManager = new RaftLockManager(rheaKvStore, raftRegistryProperties); + + initRheakv(); + } + + private void initRheakv() { + final List<RegionRouteTableOptions> regionRouteTableOptionsList = MultiRegionRouteTableOptionsConfigured + .newConfigured() + .withInitialServerList(-1L /* default id */, raftRegistryProperties.getServerAddressList()) + .config(); + final PlacementDriverOptions pdOpts = PlacementDriverOptionsConfigured.newConfigured() + .withFake(true) + .withRegionRouteTableOptionsList(regionRouteTableOptionsList) + .config(); + final RheaKVStoreOptions opts = RheaKVStoreOptionsConfigured.newConfigured() // + .withClusterName(raftRegistryProperties.getClusterName()) // + .withPlacementDriverOptions(pdOpts) // + .config(); + this.rheaKvStore.init(opts); + } + + @Override + public void start() { + if (this.started) { + log.info("RaftRegistryClient is already started"); + return; + } + log.info("starting raft client registry..."); + if (raftRegistryProperties.getModule().equals(MASTER_MODULE)) { + raftSubscribeDataManager.start(); + } Review Comment: Why only master start the `raftSubscribeDataManager`, this is strange. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
