Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[inner-2377] Ensure the orderliness of stop/start operations of dbinstance #3852

Merged
merged 1 commit into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ private boolean checkState() {
if (getBindingCount() != 0) {
state = STATE_DELETING;
IOProcessor.BACKENDS_OLD_GROUP.add(this);
long time = System.nanoTime();
allSourceMap.values().forEach(f -> f.setAsyncExecStopTime(time));
return false;
}
state = STATE_ABANDONED;
Expand Down Expand Up @@ -274,7 +276,7 @@ public void stopOfFresh(List<String> sourceNames, String reason, boolean closeFr
public boolean stopOfBackground(String reason) {
if (state.intValue() == STATE_DELETING && getBindingCount() == 0) {
for (PhysicalDbInstance dbInstance : allSourceMap.values()) {
dbInstance.stopDirectly(reason, false, false);
dbInstance.stopOfBackground(reason);
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ public abstract class PhysicalDbInstance implements ReadTimeStatusInstance {
private volatile boolean needSkipEvit = false;
private volatile boolean needSkipHeartTest = false;
private volatile int logCount;

private volatile long lastExecTime; // stop、start
private volatile long asyncExecStopTime;

public PhysicalDbInstance(DbInstanceConfig config, DbGroupConfig dbGroupConfig, boolean isReadNode) {
this.config = config;
Expand Down Expand Up @@ -431,6 +432,7 @@ public void start() {
}

void start(String reason, boolean isStartHeartbeat, boolean delayDetectionStart) {
lastExecTime = System.nanoTime();
startPool(reason);
if (isStartHeartbeat) {
startHeartbeat();
Expand All @@ -454,6 +456,7 @@ private boolean checkState() {
if (dbGroup.getBindingCount() != 0) {
dbGroup.setState(PhysicalDbGroup.STATE_DELETING);
IOProcessor.BACKENDS_OLD_INSTANCE.add(this);
setAsyncExecStopTime(System.nanoTime());
return false;
}
if (dbGroup.isStop()) {
Expand All @@ -462,13 +465,18 @@ private boolean checkState() {
if (dbGroup.getBindingCount() != 0) {
dbGroup.setState(PhysicalDbGroup.STATE_DELETING);
IOProcessor.BACKENDS_OLD_INSTANCE.add(this);
setAsyncExecStopTime(System.nanoTime());
return false;
}
return true;
}

public boolean stopOfBackground(String reason) {
if (dbGroup.getState() == PhysicalDbGroup.STATE_DELETING && dbGroup.getBindingCount() == 0) {
if (asyncExecStopTime <= lastExecTime) { // In extreme cases (equal cases), in extreme cases there may be problems,
LOGGER.info("discard expired stop() operations");
return true;
}
stopDirectly(reason, false, false);
return true;
}
Expand Down Expand Up @@ -496,6 +504,7 @@ public void stop(String reason, boolean closeFront) {
}

protected void stop(String reason, boolean closeFront, boolean isStopHeartbeat, boolean isStopPool, boolean delayDetectionStop) {
lastExecTime = System.nanoTime();
if (isStopHeartbeat) {
stopHeartbeat(reason);
}
Expand Down Expand Up @@ -576,6 +585,22 @@ public boolean enable() {
return false;
}

public long getLastExecTime() {
return lastExecTime;
}

public void setLastExecTime(long lastExecTime) {
this.lastExecTime = lastExecTime;
}

public long getAsyncExecStopTime() {
return asyncExecStopTime;
}

public void setAsyncExecStopTime(long asyncExecStopTime) {
this.asyncExecStopTime = asyncExecStopTime;
}

public final int getActiveConnections() {
return connectionPool.getCount(PooledConnection.STATE_IN_USE);
}
Expand Down
Loading