OneSizeFitsQuorum commented on code in PR #16604:
URL: https://github.com/apache/iotdb/pull/16604#discussion_r2438055725
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/AbstractFragmentParallelPlanner.java:
##########
@@ -133,13 +132,29 @@ protected TDataNodeLocation
selectTargetDataNode(TRegionReplicaSet regionReplica
if (regionReplicaSet.getDataNodeLocationsSize() !=
availableDataNodes.size()) {
LOGGER.info("available replicas: {}", availableDataNodes);
}
+ int targetIndex = getTargetIndex(availableDataNodes);
+ return availableDataNodes.get(targetIndex);
+ }
+
+ private int getTargetIndex(List<TDataNodeLocation> availableDataNodes) {
int targetIndex;
- if (!selectRandomDataNode || queryContext.getSession() == null) {
+ if (ReadConsistencyLevel.STRONG == this.readConsistencyLevel
+ || queryContext.getSession() == null) {
targetIndex = 0;
- } else {
+ } else if (ReadConsistencyLevel.WEAK == this.readConsistencyLevel) {
targetIndex = (int) (queryContext.getSession().getSessionId() %
availableDataNodes.size());
+ } else if (ReadConsistencyLevel.FOLLOWER_READ ==
this.readConsistencyLevel) {
+ // The first available data node is always leader which is guaranteed by
ConfigNode and
+ // PartitionFetcher in DataNode
+ // We only need to randomly choose any one from [1,
availableDataNodes.size()).
+ // SessionId is a unchanged long value for each connection, so we can
use that as random seed
+ targetIndex =
Review Comment:
When we only have one replica, maybe we should return 0 even user set
consistency_level to follower_read?, return a number >= 1 will cause an error?
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/AbstractFragmentParallelPlanner.java:
##########
@@ -133,13 +132,29 @@ protected TDataNodeLocation
selectTargetDataNode(TRegionReplicaSet regionReplica
if (regionReplicaSet.getDataNodeLocationsSize() !=
availableDataNodes.size()) {
LOGGER.info("available replicas: {}", availableDataNodes);
}
+ int targetIndex = getTargetIndex(availableDataNodes);
+ return availableDataNodes.get(targetIndex);
+ }
+
+ private int getTargetIndex(List<TDataNodeLocation> availableDataNodes) {
int targetIndex;
- if (!selectRandomDataNode || queryContext.getSession() == null) {
+ if (ReadConsistencyLevel.STRONG == this.readConsistencyLevel
+ || queryContext.getSession() == null) {
targetIndex = 0;
- } else {
+ } else if (ReadConsistencyLevel.WEAK == this.readConsistencyLevel) {
targetIndex = (int) (queryContext.getSession().getSessionId() %
availableDataNodes.size());
+ } else if (ReadConsistencyLevel.FOLLOWER_READ ==
this.readConsistencyLevel) {
+ // The first available data node is always leader which is guaranteed by
ConfigNode and
+ // PartitionFetcher in DataNode
+ // We only need to randomly choose any one from [1,
availableDataNodes.size()).
+ // SessionId is a unchanged long value for each connection, so we can
use that as random seed
+ targetIndex =
Review Comment:
When we only have one replica, maybe we should return 0 even user set
consistency_level to follower_read, return a number >= 1 will cause an error?
--
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]