reddycharan commented on a change in pull request #1931: (WIP) GetListOfEntriesOfLedger implementation URL: https://github.com/apache/bookkeeper/pull/1931#discussion_r254091827
########## 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: @athanatos @eolivelli I don't think it is valid to do here for the following reasons - 1) getListOfEntriesOfALedger implementation is LedgerStorage specific, I don't see how can we abstract this out at LedgerStorage specific level and deal with it here. I don’t think it is optimal to expect all the Storage implementation to return Iterator of long values (entry numbers), because in each storage implementation, things might be different for how entry details can be read. Having iterator based approach is not ideal in all cases. 2) From what I understand, GetListOfEntriesOfALedgerProcessorV3 is a request/response processor and it is not appropriate to deal with business logic in this class. 3) Also this class is in proto package, we don’t want the Encoding class details / code to be in this package and also this class won’t have access to ‘bookie’ package protected classes. ---------------------------------------------------------------- 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
