athanatos commented on a change in pull request #1931: (WIP) GetListOfEntriesOfLedger implementation URL: https://github.com/apache/bookkeeper/pull/1931#discussion_r254841207
########## File path: bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/GetListOfEntriesOfALedgerProcessorV3.java ########## @@ -0,0 +1,113 @@ +/* + * + * 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.proto; + +import com.google.protobuf.ByteString; +import io.netty.buffer.ByteBuf; +import io.netty.channel.Channel; +import io.netty.util.ReferenceCountUtil; +import java.io.IOException; +import java.util.concurrent.TimeUnit; + +import org.apache.bookkeeper.bookie.Bookie; +import org.apache.bookkeeper.proto.BookkeeperProtocol.GetListOfEntriesOfALedgerRequest; +import org.apache.bookkeeper.proto.BookkeeperProtocol.GetListOfEntriesOfALedgerResponse; +import org.apache.bookkeeper.proto.BookkeeperProtocol.Request; +import org.apache.bookkeeper.proto.BookkeeperProtocol.Response; +import org.apache.bookkeeper.proto.BookkeeperProtocol.StatusCode; +import org.apache.bookkeeper.util.MathUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * A processor class for v3 entries of a ledger packets. + */ +public class GetListOfEntriesOfALedgerProcessorV3 extends PacketProcessorBaseV3 implements Runnable { + + private static final Logger LOG = LoggerFactory.getLogger(GetListOfEntriesOfALedgerProcessorV3.class); + protected final GetListOfEntriesOfALedgerRequest getListOfEntriesOfALedgerRequest; + protected final long ledgerId; + + public GetListOfEntriesOfALedgerProcessorV3(Request request, Channel channel, + BookieRequestProcessor requestProcessor) { + super(request, channel, requestProcessor); + this.getListOfEntriesOfALedgerRequest = request.getGetListOfEntriesOfALedgerRequest(); + this.ledgerId = getListOfEntriesOfALedgerRequest.getLedgerId(); + } + + private GetListOfEntriesOfALedgerResponse getListOfEntriesOfALedgerResponse() { + long startTimeNanos = MathUtils.nowInNano(); + + GetListOfEntriesOfALedgerResponse.Builder getListOfEntriesOfALedgerResponse = GetListOfEntriesOfALedgerResponse + .newBuilder(); + getListOfEntriesOfALedgerResponse.setLedgerId(ledgerId); + + if (!isVersionCompatible()) { + getListOfEntriesOfALedgerResponse.setStatus(StatusCode.EBADVERSION); + requestProcessor.getRequestStats().getGetListOfEntriesOfALedgerStats() + .registerFailedEvent(MathUtils.elapsedNanos(startTimeNanos), TimeUnit.NANOSECONDS); + return getListOfEntriesOfALedgerResponse.build(); + } + + if (LOG.isDebugEnabled()) { + LOG.debug("Received new getListOfEntriesOfALedger request: {}", request); + } + StatusCode status = StatusCode.EOK; + ByteBuf listOfEntriesOfALedger = null; + try { + listOfEntriesOfALedger = requestProcessor.bookie.getListOfEntriesOfALedger(ledgerId); Review comment: For 2 I'd argue that it's not business logic, it's logic specific to the particular binary format you are using to ship it to the client. For 1 I'm mainly arguing that you need to merge streams of sorted entries in at least two places, I'd like it to be uniform and an iterator seems the natural way to do that. A visitor could also work. 3- That's a good argument for moving the class representing the encoding up into the proto package. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
