-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Implement Cluster ID #11702
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
OneSizeFitsQuorum
merged 15 commits into
apache:master
from
liyuheng55555:Working/clusterID
Dec 15, 2023
Merged
Implement Cluster ID #11702
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
33bbd05
implemented, but follower won't log, which is unexpected
liyuheng55555 3bb5708
UpdateClusterIdPlan
liyuheng55555 19e3e33
aaaaaaaa
liyuheng55555 86c80c8
cn rpc
liyuheng55555 b33d581
working on show clusterid
liyuheng55555 908f509
working on show clusterId, but seems not necessary
liyuheng55555 bb666c3
working on show clusterId, but seems not necessary
liyuheng55555 bdffc15
show clusterId done
liyuheng55555 e4695fe
revert
liyuheng55555 e7eb43e
remove useless code
liyuheng55555 ae6929e
small problems
liyuheng55555 7053e1d
add IT
liyuheng55555 9a66fa9
as Teacher Chen suggested
liyuheng55555 2d6ea16
as Teacher Chen suggested
liyuheng55555 3f7d7cb
as Secretary Tan mentioned
liyuheng55555 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
...ration-test/src/test/java/org/apache/iotdb/confignode/it/cluster/IoTDBClusterStartIT.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| /* | ||
| * 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.iotdb.confignode.it.cluster; | ||
|
|
||
| import org.apache.iotdb.commons.client.exception.ClientManagerException; | ||
| import org.apache.iotdb.commons.client.sync.SyncConfigNodeIServiceClient; | ||
| import org.apache.iotdb.confignode.rpc.thrift.TGetClusterIdResp; | ||
| import org.apache.iotdb.it.env.EnvFactory; | ||
| import org.apache.iotdb.it.framework.IoTDBTestRunner; | ||
| import org.apache.iotdb.itbase.category.ClusterIT; | ||
| import org.apache.iotdb.rpc.TSStatusCode; | ||
|
|
||
| import org.apache.thrift.TException; | ||
| import org.junit.After; | ||
| import org.junit.Assert; | ||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
| import org.junit.experimental.categories.Category; | ||
| import org.junit.runner.RunWith; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.concurrent.TimeUnit; | ||
|
|
||
| import static org.apache.iotdb.consensus.ConsensusFactory.RATIS_CONSENSUS; | ||
|
|
||
| @RunWith(IoTDBTestRunner.class) | ||
| @Category({ClusterIT.class}) | ||
| public class IoTDBClusterStartIT { | ||
| private static final Logger logger = LoggerFactory.getLogger(IoTDBClusterStartIT.class); | ||
|
|
||
| private static final int testConfigNodeNum = 3, testDataNodeNum = 0; | ||
|
|
||
| @Before | ||
| public void setUp() { | ||
| EnvFactory.getEnv() | ||
| .getConfig() | ||
| .getCommonConfig() | ||
| .setConfigNodeConsensusProtocolClass(RATIS_CONSENSUS) | ||
| .setSchemaRegionConsensusProtocolClass(RATIS_CONSENSUS) | ||
| .setDataRegionConsensusProtocolClass(RATIS_CONSENSUS); | ||
|
|
||
| EnvFactory.getEnv().initClusterEnvironment(testConfigNodeNum, testDataNodeNum); | ||
| } | ||
|
|
||
| @After | ||
| public void tearDown() { | ||
| EnvFactory.getEnv().cleanClusterEnvironment(); | ||
| } | ||
|
|
||
| @Test | ||
| public void clusterIdTest() throws ClientManagerException, IOException, InterruptedException { | ||
| final long maxTestTime = TimeUnit.SECONDS.toMillis(30); | ||
| final long testInterval = TimeUnit.SECONDS.toMillis(1); | ||
| try (SyncConfigNodeIServiceClient client = | ||
| (SyncConfigNodeIServiceClient) EnvFactory.getEnv().getLeaderConfigNodeConnection()) { | ||
| long startTime = System.currentTimeMillis(); | ||
| while (System.currentTimeMillis() - startTime < maxTestTime) { | ||
| try { | ||
| TGetClusterIdResp resp = client.getClusterId(); | ||
| if (TSStatusCode.SUCCESS_STATUS.getStatusCode() == resp.getStatus().getCode()) { | ||
| Assert.assertNotNull(resp.getClusterId()); | ||
| Assert.assertNotEquals("", resp.getClusterId()); | ||
| return; | ||
| } | ||
| } catch (TException e) { | ||
| logger.error("TException:", e); | ||
| } | ||
| Thread.sleep(testInterval); | ||
| } | ||
| String errorMessage = String.format("Cluster ID failed to generate in %d ms.", maxTestTime); | ||
| Assert.fail(errorMessage); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,6 +57,7 @@ keyWords | |
| | CHILD | ||
| | CLEAR | ||
| | CLUSTER | ||
| | CLUSTERID | ||
| | CONCAT | ||
| | CONDITION | ||
| | CONFIGNODES | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -141,6 +141,10 @@ CLUSTER | |
| : C L U S T E R | ||
| ; | ||
|
|
||
| CLUSTERID | ||
| : C L U S T E R I D | ||
| ; | ||
|
|
||
| CONCAT | ||
| : C O N C A T | ||
| ; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
...a/org/apache/iotdb/confignode/consensus/request/write/confignode/UpdateClusterIdPlan.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| /* | ||
| * 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.iotdb.confignode.consensus.request.write.confignode; | ||
|
|
||
| import org.apache.iotdb.confignode.consensus.request.ConfigPhysicalPlan; | ||
| import org.apache.iotdb.confignode.consensus.request.ConfigPhysicalPlanType; | ||
| import org.apache.iotdb.tsfile.utils.ReadWriteIOUtils; | ||
|
|
||
| import java.io.DataOutputStream; | ||
| import java.io.IOException; | ||
| import java.nio.ByteBuffer; | ||
| import java.util.Objects; | ||
|
|
||
| public class UpdateClusterIdPlan extends ConfigPhysicalPlan { | ||
liyuheng55555 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| private String clusterId; | ||
|
|
||
| public UpdateClusterIdPlan() { | ||
| super(ConfigPhysicalPlanType.UpdateClusterId); | ||
| } | ||
|
|
||
| public UpdateClusterIdPlan(String clusterId) { | ||
| this(); | ||
| this.clusterId = clusterId; | ||
| } | ||
|
|
||
| public String getClusterId() { | ||
| return this.clusterId; | ||
| } | ||
|
|
||
| @Override | ||
| protected void serializeImpl(DataOutputStream stream) throws IOException { | ||
| ReadWriteIOUtils.write(getType().getPlanType(), stream); | ||
| ReadWriteIOUtils.write(clusterId, stream); | ||
| } | ||
|
|
||
| @Override | ||
| protected void deserializeImpl(ByteBuffer buffer) throws IOException { | ||
| clusterId = ReadWriteIOUtils.readString(buffer); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) { | ||
| return true; | ||
| } | ||
| if (o == null || getClass() != o.getClass()) { | ||
| return false; | ||
| } | ||
| if (!getType().equals(((UpdateClusterIdPlan) o).getType())) { | ||
| return false; | ||
| } | ||
| return Objects.equals(clusterId, ((UpdateClusterIdPlan) o).clusterId); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(clusterId); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/ClusterManager.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| /* | ||
| * 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.iotdb.confignode.manager; | ||
|
|
||
| import org.apache.iotdb.confignode.consensus.request.write.confignode.UpdateClusterIdPlan; | ||
| import org.apache.iotdb.confignode.persistence.ClusterInfo; | ||
| import org.apache.iotdb.consensus.exception.ConsensusException; | ||
|
|
||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import java.util.UUID; | ||
|
|
||
| public class ClusterManager { | ||
|
|
||
| private static final Logger LOGGER = LoggerFactory.getLogger(ClusterManager.class); | ||
|
|
||
| private final IManager configManager; | ||
| private final ClusterInfo clusterInfo; | ||
|
|
||
| private static final String CONSENSUS_WRITE_ERROR = | ||
| "Failed in the write API executing the consensus layer due to: "; | ||
|
|
||
| public ClusterManager(IManager configManager, ClusterInfo clusterInfo) { | ||
| this.configManager = configManager; | ||
| this.clusterInfo = clusterInfo; | ||
| } | ||
|
|
||
| public void checkClusterId() { | ||
| if (clusterInfo.getClusterId() != null) { | ||
| LOGGER.info("clusterID: {}", clusterInfo.getClusterId()); | ||
| return; | ||
| } | ||
| generateClusterId(); | ||
| } | ||
|
|
||
| public String getClusterId() { | ||
| return clusterInfo.getClusterId(); | ||
| } | ||
|
|
||
| private void generateClusterId() { | ||
| String clusterId = String.valueOf(UUID.randomUUID()); | ||
| UpdateClusterIdPlan updateClusterIdPlan = new UpdateClusterIdPlan(clusterId); | ||
| try { | ||
| configManager.getConsensusManager().write(updateClusterIdPlan); | ||
| } catch (ConsensusException e) { | ||
| LOGGER.warn(CONSENSUS_WRITE_ERROR, e); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.