sijie commented on a change in pull request #5570: Transaction log implemention URL: https://github.com/apache/pulsar/pull/5570#discussion_r344672688
########## File path: pulsar-transaction/coordinator/src/main/java/org/apache/pulsar/transaction/coordinator/impl/ManagedLedgerTransactionReaderImpl.java ########## @@ -0,0 +1,195 @@ +/** + * 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.pulsar.transaction.coordinator.impl; + +import io.netty.buffer.ByteBuf; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.atomic.AtomicLong; + +import org.apache.bookkeeper.mledger.Entry; +import org.apache.bookkeeper.mledger.ManagedLedgerConfig; +import org.apache.bookkeeper.mledger.ManagedLedgerException; +import org.apache.bookkeeper.mledger.ManagedLedgerFactory; +import org.apache.bookkeeper.mledger.ReadOnlyCursor; +import org.apache.bookkeeper.mledger.impl.PositionImpl; +import org.apache.pulsar.common.api.proto.PulsarApi.Subscription; +import org.apache.pulsar.common.api.proto.PulsarApi.TransactionMetadataEntry; +import org.apache.pulsar.common.api.proto.PulsarApi.TxnStatus; +import org.apache.pulsar.common.util.protobuf.ByteBufCodedInputStream; +import org.apache.pulsar.transaction.coordinator.TxnMeta; +import org.apache.pulsar.transaction.coordinator.TxnSubscription; +import org.apache.pulsar.transaction.coordinator.exceptions.InvalidTxnStatusException; +import org.apache.pulsar.transaction.impl.common.TxnID; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +class ManagedLedgerTransactionReaderImpl implements + ManagedLedgerTransactionMetadataStore.ManagedLedgerTransactionReader { + + private static final Logger LOGGER = LoggerFactory.getLogger(ManagedLedgerTransactionReaderImpl.class); + + private ConcurrentMap<TxnID, TxnMeta> txnMetaMap = new ConcurrentHashMap<>(); + + private AtomicLong sequenceId = new AtomicLong(ManagedLedgerTransactionMetadataStore.TC_ID_NOT_USED); + + private final ReadOnlyCursor readOnlyCursor; + + private Exception initCacheException; + + public ManagedLedgerTransactionReaderImpl(String tcId, ManagedLedgerFactory managedLedgerFactory) throws Exception { + this.readOnlyCursor = managedLedgerFactory + .openReadOnlyCursor(tcId, + PositionImpl.earliest, new ManagedLedgerConfig()); + CountDownLatch countDownLatch = new CountDownLatch(1); Review comment: I don't think it is a good idea to have a loop in the constructor and we shouldn't use synchronous operations. since all Pulsar internals are asynchronous. ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services