congbobo184 commented on a change in pull request #8256:
URL: https://github.com/apache/pulsar/pull/8256#discussion_r511714578



##########
File path: 
pulsar-broker/src/main/java/org/apache/pulsar/broker/transaction/pendingack/impl/PendingAckHandleImpl.java
##########
@@ -0,0 +1,363 @@
+/**
+ * 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.broker.transaction.pendingack.impl;
+
+import lombok.extern.slf4j.Slf4j;
+import org.apache.bookkeeper.mledger.Position;
+import org.apache.bookkeeper.mledger.impl.ManagedCursorImpl;
+import org.apache.bookkeeper.mledger.impl.PositionImpl;
+import org.apache.bookkeeper.util.collections.ConcurrentLongLongPairHashMap;
+import org.apache.pulsar.broker.service.Consumer;
+import org.apache.pulsar.broker.service.persistent.PersistentSubscription;
+import org.apache.pulsar.broker.transaction.pendingack.PendingAckHandle;
+import org.apache.pulsar.client.api.transaction.TxnID;
+import org.apache.pulsar.common.api.proto.PulsarApi.CommandAck.AckType;
+import org.apache.pulsar.common.util.collections.ConcurrentOpenHashMap;
+import org.apache.pulsar.common.util.collections.ConcurrentOpenHashSet;
+import 
org.apache.pulsar.transaction.common.exception.TransactionConflictException;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
+
+import static com.google.common.base.Preconditions.checkArgument;
+
+@Slf4j
+public class PendingAckHandleImpl implements PendingAckHandle {
+
+    // Map to keep track of message ack by each txn.
+    private ConcurrentOpenHashMap<TxnID, ConcurrentOpenHashMap<Position, 
Position>> pendingIndividualAckMessagesMap;
+
+    // Messages acked by ongoing transaction, pending transaction commit to 
materialize the acks. For faster look up.
+    // Using hashset as a message should only be acked once by one transaction.
+    private ConcurrentOpenHashMap<Position, Position> pendingAckMessages;
+
+    private ConcurrentOpenHashMap<Position, ConcurrentOpenHashSet<TxnID>> 
pendingAckBatchMessageMap;
+
+    // Message cumulative acked by ongoing transaction, pending transaction 
commit to materialize the ack.
+    // Only one transaction can cumulative ack.
+    // This parameter only keep the the largest Position it cumulative ack,as 
any Position smaller will also be covered.
+    private volatile Position pendingCumulativeAckMessage;
+
+    private static final AtomicReferenceFieldUpdater<PendingAckHandleImpl, 
Position> POSITION_UPDATER =
+            AtomicReferenceFieldUpdater.newUpdater(PendingAckHandleImpl.class, 
Position.class,
+                    "pendingCumulativeAckMessage");
+
+    // ID of transaction currently using cumulative ack.
+    private volatile TxnID pendingCumulativeAckTxnId;
+
+    private static final AtomicReferenceFieldUpdater<PendingAckHandleImpl, 
TxnID> PENDING_CUMULATIVE_ACK_TXNID_UPDATER =
+            AtomicReferenceFieldUpdater.newUpdater(PendingAckHandleImpl.class, 
TxnID.class,
+                    "pendingCumulativeAckTxnId");
+
+    private PersistentSubscription persistentSubscription;
+
+    private final String topicName;
+
+    private final String subName;
+
+    public PendingAckHandleImpl(String topicName, String subName) {
+        this.topicName = topicName;
+        this.subName = subName;
+    }
+
+    @Override
+    public synchronized CompletableFuture<Void> acknowledgeMessage(TxnID txnId,
+                                                                   
List<Position> positions, AckType ackType) {
+        checkArgument(txnId != null, "TransactionID can not be null.");

Review comment:
       OK, it will completeException(NotAllowException).




----------------------------------------------------------------
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:
[email protected]


Reply via email to