Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix][client] moving get sequenceId into the sync code segment #17836

Merged
merged 14 commits into from
Dec 13, 2022
Merged

[fix][client] moving get sequenceId into the sync code segment #17836

merged 14 commits into from
Dec 13, 2022

Conversation

liangyepianzhou
Copy link
Contributor

@liangyepianzhou liangyepianzhou commented Sep 26, 2022

Motivation

When the producer sends messages in multiple threads, the message with the smaller sequence Id can be pushed later than the message with the bigger sequence Id.
The internalSendWithTxnAsync call internalSendAsync Asynchronously when txn != null

CompletableFuture<MessageId> internalSendWithTxnAsync(Message<?> message, Transaction txn) {

And the sendAsync acquire sequence ID is not included in the synchronized block with serializeAndSendMessage.
final long sequenceId = updateMessageMetadata(msgMetadata, uncompressedSize);

synchronized (this) {
serializeAndSendMessage(msg, payload, sequenceId, uuid, chunkId, totalChunks,
readStartIndex, payloadChunkSize, compressedPayload, compressed,
compressedPayload.readableBytes(), callback, chunkedMessageCtx);
readStartIndex = ((chunkId + 1) * payloadChunkSize);
}

For example:
We send 4 messages (msg1, msg2, msg3, msg4) to the broker and then the 4 messages may get 4 sequence Id (1, 3, 2, 4) which is not in order due to the logic to get the sequence ID and send the message is not in the same synchronous code block.
And then the msg3 with sequence ID 2 will never be persistent successfully.

Modification

Add a method to update sequenceId and move the method in the sync code.
Via #16196 we should update message metadata before computing the message size.

reproduce

This test can reproduce this problem, but this is not guaranteed to recur.

@Test
public void testUpdateSequenceIdInSyncCodeSegment() throws Exception {
    String topic = NAMESPACE1 + "/sequenceId";
    int totalMessage = 10;
    int threadSize = 30;
    String topicName = "subscription";
    ExecutorService executorService = Executors.newFixedThreadPool(threadSize);

    //build producer/consumer
    Producer<byte[]> producer = pulsarClient.newProducer()
            .topic(topic)
            .producerName("producer")
            .sendTimeout(0, TimeUnit.SECONDS)
            .create();

    Consumer<byte[]> consumer = pulsarClient.newConsumer()
            .topic(topic)
            .subscriptionType(SubscriptionType.Exclusive)
            .subscriptionName(topicName)
            .subscribe();

    //send and ack messages with transaction
    Transaction transaction = pulsarClient.newTransaction()
            .withTransactionTimeout(10, TimeUnit.SECONDS)
            .build()
            .get();

    for (int i = 0; i < totalMessage * threadSize; i++) {
        producer.newMessage().send();
    }

    CountDownLatch countDownLatch = new CountDownLatch(threadSize);
    CompletableFuture<Void> result = new CompletableFuture<>();
    for (int i = 0; i < threadSize; i++) {
        executorService.submit(() -> {
            try {
                for (int j = 0; j < totalMessage && !result.isCompletedExceptionally(); j++) {
                    producer.newMessage(transaction).sendAsync();
                    Message<byte[]> message = consumer.receive();
                    consumer.acknowledgeAsync(message.getMessageId(),
                            transaction);
                }
            } catch (Exception e) {
                result.completeExceptionally(e);
                log.error("Failed to send/ack messages with transaction.", e);
            } finally {
                countDownLatch.countDown();
            }
        });
    }
    //wait the all send/ack op is executed and store its futures in the arraylist.
    countDownLatch.await(10, TimeUnit.SECONDS);
    transaction.commit().get();
}

error logs

PersistenceError : Cannot determine whether the message is a duplicate at this time
2022-10-07T23:28:12,790 - WARN  - [pulsar-client-io-60-1:ClientCnx@692] - [id: 0xa58384cf, L:/127.0.0.1:61274 ! R:localhost/127.0.0.1:61246] Received send error from server: PersistenceError : Cannot determine whether the message is a duplicate at this time
2022-10-07T23:28:12,790 - WARN  - [pulsar-client-io-60-1:ClientCnx@692] - [id: 0xa58384cf, L:/127.0.0.1:61274 ! R:localhost/127.0.0.1:61246] Received send error from server: PersistenceError : Cannot determine whether the message is a duplicate at this time
2022-10-07T23:28:12,790 - WARN  - [pulsar-client-io-60-1:ClientCnx@692] - [id: 0xa58384cf, L:/127.0.0.1:61274 ! R:localhost/127.0.0.1:61246] Received send error from server: PersistenceError : Cannot determine whether the message is a duplicate at this time
2022-10-07T23:28:12,790 - WARN  - [pulsar-client-io-60-1:ClientCnx@692] - [id: 0xa58384cf, L:/127.0.0.1:61274 ! R:localhost/127.0.0.1:61246] Received send error from server: PersistenceError : Cannot determine whether the message is a duplicate at this time
2022-10-07T23:28:12,790 - WARN  - [pulsar-client-io-60-1:ClientCnx@692] - [id: 0xa58384cf, L:/127.0.0.1:61274 ! R:localhost/127.0.0.1:61246] Received send error from server: PersistenceError : Cannot determine whether the message is a duplicate at this time
2022-10-07T23:28:12,790 - WARN  - [pulsar-client-io-60-1:ClientCnx@692] - [id: 0xa58384cf, L:/127.0.0.1:61274 ! R:localhost/127.0.0.1:61246] Received send error from server: PersistenceError : Cannot determine whether the message is a duplicate at this time
2022-10-07T23:28:12,791 - WARN  - [pulsar-client-io-60-1:ClientCnx@692] - [id: 0xa58384cf, L:/127.0.0.1:61274 ! R:localhost/127.0.0.1:61246] Received send error from server: PersistenceError : Cannot determine whether the message is a duplicate at this time
2022-10-07T23:28:12,791 - WARN  - [pulsar-client-io-60-1:ClientCnx@692] - [id: 0xa58384cf, L:/127.0.0.1:61274 ! R:localhost/127.0.0.1:61246] Received send error from server: PersistenceError : Cannot determine whether the message is a duplicate at this time
2022-10-07T23:28:12,791 - WARN  - [pulsar-client-io-60-1:ClientCnx@692] - [id: 0xa58384cf, L:/127.0.0.1:61274 ! R:localhost/127.0.0.1:61246] Received send error from server: PersistenceError : Cannot determine whether the message is a duplicate at this time
2022-10-07T23:28:12,791 - WARN  - [pulsar-client-io-60-1:ClientCnx@692] - [id: 0xa58384cf, L:/127.0.0.1:61274 ! R:localhost/127.0.0.1:61246] Received send error from server: PersistenceError : Cannot determine whether the message is a duplicate at this time
2022-10-07T23:28:12,791 - WARN  - [pulsar-client-io-60-1:ClientCnx@692] - [id: 0xa58384cf, L:/127.0.0.1:61274 ! R:localhost/127.0.0.1:61246] Received send error from server: PersistenceError : Cannot determine whether the message is a duplicate at this time
2022-10-07T23:28:12,791 - WARN  - [pulsar-client-io-60-1:ClientCnx@692] - [id: 0xa58384cf, L:/127.0.0.1:61274 ! R:localhost/127.0.0.1:61246] Received send error from server: PersistenceError : Cannot determine whether the message is a duplicate at this time
2022-10-07T23:28:12,791 - WARN  - [pulsar-client-io-60-1:ClientCnx@692] - [id: 0xa58384cf, L:/127.0.0.1:61274 ! R:localhost/127.0.0.1:61246] Received send error from server: PersistenceError : Cannot determine whether the message is a duplicate at this time
2022-10-07T23:28:12,791 - WARN  - [pulsar-client-io-60-1:ClientCnx@692] - [id: 0xa58384cf, L:/127.0.0.1:61274 ! R:localhost/127.0.0.1:61246] Received send error from server: PersistenceError : Cannot determine whether the message is a duplicate at this time
2022-10-07T23:28:12,791 - WARN  - [pulsar-client-io-60-1:ClientCnx@692] - [id: 0xa58384cf, L:/127.0.0.1:61274 ! R:localhost/127.0.0.1:61246] Received send error from server: PersistenceError : Cannot determine whether the message is a duplicate at this time
2022-10-07T23:28:12,792 - WARN  - [pulsar-client-io-60-1:ClientCnx@692] - [id: 0xa58384cf, L:/127.0.0.1:61274 ! R:localhost/127.0.0.1:61246] Received send error from server: PersistenceError : Cannot determine whether the message is a duplicate at this time
2022-10-07T23:28:12,792 - WARN  - [pulsar-client-io-60-1:ClientCnx@692] - [id: 0xa58384cf, L:/127.0.0.1:61274 ! R:localhost/127.0.0.1:61246] Received send error from server: PersistenceError : Cannot determine whether the message is a duplicate at this time
2022-10-07T23:28:12,792 - WARN  - [pulsar-client-io-60-1:ClientCnx@692] - [id: 0xa58384cf, L:/127.0.0.1:61274 ! R:localhost/127.0.0.1:61246] Received send error from server: PersistenceError : Cannot determine whether the message is a duplicate at this time
2022-10-07T23:28:12,792 - WARN  - [pulsar-client-io-60-1:ClientCnx@692] - [id: 0xa58384cf, L:/127.0.0.1:61274 ! R:localhost/127.0.0.1:61246] Received send error from server: PersistenceError : Cannot determine whether the message is a duplicate at this time
2022-10-07T23:28:12,792 - WARN  - [pulsar-client-io-60-1:ClientCnx@692] - [id: 0xa58384cf, L:/127.0.0.1:61274 ! R:localhost/127.0.0.1:61246] Received send error from server: PersistenceError : Cannot determine whether the message is a duplicate at this time
2022-10-07T23:28:12,792 - WARN  - [pulsar-client-io-60-1:ClientCnx@692] - [id: 0xa58384cf, L:/127.0.0.1:61274 ! R:localhost/127.0.0.1:61246] Received send error from server: PersistenceError : Cannot determine whether the message is a duplicate at this time
2022-10-07T23:28:12,792 - WARN  - [pulsar-client-io-60-1:ClientCnx@692] - [id: 0xa58384cf, L:/127.0.0.1:61274 ! R:localhost/127.0.0.1:61246] Received send error from server: PersistenceError : Cannot determine whether the message is a duplicate at this time
2022-10-07T23:28:12,792 - INFO  - [pulsar-client-io-60-1:ClientCnx@284] - [id: 0xa58384cf, L:/127.0.0.1:61274 ! R:localhost/127.0.0.1:61246] Disconnected
2022-10-07T23:28:12,793 - INFO  - [pulsar-client-io-60-1:ConnectionHandler@139] - [tnx/ns1/sequenceId] [producer] Closed connection [id: 0xa58384cf, L:/127.0.0.1:61274 ! R:localhost/127.0.0.1:61246] -- Will try again in 0.1 s
2022-10-07T23:28:12,793 - INFO  - [pulsar-client-io-60-1:ConnectionHandler@139] - [tnx/ns1/sequenceId] [subscription] Closed connection [id: 0xa58384cf, L:/127.0.0.1:61274 ! R:localhost/127.0.0.1:61246] -- Will try again in 0.1 s
2022-10-07T23:28:12,793 - INFO  - [pulsar-client-io-60-1:ConnectionHandler@139] - [persistent://pulsar/system/transaction_coordinator_assign-partition-0] [Transaction meta store handler [0]] Closed connection [id: 0xa58384cf, L:/127.0.0.1:61274 ! R:localhost/127.0.0.1:61246] -- Will try again in 0.1 s
2022-10-07T23:28:12,878 - INFO  - [broker-topic-workers-OrderedExecutor-1-0:ManagedCursorImpl@2403] - [tnx/ns1/persistent/sequenceId-subscription] Rewind from 11:100 to 11:0
2022-10-07T23:28:12,893 - INFO  - [pulsar-timer-64-1:ConnectionHandler@143] - [tnx/ns1/sequenceId] [producer] Reconnecting after timeout
2022-10-07T23:28:12,893 - INFO  - [pulsar-timer-64-1:ConnectionHandler@143] - [tnx/ns1/sequenceId] [subscription] Reconnecting after timeout
2022-10-07T23:28:12,895 - INFO  - [pulsar-timer-64-1:ConnectionHandler@143] - [persistent://pulsar/system/transaction_coordinator_assign-partition-0] [Transaction meta store handler [0]] Reconnecting after timeout
2022-10-07T23:28:12,899 - INFO  - [pulsar-client-io-60-1:ConnectionPool@245] - [[id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246]] Connected to server
2022-10-07T23:28:12,901 - INFO  - [pulsar-io-17-17:ServerCnx@299] - New connection from /127.0.0.1:61275
2022-10-07T23:28:12,905 - INFO  - [pulsar-client-internal-62-1:TransactionMetaStoreHandler@128] - Transaction meta handler with transaction coordinator id 0 connection opened.
2022-10-07T23:28:12,905 - INFO  - [pulsar-client-io-60-1:ConsumerImpl@822] - [tnx/ns1/sequenceId][subscription] Subscribing to topic on cnx [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246], consumerId 0
2022-10-07T23:28:12,905 - INFO  - [pulsar-client-io-60-1:ProducerImpl@1639] - [tnx/ns1/sequenceId] [producer] Creating producer on cnx [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246]
2022-10-07T23:28:12,906 - INFO  - [pulsar-io-17-17:ServerCnx@1042] - [/127.0.0.1:61275] Subscribing on topic persistent://tnx/ns1/sequenceId / subscription
2022-10-07T23:28:12,907 - INFO  - [pulsar-io-17-17:ManagedCursorImpl@2403] - [tnx/ns1/persistent/sequenceId-subscription] Rewind from 11:0 to 11:0
2022-10-07T23:28:12,907 - INFO  - [pulsar-io-17-17:ServerCnx@1134] - [/127.0.0.1:61275] Created subscription on topic persistent://tnx/ns1/sequenceId / subscription
2022-10-07T23:28:12,909 - INFO  - [pulsar-io-17-17:ServerCnx@1474] - [/127.0.0.1:61275] Created new producer: Producer{topic=PersistentTopic{topic=persistent://tnx/ns1/sequenceId}, client=/127.0.0.1:61275, producerName=producer, producerId=0}
2022-10-07T23:28:12,909 - INFO  - [pulsar-client-io-60-1:ConsumerImpl@956] - [tnx/ns1/sequenceId][subscription] Subscribed to topic on localhost/127.0.0.1:61246 -- consumer: 0
2022-10-07T23:28:12,909 - INFO  - [pulsar-client-io-60-1:ProducerImpl@1694] - [tnx/ns1/sequenceId] [producer] Created producer on cnx [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246]
2022-10-07T23:28:12,909 - INFO  - [pulsar-client-io-60-1:ProducerImpl@1875] - [tnx/ns1/sequenceId] [producer] Re-Sending 92 messages to server
2022-10-07T23:28:12,910 - INFO  - [pulsar-client-internal-62-1:TransactionMetaStoreHandler@144] - Transaction coordinator client connect success! tcId : 0
2022-10-07T23:28:12,927 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 536 published by producer 0 has been dropped
2022-10-07T23:28:12,927 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 535 published by producer 0 has been dropped
2022-10-07T23:28:12,927 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 534 published by producer 0 has been dropped
2022-10-07T23:28:12,927 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 533 published by producer 0 has been dropped
2022-10-07T23:28:12,928 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 532 published by producer 0 has been dropped
2022-10-07T23:28:12,928 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 531 published by producer 0 has been dropped
2022-10-07T23:28:12,928 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 530 published by producer 0 has been dropped
2022-10-07T23:28:12,928 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 529 published by producer 0 has been dropped
2022-10-07T23:28:12,928 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 528 published by producer 0 has been dropped
2022-10-07T23:28:12,928 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 527 published by producer 0 has been dropped
2022-10-07T23:28:12,928 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 526 published by producer 0 has been dropped
2022-10-07T23:28:12,928 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 525 published by producer 0 has been dropped
2022-10-07T23:28:12,928 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 524 published by producer 0 has been dropped
2022-10-07T23:28:12,928 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 523 published by producer 0 has been dropped
2022-10-07T23:28:12,928 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 522 published by producer 0 has been dropped
2022-10-07T23:28:12,928 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 521 published by producer 0 has been dropped
2022-10-07T23:28:12,929 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 520 published by producer 0 has been dropped
2022-10-07T23:28:12,929 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 519 published by producer 0 has been dropped
2022-10-07T23:28:12,929 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 518 published by producer 0 has been dropped
2022-10-07T23:28:12,929 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 517 published by producer 0 has been dropped
2022-10-07T23:28:12,929 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 516 published by producer 0 has been dropped
2022-10-07T23:28:12,929 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 515 published by producer 0 has been dropped
2022-10-07T23:28:12,929 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 514 published by producer 0 has been dropped
2022-10-07T23:28:12,929 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 513 published by producer 0 has been dropped
2022-10-07T23:28:12,929 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 512 published by producer 0 has been dropped
2022-10-07T23:28:12,929 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 511 published by producer 0 has been dropped
2022-10-07T23:28:12,929 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 510 published by producer 0 has been dropped
2022-10-07T23:28:12,929 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 509 published by producer 0 has been dropped
2022-10-07T23:28:12,929 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 508 published by producer 0 has been dropped
2022-10-07T23:28:12,929 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 566 published by producer 0 has been dropped
2022-10-07T23:28:12,932 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 565 published by producer 0 has been dropped
2022-10-07T23:28:12,932 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 564 published by producer 0 has been dropped
2022-10-07T23:28:12,932 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 563 published by producer 0 has been dropped
2022-10-07T23:28:12,932 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 562 published by producer 0 has been dropped
2022-10-07T23:28:12,932 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 561 published by producer 0 has been dropped
2022-10-07T23:28:12,933 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 560 published by producer 0 has been dropped
2022-10-07T23:28:12,933 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 559 published by producer 0 has been dropped
2022-10-07T23:28:12,933 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 558 published by producer 0 has been dropped
2022-10-07T23:28:12,933 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 557 published by producer 0 has been dropped
2022-10-07T23:28:12,933 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 556 published by producer 0 has been dropped
2022-10-07T23:28:12,933 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 555 published by producer 0 has been dropped
2022-10-07T23:28:12,933 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 554 published by producer 0 has been dropped
2022-10-07T23:28:12,933 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 553 published by producer 0 has been dropped
2022-10-07T23:28:12,933 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 552 published by producer 0 has been dropped
2022-10-07T23:28:12,933 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 551 published by producer 0 has been dropped
2022-10-07T23:28:12,933 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 550 published by producer 0 has been dropped
2022-10-07T23:28:12,933 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 549 published by producer 0 has been dropped
2022-10-07T23:28:12,933 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 548 published by producer 0 has been dropped
2022-10-07T23:28:12,933 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 547 published by producer 0 has been dropped
2022-10-07T23:28:12,933 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 546 published by producer 0 has been dropped
2022-10-07T23:28:12,934 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 545 published by producer 0 has been dropped
2022-10-07T23:28:12,934 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 544 published by producer 0 has been dropped
2022-10-07T23:28:12,934 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 543 published by producer 0 has been dropped
2022-10-07T23:28:12,934 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 542 published by producer 0 has been dropped
2022-10-07T23:28:12,934 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 541 published by producer 0 has been dropped
2022-10-07T23:28:12,934 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 540 published by producer 0 has been dropped
2022-10-07T23:28:12,934 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 538 published by producer 0 has been dropped
2022-10-07T23:28:12,934 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 539 published by producer 0 has been dropped
2022-10-07T23:28:12,934 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 596 published by producer 0 has been dropped
2022-10-07T23:28:12,934 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 595 published by producer 0 has been dropped
2022-10-07T23:28:12,934 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 594 published by producer 0 has been dropped
2022-10-07T23:28:12,934 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 593 published by producer 0 has been dropped
2022-10-07T23:28:12,934 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 592 published by producer 0 has been dropped
2022-10-07T23:28:12,934 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 591 published by producer 0 has been dropped
2022-10-07T23:28:12,934 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 590 published by producer 0 has been dropped
2022-10-07T23:28:12,935 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 589 published by producer 0 has been dropped
2022-10-07T23:28:12,935 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 588 published by producer 0 has been dropped
2022-10-07T23:28:12,935 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 587 published by producer 0 has been dropped
2022-10-07T23:28:12,935 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 586 published by producer 0 has been dropped
2022-10-07T23:28:12,935 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 585 published by producer 0 has been dropped
2022-10-07T23:28:12,935 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 584 published by producer 0 has been dropped
2022-10-07T23:28:12,935 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 583 published by producer 0 has been dropped
2022-10-07T23:28:12,935 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 582 published by producer 0 has been dropped
2022-10-07T23:28:12,935 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 581 published by producer 0 has been dropped
2022-10-07T23:28:12,935 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 580 published by producer 0 has been dropped
2022-10-07T23:28:12,935 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 579 published by producer 0 has been dropped
2022-10-07T23:28:12,935 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 578 published by producer 0 has been dropped
2022-10-07T23:28:12,935 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 577 published by producer 0 has been dropped
2022-10-07T23:28:12,935 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 576 published by producer 0 has been dropped
2022-10-07T23:28:12,935 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 575 published by producer 0 has been dropped
2022-10-07T23:28:12,935 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 574 published by producer 0 has been dropped
2022-10-07T23:28:12,935 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 573 published by producer 0 has been dropped
2022-10-07T23:28:12,936 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 572 published by producer 0 has been dropped
2022-10-07T23:28:12,936 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 571 published by producer 0 has been dropped
2022-10-07T23:28:12,936 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 570 published by producer 0 has been dropped
2022-10-07T23:28:12,936 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 569 published by producer 0 has been dropped
2022-10-07T23:28:12,936 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 568 published by producer 0 has been dropped
2022-10-07T23:28:12,936 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 598 published by producer 0 has been dropped
2022-10-07T23:28:12,936 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 597 published by producer 0 has been dropped
2022-10-07T23:28:12,936 - WARN  - [pulsar-client-io-60-1:ClientCnx@428] - [id: 0xe5f1d4bf, L:/127.0.0.1:61275 - R:localhost/127.0.0.1:61246] Message with sequence-id 599 published by producer 0 has been dropped

java.util.concurrent.ExecutionException: org.apache.pulsar.client.api.PulsarClientException$ConnectException: Disconnected from server at localhost/127.0.0.1:61246

	at java.base/java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:396)
	at java.base/java.util.concurrent.CompletableFuture.get(CompletableFuture.java:2073)
	at org.apache.pulsar.broker.transaction.TransactionTest.testUpdateSequenceIdInSyncCodeSegment(TransactionTest.java:1574)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:132)
	at org.testng.internal.TestInvoker.invokeMethod(TestInvoker.java:599)
	at org.testng.internal.TestInvoker.invokeTestMethod(TestInvoker.java:174)
	at org.testng.internal.MethodRunner.runInSequence(MethodRunner.java:46)
	at org.testng.internal.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:822)
	at org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:147)
	at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146)
	at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:128)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
	at org.testng.TestRunner.privateRun(TestRunner.java:764)
	at org.testng.TestRunner.run(TestRunner.java:585)
	at org.testng.SuiteRunner.runTest(SuiteRunner.java:384)
	at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:378)
	at org.testng.SuiteRunner.privateRun(SuiteRunner.java:337)
	at org.testng.SuiteRunner.run(SuiteRunner.java:286)
	at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
	at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)
	at org.testng.TestNG.runSuitesSequentially(TestNG.java:1218)
	at org.testng.TestNG.runSuitesLocally(TestNG.java:1140)
	at org.testng.TestNG.runSuites(TestNG.java:1069)
	at org.testng.TestNG.run(TestNG.java:1037)
	at com.intellij.rt.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:66)
	at com.intellij.rt.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:109)
