Skip to content

Commit 16a16b9

Browse files
authored
use mysql 5.x driver first and fix some exceptions (#380)
1 parent d8b4634 commit 16a16b9

File tree

2 files changed

+13
-48
lines changed

2 files changed

+13
-48
lines changed

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -335,21 +335,21 @@ public static Connection getMetaRefreshConnection(String url, ObUserAuth sysUA)
335335
}
336336

337337
private static void loadJdbcDriver() {
338+
try {
339+
Class.forName("com.mysql.jdbc.Driver");
340+
} catch (ClassNotFoundException e) {
341+
RUNTIME.error(LCD.convert("01-00006"), e.getMessage(), e);
342+
throw new ObTableEntryRefreshException(format("fail to find jdbc driver, errMsg=%s",
343+
e.getMessage()), e);
344+
}
345+
338346
try {
339347
Class.forName("com.mysql.cj.jdbc.Driver");
340348
return;
341349
} catch (ClassNotFoundException ignored) {
342350
RUNTIME.debug("Class 'com.mysql.cj.jdbc.Driver' not found, "
343351
+ "try to load legacy driver class 'com.mysql.jdbc.Driver'");
344352
}
345-
346-
try {
347-
Class.forName("com.mysql.jdbc.Driver");
348-
} catch (ClassNotFoundException e) {
349-
RUNTIME.error(LCD.convert("01-00006"), e.getMessage(), e);
350-
throw new ObTableEntryRefreshException(format("fail to find jdbc driver, errMsg=%s",
351-
e.getMessage()), e);
352-
}
353353
}
354354

355355
/*

src/main/java/com/alipay/oceanbase/rpc/location/model/TableRoute.java

Lines changed: 5 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ public void initRoster(TableEntryKey rootServerKey, boolean initialized,
204204
int retryMaxTimes = rsList.size();
205205
int retryTimes = 0;
206206
boolean success = false;
207+
Exception exception = null;
207208
while (!success && retryTimes < retryMaxTimes) {
208209
try {
209210
ObServerAddr obServerAddr = rsList.get(retryTimes);
@@ -221,6 +222,7 @@ public void initRoster(TableEntryKey rootServerKey, boolean initialized,
221222
"current server addr is invalid but rsList is not updated, ip: {}, sql port: {}",
222223
rsList.get(retryTimes).getIp(), rsList.get(retryTimes).getSqlPort());
223224
retryTimes++;
225+
exception = e;
224226
} else {
225227
throw e;
226228
}
@@ -229,14 +231,13 @@ public void initRoster(TableEntryKey rootServerKey, boolean initialized,
229231
if (!success) {
230232
BOOT.error("all rs servers are not available, rootServerKey:{}, rsList: {}",
231233
rootServerKey, rsList);
232-
throw new ObTableUnexpectedException("all rs servers are not available");
234+
throw new ObTableUnexpectedException("all rs servers are not available", exception);
233235
}
234236
List<ReplicaLocation> replicaLocations = tableEntry.getTableLocation()
235237
.getReplicaLocations();
236238
BOOT.info("{} success to get replicaLocation {}", tableClient.getDatabase(),
237239
objectMapper.writeValueAsString(replicaLocations));
238240

239-
List<Exception> obTableExceptions = new ArrayList<>();
240241
for (ReplicaLocation replicaLocation : replicaLocations) {
241242
ObServerInfo info = replicaLocation.getInfo();
242243
ObServerAddr addr = replicaLocation.getAddr();
@@ -246,55 +247,19 @@ public void initRoster(TableEntryKey rootServerKey, boolean initialized,
246247
continue;
247248
}
248249

249-
// 忽略初始化建连失败,否则client会初始化失败,导致应用无法启动的问题
250-
// 初始化建连失败(可能性较小),如果后面这台server恢复,数据路由失败,就会重新刷新metadata
251-
// 在失败100次后(RUNTIME_CONTINUOUS_FAILURE_CEILING),重新刷新建连
252-
// 本地cache 1小时超时后(SERVER_ADDRESS_CACHING_TIMEOUT),重新刷新建连
253-
// 应急可以直接observer切主
254250
try {
255251
ObTable obTable = new ObTable.Builder(addr.getIp(), addr.getSvrPort())
256-
//
257252
.setLoginInfo(tableClient.getTenantName(), tableClient.getUserName(),
258253
tableClient.getPassword(), tableClient.getDatabase(),
259254
tableClient.getClientType(runningMode))
260-
//
261255
.setProperties(tableClient.getProperties())
262256
.setConfigs(tableClient.getTableConfigs()).setObServerAddr(addr).build();
263257
addr2Table.put(addr, obTable);
264258
servers.add(addr);
265259
} catch (Exception e) {
266-
BOOT.warn(
267-
"The addr{}:{} failed to put into table roster, the node status may be wrong, Ignore",
268-
addr.getIp(), addr.getSvrPort());
269-
RUNTIME.warn("initMetadata meet exception", e);
270-
e.printStackTrace();
271-
// collect exceptions when login
272-
obTableExceptions.add(e);
273-
}
274-
}
275-
if (servers.isEmpty()) {
276-
BOOT.error("{} failed to connect any replicaLocation server: {}",
277-
tableClient.getDatabase(), objectMapper.writeValueAsString(replicaLocations));
278-
boolean isSameTypeException = true;
279-
int errCode = -1;
280-
// if collected exceptions are the same type, throw the original exception
281-
for (Exception e : obTableExceptions) {
282-
if (!(e instanceof ObTableException)) {
283-
isSameTypeException = false;
284-
break;
285-
}
286-
int curErrCord = ((ObTableException) e).getErrorCode();
287-
if (errCode == -1) {
288-
errCode = curErrCord;
289-
} else if (errCode != curErrCord) {
290-
isSameTypeException = false;
291-
break;
292-
}
293-
}
294-
if (isSameTypeException && !obTableExceptions.isEmpty()) {
295-
throw obTableExceptions.get(0);
260+
BOOT.warn("initMetadata meet exception", e);
261+
throw e;
296262
}
297-
throw new Exception("failed to connect any replicaLocation server");
298263
}
299264

300265
BOOT.info("{} success to build server connection {}", tableClient.getDatabase(),

0 commit comments

Comments
 (0)