MatthewAden commented on code in PR #16352: URL: https://github.com/apache/dolphinscheduler/pull/16352#discussion_r1749056484
########## 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: done -- 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]
