Skip to content

Commit

Permalink
For alibaba#12526, judge whether cp protocol has init to avoid dead l…
Browse files Browse the repository at this point in the history
…ock to get cp protocol.
  • Loading branch information
KomachiSion committed Sep 2, 2024
1 parent 8126d59 commit 8171c90
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,14 @@ public APProtocol getApProtocol() {
return apProtocol;
}

public boolean isCpInit() {
return cpInit;
}

public boolean isApInit() {
return apInit;
}

@PreDestroy
@Override
public void destroy() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private boolean isReady() {
if (!globalConfig.isDataWarmup()) {
return true;
}
if (protocolManager.getCpProtocol() == null) {
if (!protocolManager.isCpInit() || protocolManager.getCpProtocol() == null) {
return false;
}
return protocolManager.getCpProtocol().isReady() && distroProtocol.isInitialized();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ void testGetServerStatus() {

@Test
void testGetErrorMsgForDistroProtocol() {
when(protocolManager.isCpInit()).thenReturn(true);
when(globalConfig.isDataWarmup()).thenReturn(true);
when(protocolManager.getCpProtocol()).thenReturn(cpProtocol);
when(distroProtocol.isInitialized()).thenReturn(false);
Expand All @@ -95,6 +96,7 @@ void testGetErrorMsgForDistroProtocol() {

@Test
void testGetErrorMsgForRaft() {
when(protocolManager.isCpInit()).thenReturn(true);
when(globalConfig.isDataWarmup()).thenReturn(true);
when(protocolManager.getCpProtocol()).thenReturn(cpProtocol);
when(cpProtocol.isReady()).thenReturn(false);
Expand Down Expand Up @@ -137,6 +139,7 @@ void testUpdaterStatusBySwitch() {

@Test
void testUpdaterStatusForDistroFailed() {
when(protocolManager.isCpInit()).thenReturn(true);
when(globalConfig.isDataWarmup()).thenReturn(true);
when(protocolManager.getCpProtocol()).thenReturn(cpProtocol);
ServerStatusManager.ServerStatusUpdater updater = serverStatusManager.new ServerStatusUpdater();
Expand All @@ -146,6 +149,7 @@ void testUpdaterStatusForDistroFailed() {

@Test
void testUpdaterStatusForRaftFailed() {
when(protocolManager.isCpInit()).thenReturn(true);
when(globalConfig.isDataWarmup()).thenReturn(true);
ServerStatusManager.ServerStatusUpdater updater = serverStatusManager.new ServerStatusUpdater();
updater.run();
Expand All @@ -158,6 +162,7 @@ void testUpdaterStatusForRaftFailed() {

@Test
void testUpdaterStatus() {
when(protocolManager.isCpInit()).thenReturn(true);
when(globalConfig.isDataWarmup()).thenReturn(true);
when(protocolManager.getCpProtocol()).thenReturn(cpProtocol);
when(cpProtocol.isReady()).thenReturn(true);
Expand Down

0 comments on commit 8171c90

Please sign in to comment.