-
Notifications
You must be signed in to change notification settings - Fork 1k
Pipe: implement external sources strategy and MQTT extractor #15275
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
Open
XNX02
wants to merge
24
commits into
apache:master
Choose a base branch
from
XNX02:mqtt-source
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,061
−40
Open
Changes from 16 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
f9225ae
set up
XNX02 6dc8c23
Merge branch 'master' of https://github.com/apache/iotdb into externa…
XNX02 ca62da7
update
XNX02 67f581b
Merge branch 'master' of https://github.com/apache/iotdb into externa…
XNX02 ded4261
update
XNX02 8ff357f
Merge branch 'master' of https://github.com/apache/iotdb into externa…
XNX02 57baeb2
update blancer
XNX02 eb01779
update
XNX02 3ef7238
mqtt source
XNX02 5c020da
update
XNX02 243a376
kafka source
XNX02 d61fd1a
mqtt
XNX02 ecea9a7
update
XNX02 9a82d86
add header
XNX02 a07e703
update
XNX02 3dd79d6
fix
XNX02 bf4a871
alter pipe & loadbalancer
XNX02 94a4ae2
Merge branch 'master' of https://github.com/apache/iotdb into mqtt-so…
XNX02 5da03d3
update
XNX02 caa3907
update
XNX02 ddbdf69
update
XNX02 ae41e9c
update balance logic
XNX02 7b7dc32
update
XNX02 10ef051
fix
XNX02 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 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 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 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
113 changes: 113 additions & 0 deletions
113
.../main/java/org/apache/iotdb/confignode/procedure/impl/pipe/util/ExternalLoadBalancer.java
This file contains 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,113 @@ | ||
/* | ||
* 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.procedure.impl.pipe.util; | ||
|
||
import org.apache.iotdb.common.rpc.thrift.TConsensusGroupId; | ||
import org.apache.iotdb.common.rpc.thrift.TConsensusGroupType; | ||
import org.apache.iotdb.commons.cluster.NodeStatus; | ||
import org.apache.iotdb.commons.pipe.agent.task.meta.PipeStaticMeta; | ||
import org.apache.iotdb.commons.pipe.config.constant.PipeExtractorConstant; | ||
import org.apache.iotdb.confignode.manager.ConfigManager; | ||
|
||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
public class ExternalLoadBalancer { | ||
private final ConfigManager configManager; | ||
|
||
public ExternalLoadBalancer(final ConfigManager configManager) { | ||
this.configManager = configManager; | ||
} | ||
|
||
/** | ||
* Distribute the number of source parallel tasks evenly over the sorted region group ids. | ||
* | ||
* @param parallelCount the number of parallel tasks from external source | ||
* @return a mapping from task index to leader node id | ||
*/ | ||
public Map<Integer, Integer> balance( | ||
int parallelCount, | ||
final Map<TConsensusGroupId, Integer> regionLeaderMap, | ||
PipeStaticMeta pipestaticMeta) { | ||
final Map<Integer, Integer> parallelAssignment = new HashMap<>(); | ||
|
||
// Check if the external extractor is single instance per node | ||
if (pipestaticMeta | ||
.getExtractorParameters() | ||
.getBooleanOrDefault( | ||
Arrays.asList( | ||
PipeExtractorConstant.EXTERNAL_EXTRACTOR_SINGLE_INSTANCE_PER_NODE_KEY, | ||
PipeExtractorConstant.EXTERNAL_SOURCE_SINGLE_INSTANCE_PER_NODE_KEY), | ||
PipeExtractorConstant.EXTERNAL_EXTRACTOR_SINGLE_INSTANCE_PER_NODE_DEFAULT_VALUE)) { | ||
final List<Integer> runningDataNodes = | ||
configManager.getLoadManager().filterDataNodeThroughStatus(NodeStatus.Running).stream() | ||
.sorted() | ||
.collect(Collectors.toList()); | ||
if (runningDataNodes.isEmpty()) { | ||
throw new RuntimeException("No available datanode to assign tasks"); | ||
} | ||
int numNodes = runningDataNodes.size(); | ||
for (int i = 1; i <= Math.min(numNodes, parallelCount); i++) { | ||
int datanodeId = runningDataNodes.get(i - 1); | ||
parallelAssignment.put(-i, datanodeId); | ||
} | ||
return parallelAssignment; | ||
} | ||
|
||
// Get sorted regionGroupIds | ||
final List<Integer> sortedRegionGroupIds = | ||
regionLeaderMap.entrySet().stream() | ||
.filter( | ||
t -> t.getKey().getType() == TConsensusGroupType.DataRegion && t.getValue() != -1) | ||
.map(t -> t.getKey().getId()) | ||
.sorted() | ||
.collect(Collectors.toList()); | ||
|
||
if (sortedRegionGroupIds.isEmpty()) { | ||
final List<Integer> runningDataNodes = | ||
configManager.getLoadManager().filterDataNodeThroughStatus(NodeStatus.Running).stream() | ||
.sorted() | ||
.collect(Collectors.toList()); | ||
if (runningDataNodes.isEmpty()) { | ||
throw new RuntimeException("No available datanode to assign tasks"); | ||
} | ||
int numNodes = runningDataNodes.size(); | ||
for (int i = 1; i <= parallelCount; i++) { | ||
int nodeIndex = (i - 1) % numNodes; | ||
int datanodeId = runningDataNodes.get(nodeIndex); | ||
parallelAssignment.put(-i, datanodeId); | ||
} | ||
} else { | ||
int numGroups = sortedRegionGroupIds.size(); | ||
for (int i = 1; i <= parallelCount; i++) { | ||
int groupIndex = (i - 1) % numGroups; | ||
int regionGroupId = sortedRegionGroupIds.get(groupIndex); | ||
int leaderNodeId = | ||
regionLeaderMap.get( | ||
new TConsensusGroupId(TConsensusGroupType.DataRegion, regionGroupId)); | ||
parallelAssignment.put(-i, leaderNodeId); | ||
} | ||
} | ||
return parallelAssignment; | ||
} | ||
} |
This file contains 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 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 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 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 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 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 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better rename to "taskId"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense, fixed it