Caused by: org.apache.pulsar.client.api.PulsarClientException$ConnectException: Disconnected from server at localhost/127.0.0.1:61246
	at org.apache.pulsar.client.impl.ClientCnx.channelInactive(ClientCnx.java:290)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:262)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:248)
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelInactive(AbstractChannelHandlerContext.java:241)
	at io.netty.handler.codec.ByteToMessageDecoder.channelInputClosed(ByteToMessageDecoder.java:392)
	at io.netty.handler.codec.ByteToMessageDecoder.channelInactive(ByteToMessageDecoder.java:357)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:262)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:248)
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelInactive(AbstractChannelHandlerContext.java:241)
	at io.netty.channel.DefaultChannelPipeline$HeadContext.channelInactive(DefaultChannelPipeline.java:1405)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:262)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:248)
	at io.netty.channel.DefaultChannelPipeline.fireChannelInactive(DefaultChannelPipeline.java:901)
	at io.netty.channel.AbstractChannel$AbstractUnsafe$7.run(AbstractChannel.java:813)
	at io.netty.util.concurrent.AbstractEventExecutor.runTask(AbstractEventExecutor.java:174)
	at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:167)
	at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:470)
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:500)
	at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:995)
	at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
	at java.base/java.lang.Thread.run(Thread.java:833)


