Skip to content

Conversation

@315157973
Copy link
Contributor

@315157973 315157973 commented Jan 2, 2024

Fixes #21347

Motivation

When the client machine's clock is incorrect (eg: set to 1 year later) and the Broker does not set the AppendBrokerTimestampMetadataInterceptor, the Ledger will not be cleaned up.
Because if the Broker's timestamp is not set, the expiration check will be based on the client's publish time.

Modifications

Always set the Broker's timestamp

Verifying this change

  • Make sure that the change passes the CI checks.

Documentation

  • doc-not-needed

Matching PR in forked repository

PR in forked repository: 315157973#12

@315157973 315157973 self-assigned this Jan 2, 2024
@github-actions github-actions bot added the doc-not-needed Your PR changes do not impact docs label Jan 2, 2024
@315157973 315157973 changed the title Fix messages could not expire due to incorrect client clock [fix][broker] Fix messages could not expire due to incorrect client clock Jan 2, 2024
@Technoboy- Technoboy- added this to the 3.3.0 milestone Jan 2, 2024
@Technoboy- Technoboy- closed this Jan 2, 2024
@Technoboy- Technoboy- reopened this Jan 2, 2024
@codecov-commenter
Copy link

codecov-commenter commented Jan 2, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 74.54%. Comparing base (bbc6224) to head (2f97734).
Report is 520 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##             master   #21835      +/-   ##
============================================
+ Coverage     73.57%   74.54%   +0.96%     
- Complexity    32624    34145    +1521     
============================================
  Files          1877     1920      +43     
  Lines        139502   144467    +4965     
  Branches      15299    15806     +507     
============================================
+ Hits         102638   107690    +5052     
+ Misses        28908    28519     -389     
- Partials       7956     8258     +302     
Flag Coverage Δ
inttests 27.58% <0.00%> (+3.00%) ⬆️
systests 24.74% <0.00%> (+0.42%) ⬆️
unittests 73.88% <100.00%> (+1.04%) ⬆️

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

Files Coverage Δ
...va/org/apache/pulsar/common/protocol/Commands.java 91.14% <100.00%> (+0.54%) ⬆️

... and 491 files with indirect coverage changes

Copy link
Member

@lhotari lhotari left a comment

Choose a reason for hiding this comment

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

Please also fix another issue with the reuse of the brokerEntryMetadata.
Replace BrokerEntryMetadata brokerEntryMetadata = BROKER_ENTRY_METADATA.get(); with BrokerEntryMetadata brokerEntryMetadata = BROKER_ENTRY_METADATA.get().clear(); (append .clear()) to ensure that the brokerTimestamp doesn't get reused from the previous time the instance was used. Otherwise the timestamp would never get updated.

@lhotari
Copy link
Member

lhotari commented Jan 2, 2024

Please also update the comment in org.apache.pulsar.common.protocol.Commands#getEntryTimestamp . I guess that now the BrokerEntryMetadata with the timestamp will always be added as long as broker entry metadata is enabled (any interceptor is enabled)?

if (isBrokerEntryMetadataEnabled() || isBrokerPayloadProcessorEnabled()) {
// init managedLedger interceptor
Set<BrokerEntryMetadataInterceptor> interceptors = new HashSet<>();
for (BrokerEntryMetadataInterceptor interceptor : brokerEntryMetadataInterceptors) {
// add individual AppendOffsetMetadataInterceptor for each topic
if (interceptor instanceof AppendIndexMetadataInterceptor) {
interceptors.add(new AppendIndexMetadataInterceptor());
} else {
interceptors.add(interceptor);
}
}
managedLedgerConfig.setManagedLedgerInterceptor(
new ManagedLedgerInterceptorImpl(interceptors, brokerEntryPayloadProcessors));
}

Comment on lines +1707 to +1709
if (!brokerEntryMetadata.hasBrokerTimestamp()) {
brokerEntryMetadata.setBrokerTimestamp(System.currentTimeMillis());
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The broker timestamp will be set in line:1702 if the AppendBrokerTimestampMetadataInterceptor is enabled. Is this PR wants to set the broker timestamp without AppendBrokerTimestampMetadataInterceptor enabled?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unless we can ensure that the AppendBrokerTimestampMetadataInterceptor cannot be disabled, this bug may always occur

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, I think we can either make the AppendBrokerTimestampMetadataInterceptor enabled by default or remove the AppendBrokerTimestampMetadataInterceptor to always apply the broker timestamp.

Without this change, the broker timestamp will be enabled without AppendBrokerTimestampMetadataInterceptor. Essentially, we delete the functionality of the AppendBrokerTimestampMetadataInterceptor.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@coderzc coderzc modified the milestones: 3.3.0, 3.4.0 May 8, 2024
@315157973
Copy link
Contributor Author

As #21940 is merged, close this PR

@315157973 315157973 closed this Aug 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

6 participants