2121import com .alipay .oceanbase .rpc .bolt .protocol .ObTablePacketCode ;
2222import com .alipay .oceanbase .rpc .exception .*;
2323import com .alipay .oceanbase .rpc .protocol .packet .ObCompressType ;
24- import com .alipay .oceanbase .rpc .protocol .payload .AbstractPayload ;
25- import com .alipay .oceanbase .rpc .protocol .payload .Credentialable ;
26- import com .alipay .oceanbase .rpc .protocol .payload .ObPayload ;
27- import com .alipay .oceanbase .rpc .protocol .payload .ObRpcResultCode ;
24+ import com .alipay .oceanbase .rpc .protocol .payload .*;
2825import com .alipay .oceanbase .rpc .protocol .payload .impl .login .ObTableLoginRequest ;
2926import com .alipay .oceanbase .rpc .util .ObPureCrc32C ;
3027import com .alipay .oceanbase .rpc .util .TableClientLoggerFactory ;
@@ -108,14 +105,6 @@ public ObPayload invokeSync(final ObTableConnection conn, final ObPayload reques
108105 throw new FeatureNotSupportedException (errMessage );
109106 }
110107 ByteBuf buf = response .getPacketContentBuf ();
111- // If response indicates the request is routed to wrong server, we should refresh the routing meta.
112- if (response .getHeader ().isRoutingWrong ()) {
113- String errMessage = TraceUtil .formatTraceMessage (conn , request ,
114- "routed to the wrong server: " + response .getMessage ());
115- logger .warn (errMessage );
116- throw new ObTableRoutingWrongException (errMessage );
117- }
118-
119108 // verify checksum
120109 long expected_checksum = response .getHeader ().getChecksum ();
121110 byte [] content = new byte [buf .readableBytes ()];
@@ -132,7 +121,17 @@ public ObPayload invokeSync(final ObTableConnection conn, final ObPayload reques
132121 // decode ResultCode for response packet
133122 ObRpcResultCode resultCode = new ObRpcResultCode ();
134123 resultCode .decode (buf );
135-
124+ // If response indicates the request is routed to wrong server, we should refresh the routing meta.
125+ if (response .getHeader ().isRoutingWrong ()) {
126+ String errMessage = TraceUtil .formatTraceMessage (conn , request ,
127+ "routed to the wrong server: " + response .getMessage ());
128+ logger .warn (errMessage );
129+ if (needFetchAll (resultCode .getRcode ())) {
130+ throw new ObTableRoutingWrongException (errMessage );
131+ } else {
132+ throw new ObTableMasterChangeException (errMessage );
133+ }
134+ }
136135 if (resultCode .getRcode () != 0 ) {
137136 ExceptionUtil .throwObTableException (conn .getObTable ().getIp (), conn .getObTable ()
138137 .getPort (), response .getHeader ().getTraceId1 (), response .getHeader ()
@@ -173,4 +172,11 @@ protected InvokeFuture createInvokeFuture(Connection conn, RemotingCommand reque
173172 return new ObClientFuture (request .getId ());
174173 }
175174
175+ private boolean needFetchAll (int errorCode ) {
176+ return errorCode == ResultCodes .OB_PARTITION_NOT_EXIST .errorCode
177+ || errorCode == ResultCodes .OB_INVALID_PARTITION .errorCode
178+ || errorCode == ResultCodes .OB_UNKNOWN_PARTITION .errorCode
179+ || errorCode == ResultCodes .OB_PARTITION_NOT_MATCH .errorCode
180+ || errorCode == ResultCodes .OB_TABLET_NOT_EXIST .errorCode ;
181+ }
176182}
0 commit comments