Skip to content

Commit f684cf0

Browse files
authored
[Transaction] Fix the Github CI Test (apache#8541)
Motivation Try to fix the Github CI. ## implement because we consume all transaction messages than have been produced. but commit marker may not delete, because when a commit marker operation is processing, when we ack the position will not allow to do delete operation of commit marker, so the commit marker may not delete. we should handle this case.
1 parent 64f7ea9 commit f684cf0

File tree

2 files changed

+56
-5
lines changed

2 files changed

+56
-5
lines changed

pulsar-broker/src/test/java/org/apache/pulsar/broker/transaction/pendingack/PendingAckInMemoryDeleteTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ protected void cleanup() {
9595
}
9696

9797
@Test
98-
private void txnAckTestNoBatchAndSharedSubMemoryDeleteTest() throws Exception {
98+
public void txnAckTestNoBatchAndSharedSubMemoryDeleteTest() throws Exception {
9999
String normalTopic = NAMESPACE1 + "/normal-topic";
100100
String subscriptionName = "test";
101101

@@ -178,7 +178,7 @@ private void txnAckTestNoBatchAndSharedSubMemoryDeleteTest() throws Exception {
178178
}
179179

180180
@Test
181-
private void txnAckTestBatchAndSharedSubMemoryDeleteTest() throws Exception {
181+
public void txnAckTestBatchAndSharedSubMemoryDeleteTest() throws Exception {
182182
String normalTopic = NAMESPACE1 + "/normal-topic";
183183
String subscriptionName = "test";
184184

pulsar-broker/src/test/java/org/apache/pulsar/client/impl/TransactionEndToEndTest.java

+54-3
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,29 @@
1919
package org.apache.pulsar.client.impl;
2020

2121
import static java.nio.charset.StandardCharsets.UTF_8;
22+
import static org.testng.Assert.assertTrue;
2223
import static org.testng.Assert.fail;
2324

2425
import com.google.common.collect.Sets;
2526

27+
import java.lang.reflect.Field;
28+
import java.util.Optional;
29+
import java.util.concurrent.CompletableFuture;
2630
import java.util.ArrayList;
2731
import java.util.HashMap;
2832
import java.util.List;
2933
import java.util.Map;
3034
import java.util.concurrent.TimeUnit;
35+
3136
import lombok.Cleanup;
3237
import lombok.extern.slf4j.Slf4j;
38+
39+
import org.apache.bookkeeper.mledger.Position;
40+
import org.apache.bookkeeper.mledger.impl.ManagedLedgerImpl;
41+
import org.apache.bookkeeper.mledger.impl.PositionImpl;
42+
import org.apache.pulsar.broker.service.BrokerService;
43+
import org.apache.pulsar.broker.service.Topic;
44+
import org.apache.pulsar.broker.service.persistent.PersistentSubscription;
3345
import org.apache.pulsar.broker.transaction.TransactionTestBase;
3446
import org.apache.pulsar.client.api.Consumer;
3547
import org.apache.pulsar.client.api.Message;
@@ -51,6 +63,7 @@
5163
import org.apache.pulsar.common.policies.data.ClusterData;
5264
import org.apache.pulsar.common.policies.data.PersistentTopicInternalStats;
5365
import org.apache.pulsar.common.policies.data.TenantInfo;
66+
import org.apache.pulsar.common.util.collections.ConcurrentOpenHashMap;
5467
import org.testng.Assert;
5568
import org.testng.annotations.AfterMethod;
5669
import org.testng.annotations.BeforeMethod;
@@ -317,7 +330,7 @@ private void txnAckTest(boolean batchEnable, int maxBatchSize,
317330

318331
@Test
319332
public void txnMessageAckTest() throws Exception {
320-
final String topic = TOPIC_MESSAGE_ACK_TEST;
333+
String topic = TOPIC_MESSAGE_ACK_TEST;
321334
final String subName = "test";
322335
@Cleanup
323336
Consumer<byte[]> consumer = pulsarClient
@@ -382,8 +395,46 @@ public void txnMessageAckTest() throws Exception {
382395

383396
message = consumer.receive(2, TimeUnit.SECONDS);
384397
Assert.assertNull(message);
385-
386-
markDeletePositionCheck(topic, subName, true);
398+
for (int partition = 0; partition < TOPIC_PARTITION; partition ++) {
399+
topic = TopicName.get(topic).getPartition(partition).toString();
400+
boolean exist = false;
401+
for (int i = 0; i < getPulsarServiceList().size(); i++) {
402+
403+
Field field = BrokerService.class.getDeclaredField("topics");
404+
field.setAccessible(true);
405+
ConcurrentOpenHashMap<String, CompletableFuture<Optional<Topic>>> topics =
406+
(ConcurrentOpenHashMap<String, CompletableFuture<Optional<Topic>>>) field
407+
.get(getPulsarServiceList().get(i).getBrokerService());
408+
CompletableFuture<Optional<Topic>> topicFuture = topics.get(topic);
409+
410+
if (topicFuture != null) {
411+
Optional<Topic> topicOptional = topicFuture.get();
412+
if (topicOptional.isPresent()) {
413+
PersistentSubscription persistentSubscription =
414+
(PersistentSubscription) topicOptional.get().getSubscription(subName);
415+
Position markDeletePosition = persistentSubscription.getCursor().getMarkDeletedPosition();
416+
Position lastConfirmedEntry = persistentSubscription.getCursor()
417+
.getManagedLedger().getLastConfirmedEntry();
418+
exist = true;
419+
if (!markDeletePosition.equals(lastConfirmedEntry)) {
420+
//this because of the transaction commit marker have't delete
421+
//delete commit marker after ack position
422+
//when delete commit marker operation is processing, next delete operation will not do again
423+
//when delete commit marker operation finish, it can run next delete commit marker operation
424+
//so this test may not delete all the position in this manageLedger.
425+
Position markerPosition = ((ManagedLedgerImpl) persistentSubscription.getCursor()
426+
.getManagedLedger()).getNextValidPosition((PositionImpl) markDeletePosition);
427+
//marker is the lastConfirmedEntry, after commit the marker will only be write in
428+
if (!markerPosition.equals(lastConfirmedEntry)) {
429+
log.error("Mark delete position is not commit marker position!");
430+
fail();
431+
}
432+
}
433+
}
434+
}
435+
}
436+
assertTrue(exist);
437+
}
387438

388439
log.info("receive transaction messages count: {}", receiveCnt);
389440
}

0 commit comments

Comments
 (0)