Skip to content
Open
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 @@ -20,6 +20,7 @@

import static com.google.common.base.Preconditions.checkNotNull;

import java.util.Map;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
Expand Down Expand Up @@ -62,6 +63,13 @@ public HttpServiceResponse handle(HttpServiceRequest request) throws Exception {
} else if (!stateManager.isReadOnly() && inState.isReadOnly()) {
stateManager.transitionToReadOnlyMode().get();
}
Map<String, String> params = request.getParams();
if (params != null) {
boolean isForce = params.getOrDefault("force", "false").equals("true");
if (stateManager.isReadOnly() && isForce) {
stateManager.forceToReadOnly();
}
}
} else if (!HttpServer.Method.GET.equals(request.getMethod())) {
response.setCode(HttpServer.StatusCode.NOT_FOUND);
response.setBody("Unsupported method. Should be GET or PUT method");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1022,6 +1022,17 @@ public void testBookieReadOnlyState() throws Exception {
readOnlyState = JsonUtil.fromJson(response.getBody(), ReadOnlyState.class);
assertFalse(readOnlyState.isReadOnly());

// force=true force the bookie to readonly
Map<String, String> params = new HashMap<>();
params.put("force", "true");
request = new HttpServiceRequest(JsonUtil.toJson(new ReadOnlyState(true)), HttpServer.Method.PUT, params);
response = bookieReadOnlyService.handle(request);
readOnlyState = JsonUtil.fromJson(response.getBody(), ReadOnlyState.class);
assertTrue(readOnlyState.isReadOnly());
request = new HttpServiceRequest(JsonUtil.toJson(new ReadOnlyState(false)), HttpServer.Method.PUT, null);
response = bookieReadOnlyService.handle(request);
assertEquals(400, response.getStatusCode());

//forceReadonly to writable
baseConf.setForceReadOnlyBookie(true);
baseConf.setReadOnlyModeEnabled(true);
Expand Down