-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
### What changes are proposed in this pull request? Implemented a RpcServerStandbyGrpcService which runs gRPC server on both standby and primary masters. ### Why are the changes needed? We are going to implement a feature which allows workers registering to all masters to speed up the master failover process. This requires standby masters to enable gRPC servers so that the works can rpc. This PR made these changes. ### Does this PR introduce any user facing changes? N/A pr-link: #16839 change-id: cid-743160dea3f42872555b48d9a62125b2740962a3
- Loading branch information
Showing
7 changed files
with
212 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
core/server/master/src/main/java/alluxio/master/service/rpc/RpcServerStandbyGrpcService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* The Alluxio Open Foundation licenses this work under the Apache License, version 2.0 | ||
* (the "License"). You may not use this work except in compliance with the License, which is | ||
* available at www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | ||
* either express or implied, as more fully set forth in the License. | ||
* | ||
* See the NOTICE file distributed with this work for information regarding copyright ownership. | ||
*/ | ||
|
||
package alluxio.master.service.rpc; | ||
|
||
import alluxio.master.Master; | ||
import alluxio.master.MasterProcess; | ||
import alluxio.master.MasterRegistry; | ||
|
||
import com.google.common.base.Preconditions; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.net.InetSocketAddress; | ||
|
||
/** | ||
* Created by {@link RpcServerService.Factory}. | ||
* Manages the behavior of the master's rpc service. The grpc server is always on. | ||
* When the promotion/demotion happens, the rpc service will be stopped and restarted. | ||
* The new started grpc service will serve gRPC endpoints based on the node state (PRIMARY/STANDBY). | ||
* No rejecting server is deployed. | ||
*/ | ||
public class RpcServerStandbyGrpcService extends RpcServerService { | ||
protected static final Logger LOG = LoggerFactory.getLogger(RpcServerStandbyGrpcService.class); | ||
|
||
private boolean mIsPromoted = false; | ||
|
||
protected RpcServerStandbyGrpcService( | ||
InetSocketAddress bindAddress, | ||
MasterProcess masterProcess, | ||
MasterRegistry masterRegistry | ||
) { | ||
super(bindAddress, masterProcess, masterRegistry); | ||
} | ||
|
||
@Override | ||
public synchronized void start() { | ||
LOG.info("Starting {}", this.getClass().getSimpleName()); | ||
startGrpcServer(Master::getStandbyServices); | ||
} | ||
|
||
@Override | ||
public synchronized void stop() { | ||
stopGrpcServer(); | ||
stopRpcExecutor(); | ||
mIsPromoted = false; | ||
} | ||
|
||
@Override | ||
public synchronized void promote() { | ||
Preconditions.checkState(!mIsPromoted, "double promotion is not allowed"); | ||
LOG.info("Promoting {}", this.getClass().getSimpleName()); | ||
stopGrpcServer(); | ||
stopRpcExecutor(); | ||
waitForFree(); | ||
startGrpcServer(Master::getServices); | ||
mIsPromoted = true; | ||
} | ||
|
||
@Override | ||
public synchronized void demote() { | ||
Preconditions.checkState(mIsPromoted, "double demotion is not allowed"); | ||
LOG.info("Demoting {}", this.getClass().getSimpleName()); | ||
stopGrpcServer(); | ||
stopRpcExecutor(); | ||
waitForFree(); | ||
startGrpcServer(Master::getStandbyServices); | ||
mIsPromoted = false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
...rver/master/src/test/java/alluxio/master/service/rpc/RpcServerStandbyGrpcServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* The Alluxio Open Foundation licenses this work under the Apache License, version 2.0 | ||
* (the "License"). You may not use this work except in compliance with the License, which is | ||
* available at www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | ||
* either express or implied, as more fully set forth in the License. | ||
* | ||
* See the NOTICE file distributed with this work for information regarding copyright ownership. | ||
*/ | ||
|
||
package alluxio.master.service.rpc; | ||
|
||
import alluxio.conf.Configuration; | ||
import alluxio.conf.PropertyKey; | ||
import alluxio.master.AlluxioMasterProcess; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.powermock.core.classloader.annotations.PrepareForTest; | ||
import org.powermock.modules.junit4.PowerMockRunner; | ||
|
||
/** | ||
* Test for RpcServerStandbyGrpcServiceTest. | ||
*/ | ||
@RunWith(PowerMockRunner.class) | ||
@PrepareForTest(AlluxioMasterProcess.class) | ||
public class RpcServerStandbyGrpcServiceTest extends RpcServerServiceTestBase { | ||
@Before | ||
public void setUp() { | ||
Configuration.reloadProperties(); | ||
Configuration.set(PropertyKey.STANDBY_MASTER_GRPC_ENABLED, true); | ||
super.setUp(); | ||
} | ||
|
||
@Test | ||
public void primaryOnlyTest() { | ||
RpcServerService service = | ||
RpcServerService.Factory.create(mRpcAddress, mMasterProcess, mRegistry); | ||
Assert.assertTrue(waitForFree()); | ||
|
||
Assert.assertFalse(service.isServing()); | ||
service.start(); | ||
// when standby master is enabled, gRPC server is always on even if it's standby. | ||
Assert.assertTrue(isGrpcBound()); | ||
Assert.assertTrue(service.isServing()); | ||
for (int i = 0; i < 5; i++) { | ||
service.promote(); | ||
Assert.assertTrue(service.isServing()); | ||
Assert.assertTrue(isGrpcBound()); | ||
service.demote(); | ||
Assert.assertTrue(isGrpcBound()); | ||
Assert.assertTrue(service.isServing()); | ||
} | ||
service.stop(); | ||
Assert.assertFalse(service.isServing()); | ||
Assert.assertFalse(isGrpcBound()); | ||
} | ||
|
||
@Test | ||
public void doubleStartRpcServer() { | ||
RpcServerService service = | ||
RpcServerService.Factory.create(mRpcAddress, mMasterProcess, mRegistry); | ||
|
||
service.start(); | ||
service.promote(); | ||
Assert.assertThrows("double promotion is not allowed", | ||
IllegalStateException.class, service::promote); | ||
|
||
service.demote(); | ||
Assert.assertThrows("double demotion is not allowed", | ||
IllegalStateException.class, service::demote); | ||
} | ||
} |