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

[Managed Ledger] Fix the incorrect total size when BrokerEntryMetadata is enabled #12714

Conversation

BewareMyPower
Copy link
Contributor

@BewareMyPower BewareMyPower commented Nov 10, 2021

Motivation

When the BrokerEntryMetadata is enabled, the total size in ManagedLedgerImpl is inaccurate. Because when the total size is updated in OpAddEntry#safeRun, the dataLength is the initial size of data when OpAddEntry is constructed, but data could be changed via setData method.

The inaccurate total size could affect the retention size validation. Because in ManagedLedgerImpl#internalTrimLedgers, the total size reduces by the size of LedgerInfo, which is assigned from the LedgerHandle#getLength(). Therefore, the total size will become 0 or less before all ledgers are removed.

Modifications

  • Update dataLength field in setData method.
  • Add a testManagedLedgerTotalSize test to BrokerEntryMetadataE2ETest. It produces 10 messages and trigger the rollover manually so that the first LedgerInfo of the managed ledger contains the correct total bytes. Then compare the totalSize field with it to verify this fix works.

Verifying this change

  • Make sure that the change passes the CI checks.

This change added test BrokerEntryMetadataE2ETest#testManagedLedgerTotalSize.

@BewareMyPower BewareMyPower self-assigned this Nov 10, 2021
@BewareMyPower BewareMyPower added doc-not-needed Your PR changes do not impact docs area/broker release/2.8.3 release/2.9.1 type/bug The PR fixed a bug or issue reported a bug labels Nov 10, 2021
@codelipenghui
Copy link
Contributor

@BewareMyPower

but data could be changed via setData method.

Can we update the dataLength when calling setData()? We might get different value by readableBytes() which there is a reader read the data from the buffer.

@eolivelli
Copy link
Contributor

@BewareMyPower

but data could be changed via setData method.

Can we update the dataLength when calling setData()? We might get different value by readableBytes() which there is a reader read the data from the buffer.

+1

@BewareMyPower BewareMyPower added this to the 2.10.0 milestone Nov 10, 2021
@BewareMyPower
Copy link
Contributor Author

@codelipenghui @eolivelli done.

Copy link
Contributor

@codelipenghui codelipenghui left a comment

Choose a reason for hiding this comment

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

Nice catch!

@BewareMyPower BewareMyPower merged commit 5dbb7d2 into apache:master Nov 11, 2021
@BewareMyPower BewareMyPower deleted the bewaremypower/fix-total-size-broker-meta branch November 11, 2021 09:46
nicoloboschi pushed a commit to datastax/pulsar that referenced this pull request Nov 11, 2021
…a is enabled (apache#12714)

### Motivation

When the BrokerEntryMetadata is enabled, the total size in `ManagedLedgerImpl` is inaccurate. Because when the total size is updated in `OpAddEntry#safeRun`, the `dataLength` is the initial size of `data` when `OpAddEntry` is constructed, but `data` could be changed via `setData` method.

The inaccurate total size could affect the retention size validation. Because in `ManagedLedgerImpl#internalTrimLedgers`, the total size reduces by the size of `LedgerInfo`, which is assigned from the `LedgerHandle#getLength()`. Therefore, the total size will become 0 or less before all ledgers are removed.

### Modifications

- Update `dataLength` field in `setData` method.
- Add a `testManagedLedgerTotalSize` test to `BrokerEntryMetadataE2ETest`. It produces 10 messages and trigger the rollover manually so that the first `LedgerInfo` of the managed ledger contains the correct total bytes. Then compare the `totalSize` field with it to verify this fix works.

(cherry picked from commit 5dbb7d2)
codelipenghui pushed a commit that referenced this pull request Nov 18, 2021
…a is enabled (#12714)

### Motivation

When the BrokerEntryMetadata is enabled, the total size in `ManagedLedgerImpl` is inaccurate. Because when the total size is updated in `OpAddEntry#safeRun`, the `dataLength` is the initial size of `data` when `OpAddEntry` is constructed, but `data` could be changed via `setData` method.

The inaccurate total size could affect the retention size validation. Because in `ManagedLedgerImpl#internalTrimLedgers`, the total size reduces by the size of `LedgerInfo`, which is assigned from the `LedgerHandle#getLength()`. Therefore, the total size will become 0 or less before all ledgers are removed.

### Modifications

- Update `dataLength` field in `setData` method.
- Add a `testManagedLedgerTotalSize` test to `BrokerEntryMetadataE2ETest`. It produces 10 messages and trigger the rollover manually so that the first `LedgerInfo` of the managed ledger contains the correct total bytes. Then compare the `totalSize` field with it to verify this fix works.

(cherry picked from commit 5dbb7d2)
@codelipenghui codelipenghui added cherry-picked/branch-2.8 Archived: 2.8 is end of life release/2.8.2 and removed release/2.8.3 labels Nov 18, 2021
eolivelli pushed a commit to eolivelli/pulsar that referenced this pull request Nov 29, 2021
…a is enabled (apache#12714)

### Motivation

When the BrokerEntryMetadata is enabled, the total size in `ManagedLedgerImpl` is inaccurate. Because when the total size is updated in `OpAddEntry#safeRun`, the `dataLength` is the initial size of `data` when `OpAddEntry` is constructed, but `data` could be changed via `setData` method.

The inaccurate total size could affect the retention size validation. Because in `ManagedLedgerImpl#internalTrimLedgers`, the total size reduces by the size of `LedgerInfo`, which is assigned from the `LedgerHandle#getLength()`. Therefore, the total size will become 0 or less before all ledgers are removed.

### Modifications

- Update `dataLength` field in `setData` method.
- Add a `testManagedLedgerTotalSize` test to `BrokerEntryMetadataE2ETest`. It produces 10 messages and trigger the rollover manually so that the first `LedgerInfo` of the managed ledger contains the correct total bytes. Then compare the `totalSize` field with it to verify this fix works.
eolivelli pushed a commit that referenced this pull request Dec 15, 2021
…a is enabled (#12714)

### Motivation

When the BrokerEntryMetadata is enabled, the total size in `ManagedLedgerImpl` is inaccurate. Because when the total size is updated in `OpAddEntry#safeRun`, the `dataLength` is the initial size of `data` when `OpAddEntry` is constructed, but `data` could be changed via `setData` method.

The inaccurate total size could affect the retention size validation. Because in `ManagedLedgerImpl#internalTrimLedgers`, the total size reduces by the size of `LedgerInfo`, which is assigned from the `LedgerHandle#getLength()`. Therefore, the total size will become 0 or less before all ledgers are removed.

### Modifications

- Update `dataLength` field in `setData` method.
- Add a `testManagedLedgerTotalSize` test to `BrokerEntryMetadataE2ETest`. It produces 10 messages and trigger the rollover manually so that the first `LedgerInfo` of the managed ledger contains the correct total bytes. Then compare the `totalSize` field with it to verify this fix works.

(cherry picked from commit 5dbb7d2)
@codelipenghui codelipenghui added cherry-picked/branch-2.9 Archived: 2.9 is end of life release/2.9.1 and removed release/2.9.2 labels Dec 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/broker cherry-picked/branch-2.8 Archived: 2.8 is end of life cherry-picked/branch-2.9 Archived: 2.9 is end of life doc-not-needed Your PR changes do not impact docs release/2.8.2 release/2.9.1 type/bug The PR fixed a bug or issue reported a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants