Skip to content

Commit

Permalink
[inner-2129] When getKeyVariables, npe occasionally appears in dble.log
Browse files Browse the repository at this point in the history
  • Loading branch information
wenyh1 committed Oct 23, 2023
1 parent d5f2b72 commit 7ca0cd3
Showing 1 changed file with 69 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,11 @@ public KeyVariables call() {
while (!isFinish) {
boolean await = finishCond.await(ds.getConfig().getPoolConfig().getHeartbeatPeriodMillis(), TimeUnit.MILLISECONDS);
if (!await) {
fail = true;
isFinish = true;
LOGGER.warn("test conn timeout,TCP connection may be lost");
if (!isFinish) {
fail = true;
isFinish = true;
LOGGER.warn("test conn timeout,TCP connection may be lost");
}
}
}
} catch (InterruptedException e) {
Expand All @@ -86,89 +88,85 @@ public KeyVariables call() {
private class GetDbInstanceKeyVariablesListener implements SQLQueryResultListener<SQLQueryResult<Map<String, String>>> {
@Override
public void onResult(SQLQueryResult<Map<String, String>> result) {
if (result.isSuccess()) {
ds.setTestConnSuccess(true);
keyVariables = new KeyVariables();
keyVariables.setLowerCase(!result.getResult().get(COLUMN_LOWER_CASE).equals("0"));

keyVariables.setAutocommit(result.getResult().get(COLUMN_AUTOCOMMIT).equals("1"));
keyVariables.setTargetAutocommit(SystemConfig.getInstance().getAutocommit() == 1);

String isolation = result.getResult().get(columnIsolation);
switch (isolation) {
case "READ-COMMITTED":
keyVariables.setIsolation(Isolations.READ_COMMITTED);
break;
case "READ-UNCOMMITTED":
keyVariables.setIsolation(Isolations.READ_UNCOMMITTED);
break;
case "REPEATABLE-READ":
keyVariables.setIsolation(Isolations.REPEATABLE_READ);
break;
case "SERIALIZABLE":
keyVariables.setIsolation(Isolations.SERIALIZABLE);
break;
default:
break;
boolean isSuccess = result.isSuccess();
ds.setTestConnSuccess(isSuccess);
lock.lock();
try {
if (isFinish) {
if (fail)
LOGGER.info("test conn timeout, need to resynchronize");
return;
}
keyVariables.setTargetIsolation(SystemConfig.getInstance().getTxIsolation());
keyVariables.setMaxPacketSize(Integer.parseInt(result.getResult().get(COLUMN_MAX_PACKET)));
keyVariables.setTargetMaxPacketSize(SystemConfig.getInstance().getMaxPacketSize() + KeyVariables.MARGIN_PACKET_SIZE);
keyVariables.setReadOnly(result.getResult().get(COLUMN_READONLY).equals("1"));
keyVariables.setVersion(result.getResult().get(COLUMN_VERSION));
keyVariables.setBackLog(Integer.parseInt(result.getResult().get(COLUMN_BACK_LOG)));
if (isSuccess) {
ds.setTestConnSuccess(true);
keyVariables = new KeyVariables();
keyVariables.setLowerCase(!result.getResult().get(COLUMN_LOWER_CASE).equals("0"));

if (needSync) {
boolean checkNeedSync = false;
if (keyVariables.getTargetMaxPacketSize() > keyVariables.getMaxPacketSize()) {
checkNeedSync = true;
}
if (keyVariables.isTargetAutocommit() != keyVariables.isAutocommit()) {
checkNeedSync = true;
} else {
ds.setAutocommitSynced(true);
}
if (keyVariables.getTargetIsolation() != keyVariables.getIsolation()) {
checkNeedSync = true;
} else {
ds.setIsolationSynced(true);
keyVariables.setAutocommit(result.getResult().get(COLUMN_AUTOCOMMIT).equals("1"));
keyVariables.setTargetAutocommit(SystemConfig.getInstance().getAutocommit() == 1);

String isolation = result.getResult().get(columnIsolation);
switch (isolation) {
case "READ-COMMITTED":
keyVariables.setIsolation(Isolations.READ_COMMITTED);
break;
case "READ-UNCOMMITTED":
keyVariables.setIsolation(Isolations.READ_UNCOMMITTED);
break;
case "REPEATABLE-READ":
keyVariables.setIsolation(Isolations.REPEATABLE_READ);
break;
case "SERIALIZABLE":
keyVariables.setIsolation(Isolations.SERIALIZABLE);
break;
default:
break;
}
keyVariables.setTargetIsolation(SystemConfig.getInstance().getTxIsolation());
keyVariables.setMaxPacketSize(Integer.parseInt(result.getResult().get(COLUMN_MAX_PACKET)));
keyVariables.setTargetMaxPacketSize(SystemConfig.getInstance().getMaxPacketSize() + KeyVariables.MARGIN_PACKET_SIZE);
keyVariables.setReadOnly(result.getResult().get(COLUMN_READONLY).equals("1"));
keyVariables.setVersion(result.getResult().get(COLUMN_VERSION));
keyVariables.setBackLog(Integer.parseInt(result.getResult().get(COLUMN_BACK_LOG)));

if (checkNeedSync) {
SyncDbInstanceKeyVariables task = new SyncDbInstanceKeyVariables(keyVariables, ds);
boolean synced = false;
try {
synced = task.call();
} catch (Exception e) {
LOGGER.warn("SyncDbInstanceKeyVariables error", e);
if (needSync) {
boolean checkNeedSync = false;
if (keyVariables.getTargetMaxPacketSize() > keyVariables.getMaxPacketSize()) {
checkNeedSync = true;
}
if (synced) {
if (keyVariables.isTargetAutocommit() != keyVariables.isAutocommit()) {
checkNeedSync = true;
} else {
ds.setAutocommitSynced(true);
}
if (keyVariables.getTargetIsolation() != keyVariables.getIsolation()) {
checkNeedSync = true;
} else {
ds.setIsolationSynced(true);
keyVariables.setMaxPacketSize(keyVariables.getTargetMaxPacketSize());
}
}
}
} else {
ds.setTestConnSuccess(false);
}

handleFinished();
}
if (checkNeedSync) {
SyncDbInstanceKeyVariables task = new SyncDbInstanceKeyVariables(keyVariables, ds);
boolean synced = false;
try {
synced = task.call();
} catch (Exception e) {
LOGGER.warn("SyncDbInstanceKeyVariables error", e);
}

private void handleFinished() {
lock.lock();
try {
if (synced) {
ds.setAutocommitSynced(true);
ds.setIsolationSynced(true);
keyVariables.setMaxPacketSize(keyVariables.getTargetMaxPacketSize());
}
}
}
}
isFinish = true;
finishCond.signal();
if (fail) {
keyVariables = null;
LOGGER.info("test conn timeout, need to resynchronize");
}
} finally {
lock.unlock();
}
}
}

}

0 comments on commit 7ca0cd3

Please sign in to comment.