wenbingshen opened a new pull request, #3972:
URL: https://github.com/apache/bookkeeper/pull/3972
### Motivation
When bookie disabled readOnlyMode, once the user initiates a readOnly
conversion through the rest api, the bookie process will be shut down directly.
```java
public void doTransitionToReadOnlyMode() {
......
if (!conf.isReadOnlyModeEnabled()) {
LOG.warn("ReadOnly mode is not enabled. "
+ "Can be enabled by configuring "
+ "'readOnlyModeEnabled=true' in configuration."
+ " Shutting down bookie");
shutdownHandler.shutdown(ExitCode.BOOKIE_EXCEPTION);
return;
}
......
}
```
I have the following reasons for this PR:
1. If the user wants to shut down the bookie, there is no need to operate it
through the rest api, and can directly use the shell shutdown script.
2. The user switches the readOnly state through the rest api, the first
purpose is not to shut down the bookie process;
3. Exposing the bookie shutdown logic through the rest api has certain
security risks.
You can copy the following code to
org.apache.bookkeeper.server.http.TestHttpService#testBookieReadOnlyState to
reproduce the shutdown of bookie:
```java
// disable readOnly mode
restartBookies(c -> {
c.setForceReadOnlyBookie(false);
c.setReadOnlyModeEnabled(false);
return c;
});
MetadataBookieDriver metadataDriver =
BookieResources.createMetadataDriver(
baseConf, NullStatsLogger.INSTANCE);
BKHttpServiceProvider bkHttpServiceProvider2 = new
BKHttpServiceProvider.Builder()
.setBookieServer(serverByIndex(numberOfBookies - 1))
.setServerConfiguration(baseConf)
.setLedgerManagerFactory(metadataDriver.getLedgerManagerFactory())
.build();
HttpEndpointService bookieReadOnlyService2 = bkHttpServiceProvider2
.provideHttpEndpointService(HttpServer.ApiType.BOOKIE_STATE_READONLY);
request = new HttpServiceRequest(JsonUtil.toJson(new
ReadOnlyState(true)), HttpServer.Method.PUT, null);
response = bookieReadOnlyService2.handle(request);
Awaitility.await().untilAsserted(() -> {
assertFalse(serverByIndex(numberOfBookies -
1).isBookieRunning()); // here the bookie will be shutdown.
});
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]