Documentation

  • doc-not-needed
    (Please explain why)

Matching PR in forked repository

PR in forked repository: liangyepianzhou#6

### Motivation
When the producer send message in the multiple thread, the message with the smaller sequenceId can be push later than the message with the bigger sequenceId. Then there will be exception thrown at persistentTopic::publishTxnMessage
### Modification
Move getting sequenceId in the sync code.
@github-actions github-actions bot added the doc-not-needed Your PR changes do not impact docs label Sep 26, 2022
@liangyepianzhou liangyepianzhou changed the title [Fix][client] moving get sequenceId into the sync code segment [fix][client] moving get sequenceId into the sync code segment Oct 10, 2022
@github-actions
Copy link

The pr had no activity for 30 days, mark with Stale label.

@labuladong
Copy link
Contributor

For example we send 4 messages (msg1, msg2, msg3, msg4) to the broker and then the 4 messages may get 4 sequence Id (1, 3, 2, 4)

For your example, is this helpful to reproduce the issue you mentioned?

        producer.newMessage(transaction).value("msg1".getBytes()).sequenceId(1).send();
        producer.newMessage(transaction).value("msg2".getBytes()).sequenceId(3).send();
        producer.newMessage(transaction).value("msg3".getBytes()).sequenceId(2).send();
        producer.newMessage(transaction).value("msg4".getBytes()).sequenceId(4).send();

@github-actions github-actions bot removed the Stale label Nov 21, 2022
@liangyepianzhou
Copy link
Contributor Author

liangyepianzhou commented Nov 21, 2022

For example we send 4 messages (msg1, msg2, msg3, msg4) to the broker and then the 4 messages may get 4 sequence Id (1, 3, 2, 4)

For your example, is this helpful to reproduce the issue you mentioned?

        producer.newMessage(transaction).value("msg1".getBytes()).sequenceId(1).send();
        producer.newMessage(transaction).value("msg2".getBytes()).sequenceId(3).send();
        producer.newMessage(transaction).value("msg3".getBytes()).sequenceId(2).send();
        producer.newMessage(transaction).value("msg4".getBytes()).sequenceId(4).send();

No, it is a sync method. You can reproduce it using the test I provided.

liangyepianzhou added a commit that referenced this pull request Nov 24, 2022
## Motivation
1. fix flaky test #18466 caused by txn async send method
2. decrease run time by optimizing receive method 
## Modification
1. fix flaky test
   * modify `producer.newMessage(txn1).value(("Hello Txn - " + i).getBytes(UTF_8)).sendAsync();` to `producer.newMessage(txn1).value(("Hello Txn - " + i).getBytes(UTF_8)).send();` 
This also can be resolved by #17836 and #18486 later.
2. decrease run time by optimizing receive method 
    * modify
 `    Message<byte[]> message = consumer.receive(5, TimeUnit.SECONDS);
                   Assert.assertNull(message);` to
                   `  Message<byte[]> message = consumer.receive(300, TimeUnit.MILLISECONDS);
                            Assert.assertNull(message);`
   * modify `message = consumer.receive();` to `message = consumer.receive(5, TimeUnit.SECONDS);`
   * keep other `consumer.receive(x, y)` no change.
