From ab6ce0ede59f0bbef29081ff684ae5864abaa708 Mon Sep 17 00:00:00 2001 From: JackShi148 Date: Thu, 8 May 2025 15:18:26 +0800 Subject: [PATCH] do not set odp ip and port dirty in diaster recovery --- .../oceanbase/rpc/location/model/OdpInfo.java | 4 +- .../alipay/oceanbase/rpc/table/ObTable.java | 38 +++++++++++++++---- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/alipay/oceanbase/rpc/location/model/OdpInfo.java b/src/main/java/com/alipay/oceanbase/rpc/location/model/OdpInfo.java index 6389d105..ec9a2fd7 100644 --- a/src/main/java/com/alipay/oceanbase/rpc/location/model/OdpInfo.java +++ b/src/main/java/com/alipay/oceanbase/rpc/location/model/OdpInfo.java @@ -48,11 +48,11 @@ public void buildOdpTable(String tenantName, String fullUserName, String passwor this.obTable = new ObTable.Builder(addr, port) // .setLoginInfo(tenantName, fullUserName, password, database, ObTableClientType.JAVA_TABLE_CLIENT) // - .setProperties(properties).setConfigs(tableConfigs).build(); + .setProperties(properties).setConfigs(tableConfigs).setIsOdpMode(true).build(); if (ObGlobal.isDistributedExecSupport() && runningMode == ObTableClient.RunningMode.HBASE) { // support distributed execute, login again this.obTable = new ObTable.Builder(addr, port) .setLoginInfo(tenantName, fullUserName, password, database, ObTableClientType.JAVA_HBASE_CLIENT) - .setProperties(properties).setConfigs(tableConfigs).build(); + .setProperties(properties).setConfigs(tableConfigs).setIsOdpMode(true).build(); } } diff --git a/src/main/java/com/alipay/oceanbase/rpc/table/ObTable.java b/src/main/java/com/alipay/oceanbase/rpc/table/ObTable.java index bcf306f3..e5426ae6 100644 --- a/src/main/java/com/alipay/oceanbase/rpc/table/ObTable.java +++ b/src/main/java/com/alipay/oceanbase/rpc/table/ObTable.java @@ -78,6 +78,7 @@ public class ObTable extends AbstractObTable implements Lifecycle { private ReentrantLock statusLock = new ReentrantLock(); private AtomicBoolean valid = new AtomicBoolean(true); + private boolean isOdpMode = false; // default as false /* * Init. @@ -413,7 +414,7 @@ public ObTableOperationResult execute(String tableName, ObTableOperationType typ public ObPayload execute(final ObPayload request) throws RemotingException, InterruptedException { - if (!isValid()) { + if (!isOdpMode && !isValid()) { log.debug("The server is not available, server address: " + ip + ":" + port); throw new ObTableServerConnectException("The server is not available, server address: " + ip + ":" + port); } @@ -424,10 +425,16 @@ public ObPayload execute(final ObPayload request) throws RemotingException, connection.checkStatus(); } catch (ConnectException ex) { // cannot connect to ob server, need refresh table location - setDirty(); + // do not set odp ip and port as dirty + if (!isOdpMode) { + setDirty(); + } throw new ObTableServerConnectException(ex); } catch (ObTableServerConnectException ex) { - setDirty(); + // do not set odp ip and port as dirty + if (!isOdpMode) { + setDirty(); + } throw ex; } catch (Exception ex) { throw new ObTableConnectionStatusException("check status failed, cause: " + ex.getMessage(), ex); @@ -478,7 +485,7 @@ public ObPayload executeWithConnection(final ObPayload request, AtomicReference connectionRef) throws RemotingException, InterruptedException { - if (!isValid()) { + if (!isOdpMode && !isValid()) { log.debug("The server is not available, server address: " + ip + ":" + port); throw new ObTableServerConnectException("The server is not available, server address: " + ip + ":" + port); } @@ -494,10 +501,16 @@ public ObPayload executeWithConnection(final ObPayload request, connection.checkStatus(); } catch (ConnectException ex) { // Cannot connect to ob server, need refresh table location - setDirty(); + // do not set odp ip and port as dirty + if (!isOdpMode) { + setDirty(); + } throw new ObTableServerConnectException(ex); } catch (ObTableServerConnectException ex) { - setDirty(); + // do not set odp ip and port as dirty + if (!isOdpMode) { + setDirty(); + } throw ex; } catch (Exception ex) { throw new ObTableConnectionStatusException("check status failed, cause: " + ex.getMessage(), ex); @@ -621,6 +634,10 @@ public void setDatabase(String database) { this.database = database; } + public void setIsOdpMode(boolean isOdpMode) { + this.isOdpMode = isOdpMode; + } + public void setConfigs(Map configs) { this.configs = configs; } @@ -705,11 +722,12 @@ public static class Builder { private String userName; private String password; private String database; - ObTableClientType clientType; + ObTableClientType clientType; private Properties properties = new Properties(); private Map tableConfigs = new HashMap<>(); + private boolean isOdpMode = false; // default as false /* * Builder. @@ -753,6 +771,11 @@ public Builder setConfigs(Map tableConfigs) { return this; } + public Builder setIsOdpMode(boolean isOdpMode) { + this.isOdpMode = isOdpMode; + return this; + } + /* * Build. */ @@ -767,6 +790,7 @@ public ObTable build() throws Exception { obTable.setProperties(properties); obTable.setConfigs(tableConfigs); obTable.setClientType(clientType); + obTable.setIsOdpMode(isOdpMode); obTable.init();