Skip to content

Commit

Permalink
[Bookie] Prevent transit to writable mode when forceReadOnly mode is …
Browse files Browse the repository at this point in the history
…active (#3881)

* Fix forceReadOnly

* add unittest

---------

Co-authored-by: gavingaozhangmin <gavingaozhangmin@didiglobal.com>
  • Loading branch information
gaozhangmin and gavingaozhangmin committed Apr 3, 2023
1 parent 0171a40 commit a6387d1
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,11 @@ public boolean isReadOnly(){
return forceReadOnly.get() || bookieStatus.isInReadOnlyMode();
}

@Override
public boolean isForceReadOnly(){
return forceReadOnly.get();
}

@Override
public boolean isAvailableForHighPriorityWrites() {
return availableForHighPriorityWrites;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ public interface StateManager extends AutoCloseable {
*/
boolean isReadOnly();

/**
* Check is forceReadOnly.
*/
boolean isForceReadOnly();

/**
* Check is Running.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ public HttpServiceResponse handle(HttpServiceRequest request) throws Exception {
if (HttpServer.Method.PUT.equals(request.getMethod())) {
ReadOnlyState inState = JsonUtil.fromJson(request.getBody(), ReadOnlyState.class);
if (stateManager.isReadOnly() && !inState.isReadOnly()) {
if (stateManager.isForceReadOnly()) {
response.setCode(HttpServer.StatusCode.BAD_REQUEST);
response.setBody("Bookie is in forceReadOnly mode, cannot transit to writable mode");
return response;
}
stateManager.transitionToWritableMode().get();
} else if (!stateManager.isReadOnly() && inState.isReadOnly()) {
stateManager.transitionToReadOnlyMode().get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,14 @@ public void testBookieReadOnlyState() throws Exception {
response = bookieReadOnlyService.handle(request);
readOnlyState = JsonUtil.fromJson(response.getBody(), ReadOnlyState.class);
assertFalse(readOnlyState.isReadOnly());

//forceReadonly to writable
baseConf.setForceReadOnlyBookie(true);
baseConf.setReadOnlyModeEnabled(true);
restartBookies();
request = new HttpServiceRequest(JsonUtil.toJson(new ReadOnlyState(false)), HttpServer.Method.PUT, null);
response = bookieReadOnlyService.handle(request);
assertEquals(400, response.getStatusCode());
}

@Test
Expand Down

0 comments on commit a6387d1

Please sign in to comment.