Skip to content

[Bug] Pulsar broker prints mac mismatch error when read entry from Bookkeeper #24464

Closed

Description

@dao-jun

Search before reporting

  • I searched in the issues and found nothing similar.

Read release policy

  • I understand that unsupported versions don't get bug fixes. I will attempt to reproduce the issue on a supported version of Pulsar client and Pulsar broker.

User environment

Pulsar broker 3.0.12 with KoP
Bookkeeper 4.16.4

Issue Description

We set TTL and retention to retain 1 day data.
And set bookkeeperClientTimeoutInSeconds, managedLedgerAddEntryTimeoutSeconds and managedLedgerReadEntryTimeoutSeconds to 30.

We found some error logs in our broker:

2025-06-05T23:34:15,638+0800 [BookKeeperClientWorker-OrderedExecutor-87-0] ERROR org.apache.bookkeeper.proto.checksum.DigestManager - Digest mismatch for ledger-id: 6545646, entry-id: 9085
2025-06-05T23:34:46,814+0800 [BookKeeperClientWorker-OrderedExecutor-87-0] ERROR org.apache.bookkeeper.proto.checksum.DigestManager - Digest mismatch for ledger-id: 6545646, entry-id: 10208
2025-06-05T23:35:08,865+0800 [BookKeeperClientWorker-OrderedExecutor-89-0] ERROR org.apache.bookkeeper.proto.checksum.DigestManager - Digest mismatch for ledger-id: 6546035, entry-id: 2226
2025-06-05T23:36:20,565+0800 [BookKeeperClientWorker-OrderedExecutor-68-0] ERROR org.apache.bookkeeper.proto.checksum.DigestManager - Digest mismatch for ledger-id: 6545801, entry-id: 5954
2025-06-05T23:36:22,456+0800 [BookKeeperClientWorker-OrderedExecutor-68-0] ERROR org.apache.bookkeeper.proto.checksum.DigestManager - Digest mismatch for ledger-id: 6545801, entry-id: 5971
2025-06-05T23:38:13,132+0800 [BookKeeperClientWorker-OrderedExecutor-24-0] ERROR org.apache.bookkeeper.proto.checksum.DigestManager - Digest mismatch for ledger-id: 6538416, entry-id: 7660
2025-06-05T23:39:07,811+0800 [BookKeeperClientWorker-OrderedExecutor-24-0] ERROR org.apache.bookkeeper.proto.checksum.DigestManager - Digest mismatch for ledger-id: 6538416, entry-id: 8212
2025-06-05T23:40:50,904+0800 [BookKeeperClientWorker-OrderedExecutor-24-0] ERROR org.apache.bookkeeper.proto.checksum.DigestManager - Digest mismatch for ledger-id: 6538416, entry-id: 9090
2025-06-05T23:41:18,761+0800 [BookKeeperClientWorker-OrderedExecutor-0-0] ERROR org.apache.bookkeeper.proto.checksum.DigestManager - Digest mismatch for ledger-id: 6546049, entry-id: 2173
2025-06-05T23:41:29,022+0800 [BookKeeperClientWorker-OrderedExecutor-65-0] ERROR org.apache.bookkeeper.proto.checksum.DigestManager - Digest mismatch for ledger-id: 6547331, entry-id: 726
2025-06-05T23:42:43,723+0800 [BookKeeperClientWorker-OrderedExecutor-4-0] ERROR org.apache.bookkeeper.proto.checksum.DigestManager - Digest mismatch for ledger-id: 6539528, entry-id: 1928
2025-06-05T23:44:05,167+0800 [BookKeeperClientWorker-OrderedExecutor-2-0] ERROR org.apache.bookkeeper.proto.checksum.DigestManager - Digest mismatch for ledger-id: 6547588, entry-id: 1048
2025-06-05T23:44:17,130+0800 [BookKeeperClientWorker-OrderedExecutor-65-0] ERROR org.apache.bookkeeper.proto.checksum.DigestManager - Digest mismatch for ledger-id: 6547331, entry-id: 1454
2025-06-05T23:44:24,529+0800 [BookKeeperClientWorker-OrderedExecutor-2-0] ERROR org.apache.bookkeeper.proto.checksum.DigestManager - Digest mismatch for ledger-id: 6547588, entry-id: 2122
2025-06-05T23:45:30,965+0800 [BookKeeperClientWorker-OrderedExecutor-42-0] ERROR org.apache.bookkeeper.proto.checksum.DigestManager - Digest mismatch for ledger-id: 6539604, entry-id: 3122
2025-06-05T23:46:20,720+0800 [BookKeeperClientWorker-OrderedExecutor-42-0] ERROR org.apache.bookkeeper.proto.checksum.DigestManager - Digest mismatch for ledger-id: 6539604, entry-id: 3766
2025-06-05T23:51:59,317+0800 [BookKeeperClientWorker-OrderedExecutor-77-0] ERROR org.apache.bookkeeper.proto.checksum.DigestManager - Digest mismatch for ledger-id: 6547354, entry-id: 7198
2025-06-05T23:54:28,204+0800 [BookKeeperClientWorker-OrderedExecutor-19-0] ERROR org.apache.bookkeeper.proto.checksum.DigestManager - Digest mismatch for ledger-id: 6547622, entry-id: 5642
2025-06-05T23:55:04,648+0800 [BookKeeperClientWorker-OrderedExecutor-42-0] ERROR org.apache.bookkeeper.proto.checksum.DigestManager - Digest mismatch for ledger-id: 6539604, entry-id: 12005
2025-06-05T23:59:35,261+0800 [BookKeeperClientWorker-OrderedExecutor-65-0] ERROR org.apache.bookkeeper.proto.checksum.DigestManager - Digest mismatch for ledger-id: 6547331, entry-id: 5605