@congbobo184
Copy link
Contributor

@codelipenghui @gaoran10 @poorbarcode /cc

@codecov-commenter
Copy link

codecov-commenter commented Nov 24, 2022

Codecov Report

Merging #17836 (460a38a) into master (3180a4a) will increase coverage by 3.29%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master   #17836      +/-   ##
============================================
+ Coverage     46.17%   49.47%   +3.29%     
+ Complexity    10359     8272    -2087     
============================================
  Files           703      468     -235     
  Lines         68845    52184   -16661     
  Branches       7382     5564    -1818     
============================================
- Hits          31788    25817    -5971     
+ Misses        33448    23509    -9939     
+ Partials       3609     2858     -751     
Flag Coverage Δ
unittests 49.47% <100.00%> (+3.29%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
.../pulsar/broker/service/AbstractBaseDispatcher.java 60.00% <100.00%> (+2.52%) ⬆️
...sistent/PersistentDispatcherMultipleConsumers.java 58.50% <100.00%> (+6.77%) ⬆️
...ker/service/schema/exceptions/SchemaException.java 60.00% <0.00%> (-40.00%) ⬇️
...g/apache/bookkeeper/mledger/util/StatsBuckets.java 43.75% <0.00%> (-16.67%) ⬇️
...ookkeeper/mledger/impl/ManagedLedgerMBeanImpl.java 53.17% <0.00%> (-9.53%) ⬇️
...ce/schema/validator/StructSchemaDataValidator.java 52.38% <0.00%> (-9.53%) ⬇️
...oker/service/schema/SchemaRegistryServiceImpl.java 62.42% <0.00%> (-2.90%) ⬇️
...ker/resourcegroup/ResourceGroupConfigListener.java 64.38% <0.00%> (-2.74%) ⬇️
...sar/broker/service/schema/SchemaRegistryStats.java 72.50% <0.00%> (-2.50%) ⬇️
...a/org/apache/pulsar/client/impl/RawReaderImpl.java 83.90% <0.00%> (-1.15%) ⬇️
... and 319 more

Copy link
Contributor

@poorbarcode poorbarcode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use msgIdGenerator++ instead of msgIdGeneratorUpdater.getAndIncrement(this) now, right?

lifepuzzlefun pushed a commit to lifepuzzlefun/pulsar that referenced this pull request Dec 9, 2022
## Motivation
1. fix flaky test apache#18466 caused by txn async send method
2. decrease run time by optimizing receive method 
## Modification
1. fix flaky test
   * modify `producer.newMessage(txn1).value(("Hello Txn - " + i).getBytes(UTF_8)).sendAsync();` to `producer.newMessage(txn1).value(("Hello Txn - " + i).getBytes(UTF_8)).send();` 
This also can be resolved by apache#17836 and apache#18486 later.
2. decrease run time by optimizing receive method 
    * modify
 `    Message<byte[]> message = consumer.receive(5, TimeUnit.SECONDS);
                   Assert.assertNull(message);` to
                   `  Message<byte[]> message = consumer.receive(300, TimeUnit.MILLISECONDS);
                            Assert.assertNull(message);`
   * modify `message = consumer.receive();` to `message = consumer.receive(5, TimeUnit.SECONDS);`
   * keep other `consumer.receive(x, y)` no change.
@liangyepianzhou liangyepianzhou merged commit 7e258af into apache:master Dec 13, 2022
Demogorgon314 pushed a commit to Demogorgon314/pulsar that referenced this pull request Dec 26, 2022
…e#17836)

### Motivation
When the producer sends messages in multiple threads, the message with the smaller sequence Id can be pushed later than the message with the bigger sequence Id. 
The `internalSendWithTxnAsync` call `internalSendAsync` Asynchronously when `txn != null`
https://github.com/apache/pulsar/blob/aeb4503be59f9a9450dfd47cf5dfcb375735d064/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ProducerImpl.java#L409
And the `sendAsync` acquire sequence ID is not included in the synchronized block with `serializeAndSendMessage`.
https://github.com/apache/pulsar/blob/aeb4503be59f9a9450dfd47cf5dfcb375735d064/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ProducerImpl.java#L490 
https://github.com/apache/pulsar/blob/aeb4503be59f9a9450dfd47cf5dfcb375735d064/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ProducerImpl.java#L555-L560
For example:
We send 4 messages (msg1, msg2, msg3, msg4)  to the broker and then the 4 messages may get 4 sequence Id (1, 3, 2, 4) which is not in order due to the logic to get the sequence ID and send the message is not in the same synchronous code block.
And then the msg3 with sequence ID 2 will never be persistent successfully. 
### Modification
Add a method to update `sequenceId` and move the method in the sync code.
Via apache#16196 we should update message metadata before computing the message size.
Demogorgon314 pushed a commit to Demogorgon314/pulsar that referenced this pull request Dec 29, 2022
…e#17836)

### Motivation
When the producer sends messages in multiple threads, the message with the smaller sequence Id can be pushed later than the message with the bigger sequence Id. 
The `internalSendWithTxnAsync` call `internalSendAsync` Asynchronously when `txn != null`
https://github.com/apache/pulsar/blob/aeb4503be59f9a9450dfd47cf5dfcb375735d064/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ProducerImpl.java#L409
And the `sendAsync` acquire sequence ID is not included in the synchronized block with `serializeAndSendMessage`.
https://github.com/apache/pulsar/blob/aeb4503be59f9a9450dfd47cf5dfcb375735d064/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ProducerImpl.java#L490 
https://github.com/apache/pulsar/blob/aeb4503be59f9a9450dfd47cf5dfcb375735d064/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ProducerImpl.java#L555-L560
For example:
We send 4 messages (msg1, msg2, msg3, msg4)  to the broker and then the 4 messages may get 4 sequence Id (1, 3, 2, 4) which is not in order due to the logic to get the sequence ID and send the message is not in the same synchronous code block.
And then the msg3 with sequence ID 2 will never be persistent successfully. 
### Modification
Add a method to update `sequenceId` and move the method in the sync code.
Via apache#16196 we should update message metadata before computing the message size.
lifepuzzlefun pushed a commit to lifepuzzlefun/pulsar that referenced this pull request Jan 10, 2023
## Motivation
1. fix flaky test apache#18466 caused by txn async send method
2. decrease run time by optimizing receive method 
## Modification
1. fix flaky test
   * modify `producer.newMessage(txn1).value(("Hello Txn - " + i).getBytes(UTF_8)).sendAsync();` to `producer.newMessage(txn1).value(("Hello Txn - " + i).getBytes(UTF_8)).send();` 
This also can be resolved by apache#17836 and apache#18486 later.
2. decrease run time by optimizing receive method 
    * modify
 `    Message<byte[]> message = consumer.receive(5, TimeUnit.SECONDS);
                   Assert.assertNull(message);` to
                   `  Message<byte[]> message = consumer.receive(300, TimeUnit.MILLISECONDS);
                            Assert.assertNull(message);`
   * modify `message = consumer.receive();` to `message = consumer.receive(5, TimeUnit.SECONDS);`
   * keep other `consumer.receive(x, y)` no change.
lifepuzzlefun pushed a commit to lifepuzzlefun/pulsar that referenced this pull request Jan 10, 2023
…e#17836)

### Motivation
When the producer sends messages in multiple threads, the message with the smaller sequence Id can be pushed later than the message with the bigger sequence Id. 
The `internalSendWithTxnAsync` call `internalSendAsync` Asynchronously when `txn != null`
https://github.com/apache/pulsar/blob/aeb4503be59f9a9450dfd47cf5dfcb375735d064/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ProducerImpl.java#L409
And the `sendAsync` acquire sequence ID is not included in the synchronized block with `serializeAndSendMessage`.
https://github.com/apache/pulsar/blob/aeb4503be59f9a9450dfd47cf5dfcb375735d064/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ProducerImpl.java#L490 
https://github.com/apache/pulsar/blob/aeb4503be59f9a9450dfd47cf5dfcb375735d064/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ProducerImpl.java#L555-L560
For example:
We send 4 messages (msg1, msg2, msg3, msg4)  to the broker and then the 4 messages may get 4 sequence Id (1, 3, 2, 4) which is not in order due to the logic to get the sequence ID and send the message is not in the same synchronous code block.
And then the msg3 with sequence ID 2 will never be persistent successfully. 
### Modification
Add a method to update `sequenceId` and move the method in the sync code.
Via apache#16196 we should update message metadata before computing the message size.
liangyepianzhou added a commit that referenced this pull request Mar 16, 2023
When the producer sends messages in multiple threads, the message with the smaller sequence Id can be pushed later than the message with the bigger sequence Id.
The `internalSendWithTxnAsync` call `internalSendAsync` Asynchronously when `txn != null`
https://github.com/apache/pulsar/blob/aeb4503be59f9a9450dfd47cf5dfcb375735d064/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ProducerImpl.java#L409
And the `sendAsync` acquire sequence ID is not included in the synchronized block with `serializeAndSendMessage`.
https://github.com/apache/pulsar/blob/aeb4503be59f9a9450dfd47cf5dfcb375735d064/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ProducerImpl.java#L490
https://github.com/apache/pulsar/blob/aeb4503be59f9a9450dfd47cf5dfcb375735d064/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ProducerImpl.java#L555-L560
For example:
We send 4 messages (msg1, msg2, msg3, msg4)  to the broker and then the 4 messages may get 4 sequence Id (1, 3, 2, 4) which is not in order due to the logic to get the sequence ID and send the message is not in the same synchronous code block.
And then the msg3 with sequence ID 2 will never be persistent successfully.
Add a method to update `sequenceId` and move the method in the sync code.
Via #16196 we should update message metadata before computing the message size.

(cherry picked from commit 7e258af)
@lhotari lhotari modified the milestones: 2.11.0, 3.0.0 Mar 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants