File tree Expand file tree Collapse file tree 4 files changed +266
-147
lines changed
main/java/com/alipay/oceanbase/rpc
test/java/com/alipay/oceanbase/rpc Expand file tree Collapse file tree 4 files changed +266
-147
lines changed Original file line number Diff line number Diff line change @@ -2754,15 +2754,15 @@ public ObTableClientType getClientType(RunningMode runningMode) {
27542754 }
27552755 }
27562756
2757- public void setReadConsistency (ObReadConsistency readConsistency ) throws IllegalArgumentException {
2757+ public void setReadConsistency (ObReadConsistency readConsistency ) {
27582758 tableRoute .setReadConsistency (readConsistency );
27592759 }
27602760
27612761 public String getReadConsistency () {
27622762 return tableRoute .getReadConsistency ().name ();
27632763 }
27642764
2765- public void setRoutePolicy (ObRoutePolicy policy ) throws IllegalArgumentException {
2765+ public void setRoutePolicy (ObRoutePolicy policy ) {
27662766 tableRoute .setRoutePolicy (policy );
27672767 }
27682768
Original file line number Diff line number Diff line change @@ -158,7 +158,7 @@ public ObReadConsistency getReadConsistency() {
158158 * Set read consistency level.
159159 * @param readConsistency read consistency level
160160 */
161- public void setReadConsistency (ObReadConsistency readConsistency ) throws IllegalArgumentException {
161+ public void setReadConsistency (ObReadConsistency readConsistency ) {
162162 this .consistencyLevel = readConsistency ;
163163 }
164164
Original file line number Diff line number Diff line change @@ -104,26 +104,38 @@ private ReplicaLocation getReadReplicaNoLdc(ObRoutePolicy routePolicy) {
104104
105105 private ReplicaLocation getReadReplicaByRoutePolicy (ObRoutePolicy routePolicy )
106106 throws IllegalArgumentException {
107+ // 路由策略优先:FOLLOWER_FIRST 优先选择 follower,FOLLOWER_ONLY 只能选择 follower
108+ // 在满足路由策略的前提下,按就近原则选择(同机房 -> 同 region -> 其他 region)
109+
110+ // 优先在同机房找 follower
107111 for (ReplicaLocation r : sameIdc ) {
108- if (r .isValid ()) {
112+ if (r .isValid () && ! r . isLeader () ) {
109113 return r ;
110114 }
111115 }
116+
117+ // 如果同机房没有 follower,在同 region 找 follower
112118 for (ReplicaLocation r : sameRegion ) {
113- if (r .isValid ()) {
119+ if (r .isValid () && ! r . isLeader () ) {
114120 return r ;
115121 }
116122 }
123+
124+ // 如果同 region 没有 follower,在其他 region 找 follower
117125 for (ReplicaLocation r : otherRegion ) {
118- if (r .isValid ()) {
126+ if (r .isValid () && ! r . isLeader () ) {
119127 return r ;
120128 }
121129 }
122-
130+
131+ // 如果都没有找到 follower
123132 if (routePolicy == ObRoutePolicy .FOLLOWER_ONLY ) {
133+ // FOLLOWER_ONLY 必须选择 follower,没有就抛出异常
124134 throw new IllegalArgumentException ("No follower replica found for route policy: "
125- + routePolicy );
135+ + routePolicy );
126136 }
137+
138+ // 如果都没有找到,返回 leader(兜底)
127139 return leader ;
128140 }
129141
You can’t perform that action at this time.
0 commit comments