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/16 14:03:33 UTC

[GitHub] [pulsar] sijie commented on a change in pull request #4738: [WIP][Transaction][buffer] Add basic operation of transaction

sijie commented on a change in pull request #4738: [WIP][Transaction][buffer] Add basic operation of transaction
URL: https://github.com/apache/pulsar/pull/4738#discussion_r303924802
 
 

 ##########
 File path: pulsar-transaction/buffer/src/main/java/org/apache/pulsar/transaction/buffer/impl/PersistentTransactionBuffer.java
 ##########
 @@ -0,0 +1,179 @@
+/**
+ * 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.buffer.impl;
+
+import io.netty.buffer.ByteBuf;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import org.apache.bookkeeper.mledger.ManagedLedger;
+import org.apache.bookkeeper.mledger.ManagedLedgerException;
+import org.apache.bookkeeper.mledger.impl.PositionImpl;
+import org.apache.pulsar.broker.service.BrokerService;
+import org.apache.pulsar.broker.service.BrokerServiceException;
+import org.apache.pulsar.broker.service.persistent.PersistentTopic;
+import org.apache.pulsar.transaction.buffer.TransactionBuffer;
+import org.apache.pulsar.transaction.buffer.TransactionBufferReader;
+import org.apache.pulsar.transaction.buffer.TransactionCursor;
+import org.apache.pulsar.transaction.buffer.TransactionMeta;
+import org.apache.pulsar.transaction.impl.common.TxnID;
+
+public class PersistentTransactionBuffer extends PersistentTopic implements TransactionBuffer {
+
+    private TransactionCursor txnCursor;
+
+    abstract class TxnCtx implements PublishContext {}
+
+    public PersistentTransactionBuffer(String topic, ManagedLedger ledger, BrokerService brokerService)
+        throws BrokerServiceException.NamingException {
+        super(topic, ledger, brokerService);
+        this.txnCursor = new TransactionCursorImpl();
+    }
+
+    @Override
+    public CompletableFuture<TransactionMeta> getTransactionMeta(TxnID txnID) {
+        CompletableFuture<TransactionMeta> getFuture = new CompletableFuture<>();
+
+        txnCursor.getTxnMeta(txnID, false).thenCompose(meta -> {
+            getFuture.complete(meta);
+            return null;
+        }).exceptionally(e -> {
+            getFuture.completeExceptionally(e);
+            return null;
+        });
+
+        return getFuture;
+    }
+
+    @Override
+    public CompletableFuture<Void> appendBufferToTxn(TxnID txnId, long sequenceId, ByteBuf buffer) {
 
 Review comment:
   It seems that sequenceId is not used in publishMessage. `sequenceId` should be used for de-duplication.

----------------------------------------------------------------
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