Error messages


Reproducing the issue

NONE

Additional information

No response

Are you willing to submit a PR?

  • I'm willing to submit a PR!

Activity

  1. added
    type/bug
    on Jun 25, 2025
  2. changed the title [-][Bug] Pulsar broker mac mismatch when read entry from Bookkeeper[/-] [+][Bug] Pulsar broker prints mac mismatch error when read entry from Bookkeeper[/+] on Jun 25, 2025
  3. dao-jun commented on Jun 25, 2025

    @dao-jun
    MemberAuthor

    related to:
    #21421

  4. dao-jun commented on Jun 25, 2025

    @dao-jun
    MemberAuthor

    @lhotari

    The problem reminds of issues that I faced in
    #10738 along time ago. The problem is
    most likely different, but that might give some ideas of ways to reproduce the issue.
    Do you get any sign of IllegalReferenceCountException in logs as a result of double releasing buffers?

    I dont find memory leaks and IllegalReferenceCountException in the broker side, seems it's not caused by memory leak.

    Do you happen to have a ManagedLedgerInterceptor configured?

    We are using KoP, so we have a AppendIndexMetadataInterceptor.

    When looking at the code, I think I see multiple concerns in the OpAddEntry.run method and using timeouts.
    It seems that the currentLedgerTimeoutTriggered solution added in #22221 is
    incomplete.
    I don't see how things could work properly when managedLedgerAddEntryTimeoutSeconds is enabled. We can continue to
    discuss that on the new GitHub issue.

    I've read the code, seems it will not release the ByteBuf before write to Bookie, I personally think it's fine

  5. lhotari commented on Jun 25, 2025

    @lhotari
    Member

    We are using KoP, so we have a AppendIndexMetadataInterceptor.

    @dao-jun I think @BewareMyPower might be aware of issues with this. perhaps something related to your previous discussion in #23940 (comment) . Possibly also related to #24109.

  6. gaozhangmin commented on Jul 21, 2025

    @gaozhangmin
    Contributor

    @lhotari @dao-jun

    This issue is not a pulsar issue. it's kop's issue.

    The offset field in Kafka messages has been modified due to Pulsar's write cache, which caches the message body from the business logic. For tailing consumers, messages are read directly from the Pulsar cache. Since the BookKeeper client is configured with ack=1, a message becomes visible to consumers once it is written to a single replica. This can lead to a race condition: an entry is successfully written to bk1 (CRC check completed), and the consumer retrieves the message from the cache and sets the start offset. However, when the entry is later written to bk2, the two replicas may end up with inconsistent message content.

    https://github.com/streamnative/kop/blob/14f9832d8a437c5b717e3c74fd7e4cda9810aff7/kafka-impl/src/main/java/io/streamnative/pulsar/handlers/kop/format/AbstractEntryFormatter.java#L70C21-L70C28

  7. BewareMyPower commented on Jul 21, 2025

    @BewareMyPower
    Contributor

    Yes, this issue can be resolved by creating a short buffer rather than modifying the original entry's buffer like https://github.com/streamnative/kop/blob/14f9832d8a437c5b717e3c74fd7e4cda9810aff7/kafka-impl/src/main/java/io/streamnative/pulsar/handlers/kop/format/AbstractEntryFormatter.java#L70

    In our internal fork (KSN), it's fixed by adding a buffer list abstraction:

        private final List<ByteBuf> bufferList;
    
        public void addLong(long value) {
            final var buffer = ALLOCATOR.buffer(8);
            bufferList.add(buffer);
            buffer.writeLong(value);
        }
    
        public void addSlice(ByteBuf buffer, int startOffset) {
            bufferList.add(buffer.retainedSlice(buffer.readerIndex() + startOffset, buffer.readableBytes() - startOffset));
        }

    and merge the buffers added in addLong and addSlice.

    kafkaBuffers.addLong(startOffset);
    kafkaBuffers.addSlice(byteBuf, OFFSET_LENGTH);
    final var batchedByteBuf = kafkaBuffers.merge(); // the merged buffer
  8. gaozhangmin commented on Jul 22, 2025

    @gaozhangmin
    Contributor

    We can close this issue now, since it's not a pulsar issue

  9. dao-jun commented on Jul 22, 2025

    @dao-jun
    MemberAuthor

    @gaozhangmin @BewareMyPower Thanks for your sharing, it would helps a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type/bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions