codelipenghui commented on a change in pull request #8318:
URL: https://github.com/apache/pulsar/pull/8318#discussion_r511474993



##########
File path: 
pulsar-broker/src/test/java/org/apache/pulsar/broker/service/TransactionMarkerDeleteTest.java
##########
@@ -0,0 +1,68 @@
+/**
+ * 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.service;
+
+import org.apache.bookkeeper.mledger.ManagedLedger;
+import org.apache.bookkeeper.mledger.Position;
+import org.apache.bookkeeper.mledger.impl.PositionImpl;
+import org.apache.pulsar.broker.service.persistent.PersistentSubscription;
+import org.apache.pulsar.broker.service.persistent.PersistentTopic;
+import org.apache.pulsar.common.api.proto.PulsarApi.CommandAck.AckType;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import java.util.Collections;
+
+public class TransactionMarkerDeleteTest extends BrokerTestBase{
+
+    @BeforeMethod
+    @Override
+    protected void setup() throws Exception {
+        super.baseSetup();
+    }
+
+    @AfterMethod
+    @Override
+    protected void cleanup() throws Exception {
+        super.internalCleanup();
+    }
+
+    @Test
+    public void TransactionMarkerDeleteTest() throws Exception {

Review comment:
       ```suggestion
       public void testTransactionMarkerDelete() throws Exception {
   ```

##########
File path: 
pulsar-broker/src/test/java/org/apache/pulsar/broker/service/TransactionMarkerDeleteTest.java
##########
@@ -0,0 +1,68 @@
+/**
+ * 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.service;
+
+import org.apache.bookkeeper.mledger.ManagedLedger;
+import org.apache.bookkeeper.mledger.Position;
+import org.apache.bookkeeper.mledger.impl.PositionImpl;
+import org.apache.pulsar.broker.service.persistent.PersistentSubscription;
+import org.apache.pulsar.broker.service.persistent.PersistentTopic;
+import org.apache.pulsar.common.api.proto.PulsarApi.CommandAck.AckType;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import java.util.Collections;
+
+public class TransactionMarkerDeleteTest extends BrokerTestBase{
+
+    @BeforeMethod
+    @Override
+    protected void setup() throws Exception {
+        super.baseSetup();
+    }
+
+    @AfterMethod
+    @Override
+    protected void cleanup() throws Exception {
+        super.internalCleanup();
+    }
+
+    @Test
+    public void TransactionMarkerDeleteTest() throws Exception {
+        ManagedLedger managedLedger = 
pulsar.getManagedLedgerFactory().open("test");
+        Position position1 = managedLedger.addEntry("test".getBytes());
+        managedLedger.addEntry("test".getBytes());
+        Position position3 = managedLedger.addEntry("test".getBytes());
+        PersistentTopic topic = mock(PersistentTopic.class);
+        doReturn(managedLedger).when(topic).getManagedLedger();
+        managedLedger.openCursor("test");
+        PersistentSubscription persistentSubscription = new 
PersistentSubscription(topic, "test",
+                managedLedger.openCursor("test"), false);
+        
persistentSubscription.acknowledgeMessage(Collections.singletonList(position1),
+                AckType.Individual, Collections.emptyMap());
+        assertEquals(0, ((PositionImpl) persistentSubscription.getCursor()
+                .getMarkDeletedPosition()).compareTo((PositionImpl) 
position3));

Review comment:
       I did not understand this test, looks not related to the changes that 
the PR introduced. At least you need to write one Transaction Marker into the 
managed ledger?

##########
File path: 
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentSubscription.java
##########
@@ -393,6 +398,27 @@ public void acknowledgeMessage(List<Position> positions, 
AckType ackType, Map<St
         }
     }
 
+    private void deleteTransactionMarker(PositionImpl position, AckType 
ackType, Map<String,Long> properties) {
+        if (position != null) {
+            ManagedLedgerImpl managedLedger = ((ManagedLedgerImpl) 
cursor.getManagedLedger());
+            managedLedger.asyncReadEntry(position, new ReadEntryCallback() {
+                @Override
+                public void readEntryComplete(Entry entry, Object ctx) {
+                    MessageMetadata messageMetadata = 
Commands.parseMessageMetadata(entry.getDataBuffer());
+                    if (Markers.isTxnCommitMarker(messageMetadata)) {

Review comment:
       I think we should delete all transaction markers right? not only the 
commit marker.




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