Skip to content

Commit a6da47e

Browse files
authored
Disable old client odp distributed execution (#393)
* add new field allowDistributeCapability * set lsId as INVALID_LS_ID for non-partitioned table
1 parent 16f9221 commit a6da47e

File tree

4 files changed

+30
-8
lines changed

4 files changed

+30
-8
lines changed

src/main/java/com/alipay/oceanbase/rpc/bolt/transport/ObTableConnection.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public class ObTableConnection {
5252
private AtomicBoolean isExpired = new AtomicBoolean(false);
5353
private LocalDateTime lastConnectionTime;
5454
private boolean loginWithConfigs = false;
55+
private boolean isOdpMode = false;
5556

5657
public static long ipToLong(String strIp) {
5758
String[] ip = strIp.split("\\.");
@@ -79,8 +80,9 @@ public void enableLoginWithConfigs() {
7980
/*
8081
* Ob table connection.
8182
*/
82-
public ObTableConnection(ObTable obTable) {
83+
public ObTableConnection(ObTable obTable, boolean isOdpMode) {
8384
this.obTable = obTable;
85+
this.isOdpMode = isOdpMode;
8486
}
8587

8688
/*
@@ -157,6 +159,7 @@ private void login() throws Exception {
157159
request.setTenantName(obTable.getTenantName());
158160
request.setUserName(obTable.getUserName());
159161
request.setDatabaseName(obTable.getDatabase());
162+
request.setAllowDistributeCapability(isAllowDistributeCapability());
160163
// When the caller doesn't provide any parameters, configsMap is empty.
161164
// In this case, we don't generate any JSON to avoid creating an empty object.
162165
if (loginWithConfigs && !obTable.getConfigs().isEmpty()) {
@@ -402,4 +405,11 @@ private String logMessage(String traceId, String methodName, String endpoint, lo
402405
return stringBuilder.toString();
403406
}
404407

408+
private boolean isAllowDistributeCapability() {
409+
if (isOdpMode) {
410+
return ObGlobal.OB_PROXY_VERSION >= ObGlobal.OB_PROXY_VERSION_4_3_6_0;
411+
} else {
412+
return true;
413+
}
414+
}
405415
}

src/main/java/com/alipay/oceanbase/rpc/location/LocationUtil.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1583,11 +1583,10 @@ private static ObPartitionEntry getPartitionLocationFromResultSet(TableEntry tab
15831583
long partitionId;
15841584
partitionId = rs.getLong("tablet_id");
15851585
long lsId = withLsId ? rs.getLong("ls_id") : INVALID_LS_ID;
1586-
if (!rs.wasNull()) {
1587-
tabletLsIdMap.put(partitionId, lsId);
1588-
} else {
1589-
tabletLsIdMap.put(partitionId, INVALID_LS_ID); // non-partitioned table
1586+
if (withLsId && rs.wasNull()) {
1587+
lsId = INVALID_LS_ID;
15901588
}
1589+
tabletLsIdMap.put(partitionId, lsId);
15911590
ObPartitionLocationInfo partitionLocationInfo = partitionEntry
15921591
.getPartitionInfo(partitionId);
15931592
ObPartitionLocation location = partitionLocationInfo.getPartitionLocation();

src/main/java/com/alipay/oceanbase/rpc/protocol/payload/impl/login/ObTableLoginRequest.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public int getPcode() {
5454
private String databaseName;
5555
private long ttlUs;
5656
private String configsStr;
57+
private boolean allowDistributeCapability;
5758

5859
/*
5960
* Ob table login request.
@@ -116,6 +117,9 @@ public byte[] encode() {
116117
idx += len;
117118
strbytes = Serialization.encodeVString(configsStr);
118119
System.arraycopy(strbytes, 0, bytes, idx, strbytes.length);
120+
idx += strbytes.length;
121+
System.arraycopy(Serialization.encodeI8(allowDistributeCapability ? (byte) 1 : (byte) 0), 0,
122+
bytes, idx, 1);
119123
return bytes;
120124
}
121125

@@ -168,7 +172,7 @@ public long getPayloadContentSize() {
168172
+ Serialization.getNeedBytes(userName) + Serialization.getNeedBytes(passSecret)
169173
+ Serialization.getNeedBytes(passScramble)
170174
+ Serialization.getNeedBytes(databaseName) + Serialization.getNeedBytes(ttlUs)
171-
+ Serialization.getNeedBytes(configsStr);
175+
+ Serialization.getNeedBytes(configsStr) + 1 /* allowDistributeCapability */;
172176
}
173177

174178
/*
@@ -318,6 +322,7 @@ public ObBytesString getPassSecret() {
318322
return passSecret;
319323
}
320324

325+
321326
/*
322327
* Set pass secret.
323328
*/
@@ -382,4 +387,12 @@ public void setConfigsStr(String configsStr) {
382387
this.configsStr = configsStr;
383388
}
384389

390+
public void setAllowDistributeCapability(boolean allowDistributeCapability) {
391+
this.allowDistributeCapability = allowDistributeCapability;
392+
}
393+
394+
public boolean getAllowDistributeCapability() {
395+
return this.allowDistributeCapability;
396+
}
397+
385398
}

src/main/java/com/alipay/oceanbase/rpc/table/ObTable.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,7 @@ public void init() throws Exception {
863863
// expand other connections (if needed) in the background
864864
connectionPool = new AtomicReference<ObTableConnection[]>();
865865
ObTableConnection[] curConnectionPool = new ObTableConnection[1];
866-
curConnectionPool[0] = new ObTableConnection(obTable);
866+
curConnectionPool[0] = new ObTableConnection(obTable, obTable.isOdpMode());
867867
curConnectionPool[0].enableLoginWithConfigs();
868868
curConnectionPool[0].init();
869869

@@ -912,7 +912,7 @@ private void checkAndExpandPool() {
912912
List<ObTableConnection> tmpConnections = new ArrayList<>();
913913
for (int i = 0; i < expandSize; ++i) {
914914
try {
915-
ObTableConnection tmpConnection = new ObTableConnection(obTable);
915+
ObTableConnection tmpConnection = new ObTableConnection(obTable, obTable.isOdpMode());
916916
tmpConnection.init();
917917
tmpConnections.add(tmpConnection);
918918
} catch (Exception e) {

0 commit comments

Comments
 (0)