Nicklee007 commented on code in PR #3802: URL: https://github.com/apache/bookkeeper/pull/3802#discussion_r1135364457
########## bookkeeper-server/src/main/java/org/apache/bookkeeper/server/http/service/TriggerLocationCompactService.java: ########## @@ -0,0 +1,154 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.bookkeeper.server.http.service; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.apache.bookkeeper.bookie.LedgerStorage; +import org.apache.bookkeeper.common.util.JsonUtil; +import org.apache.bookkeeper.http.HttpServer; +import org.apache.bookkeeper.http.service.HttpEndpointService; +import org.apache.bookkeeper.http.service.HttpServiceRequest; +import org.apache.bookkeeper.http.service.HttpServiceResponse; +import org.apache.bookkeeper.proto.BookieServer; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * HttpEndpointService that handle force trigger entry location compact requests. + * + * <p>The PUT method will trigger entry location compact on current bookie. + * + * <p>The GET method will get the entry location compact running or not. + * Output would be like: + * { + * "/data1/bookkeeper/ledgers/current/locations" : "false", + * "/data2/bookkeeper/ledgers/current/locations" : "true", + * } + */ + +public class TriggerLocationCompactService implements HttpEndpointService { + + static final Logger LOG = LoggerFactory.getLogger(TriggerLocationCompactService.class); + + private final BookieServer bookieServer; + + public TriggerLocationCompactService(BookieServer bookieServer) { + this.bookieServer = checkNotNull(bookieServer); + } + + @Override + public HttpServiceResponse handle(HttpServiceRequest request) throws Exception { + HttpServiceResponse response = new HttpServiceResponse(); + LedgerStorage ledgerStorage = bookieServer.getBookie().getLedgerStorage(); + + if (HttpServer.Method.PUT.equals(request.getMethod())) { + String requestBody = request.getBody(); + String output = "Not trigger Entry Location RocksDB compact."; + + if (StringUtils.isBlank(requestBody)) { + output = "Empty request body"; + response.setBody(output); + response.setCode(HttpServer.StatusCode.BAD_REQUEST); + return response; + } + + try { + @SuppressWarnings("unchecked") + Map<String, Object> configMap = JsonUtil.fromJson(requestBody, HashMap.class); + Boolean isEntryLocationCompact = (Boolean) configMap + .getOrDefault("entryLocationRocksDBCompact", false); + String entryLocations = (String) configMap.getOrDefault("entryLocations", ""); + List<String> entryLocationDBPath = ledgerStorage.getEntryLocationDBPath(); + if (!isEntryLocationCompact) { + // If entryLocationRocksDBCompact is false, doing nothing. + response.setBody(output); + response.setCode(HttpServer.StatusCode.OK); + return response; + } + if (StringUtils.isNotBlank(entryLocations)) { + // Specified trigger RocksDB compact entryLocations. + List<String> locations = Arrays.asList(entryLocations.trim().split(",")); + Map<String, Boolean> compactStatus = ledgerStorage.isEntryLocationCompacting(locations); + + if (entryLocationDBPath.containsAll(locations) && !compactStatus.containsValue(true)) { Review Comment: Has do some changes. > The request input locations are path1, and path4. It won't trigger. We'd better keep the all input path trigger or all not trigger. So in this case, we won't trigger any path compact, and response bad code and some message to tell user how to modify path to correct. then do request again. > The request input locations are path1, and path2. And the path1 is compacting, it also won't trigger. This case logic has changed ,will skip trigger path1 and will trigger path2 compact. -- 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]
