You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2019/07/10 07:52:57 UTC

[GitHub] [pulsar] sijie commented on a change in pull request #4686: [Transaction][buffer] persist transaction buffer implementation

sijie commented on a change in pull request #4686: [Transaction][buffer] persist transaction buffer implementation
URL: https://github.com/apache/pulsar/pull/4686#discussion_r301927295
 
 

 ##########
 File path: pulsar-transaction/buffer/src/main/java/org/apache/pulsar/transaction/buffer/impl/TransactionCursorImpl.java
 ##########
 @@ -0,0 +1,249 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.buffer.impl;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.stream.Collectors;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.bookkeeper.mledger.AsyncCallbacks;
+import org.apache.bookkeeper.mledger.Entry;
+import org.apache.bookkeeper.mledger.ManagedCursor;
+import org.apache.bookkeeper.mledger.ManagedLedger;
+import org.apache.bookkeeper.mledger.ManagedLedgerException;
+import org.apache.bookkeeper.mledger.Position;
+import org.apache.bookkeeper.mledger.impl.PositionImpl;
+import org.apache.pulsar.broker.PulsarService;
+import org.apache.pulsar.transaction.buffer.TransactionCursor;
+import org.apache.pulsar.transaction.buffer.TransactionMeta;
+import org.apache.pulsar.transaction.buffer.exceptions.TransactionNotFoundException;
+import org.apache.pulsar.transaction.impl.common.TxnID;
+import org.apache.pulsar.transaction.proto.TransactionBufferDataFormats;
+
+// Transaction cursor maintains transaction indexes.
+@Slf4j
+public class TransactionCursorImpl implements TransactionCursor {
+
+    private final ManagedLedger transactionLog;
+    private ManagedCursor indexLogCursor;
+
+    private ConcurrentMap<TxnID, TransactionMetaImpl> txnIndex;
+    private Map<Long, Set<TxnID>> committedTxnIndex;
+
+    private PulsarService pulsar;
+
+    private volatile boolean reocvering;
+
+    static class Result {
+        Position position;
+        ManagedLedgerException exception;
+    }
+
+    public TransactionCursorImpl(ManagedLedger managedLedger, PulsarService pulsar) {
+        this.pulsar = pulsar;
+        this.transactionLog = managedLedger;
+        this.txnIndex = new ConcurrentHashMap<>();
+        this.committedTxnIndex = new TreeMap<>();
+
+        initializeTransactionCursor();
+    }
+
+    private void initializeTransactionCursor() {
+        transactionLog.asyncOpenCursor(PersistentTransactionTopic.TRANSACTION_CURSOR_NAME,
+           new AsyncCallbacks.OpenCursorCallback() {
+               @Override
+               public void openCursorComplete(ManagedCursor cursor, Object ctx) {
+                   cursor.setAlwaysInactive();
+                   indexLogCursor = cursor;
+                   recover();
+               }
+
+               @Override
+               public void openCursorFailed(ManagedLedgerException exception, Object ctx) {
+                   log.warn("Failed to open transaction index cursor: {}",
+                            exception.getMessage());
 
 Review comment:
   `log.warn("...", exception)` to dump the stacktrace of the exception?
   
   

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services