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

[feat][broker] PIP-180 Part VI: Add ShadowManagedLedgerImpl #18265

Merged
merged 11 commits into from
Nov 29, 2022

Conversation

Jason918
Copy link
Contributor

@Jason918 Jason918 commented Oct 31, 2022

Master Issue: #16153

Motivation

After this PR, the basic function of PIP-180 shadow topic will be ready.

Modifications

  • Add ShadowManagedLedgerImpl

Verifying this change

  • Make sure that the change passes the CI checks.

This change added tests and can be verified as follows:

  • see ShadowTopicTest.java

Does this pull request potentially affect one of the following parts:

If the box was checked, please highlight the changes

  • Dependencies (add or upgrade a dependency)
  • The public API
  • The schema
  • The default values of configurations
  • The threading model
  • The binary protocol
  • The REST endpoints
  • The admin CLI options
  • Anything that affects deployment

Documentation

  • doc
  • doc-required
  • doc-not-needed
  • doc-complete

Matching PR in forked repository

PR in forked repository: Jason918#12

@github-actions github-actions bot added the doc-required Your PR changes impact docs and you will update later. label Oct 31, 2022
@Jason918 Jason918 self-assigned this Oct 31, 2022
@Jason918 Jason918 added type/feature The PR added a new feature or issue requested a new feature area/broker labels Oct 31, 2022
@Jason918 Jason918 added this to the 2.12.0 milestone Oct 31, 2022
@Jason918
Copy link
Contributor Author

/pulsarbot run-failure-checks

@Jason918
Copy link
Contributor Author

@codecov-commenter
Copy link

codecov-commenter commented Nov 15, 2022

Codecov Report

Merging #18265 (536f10a) into master (b579bb8) will decrease coverage by 0.45%.
The diff coverage is 16.34%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master   #18265      +/-   ##
============================================
- Coverage     47.51%   47.06%   -0.46%     
+ Complexity    10520    10457      -63     
============================================
  Files           698      698              
  Lines         68079    68323     +244     
  Branches       7280     7332      +52     
============================================
- Hits          32351    32157     -194     
- Misses        32151    32565     +414     
- Partials       3577     3601      +24     
Flag Coverage Δ
unittests 47.06% <16.34%> (-0.46%) ⬇️

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

Impacted Files Coverage Δ
...apache/bookkeeper/mledger/ManagedLedgerConfig.java 71.60% <0.00%> (-0.90%) ⬇️
.../org/apache/bookkeeper/mledger/impl/MetaStore.java 100.00% <ø> (ø)
...okkeeper/mledger/impl/ShadowManagedLedgerImpl.java 0.00% <0.00%> (ø)
...loadbalance/impl/LeastResourceUsageWithWeight.java 0.00% <0.00%> (ø)
...lsar/broker/loadbalance/impl/ThresholdShedder.java 3.27% <0.00%> (-44.44%) ⬇️
...ersistentStreamingDispatcherMultipleConsumers.java 0.00% <0.00%> (ø)
...istentStreamingDispatcherSingleActiveConsumer.java 0.00% <0.00%> (ø)
...ervice/streamingdispatch/StreamingEntryReader.java 0.00% <0.00%> (ø)
...va/org/apache/pulsar/client/impl/ProducerImpl.java 17.00% <0.00%> (-0.02%) ⬇️
...rg/apache/pulsar/broker/service/BrokerService.java 57.40% <20.00%> (-0.55%) ⬇️
... and 57 more

Copy link
Contributor

@HQebupt HQebupt left a comment

Choose a reason for hiding this comment

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

LGTM

@AnonHxy
Copy link
Contributor

AnonHxy commented Nov 16, 2022

LGTM with minor comments


public ShadowManagedLedgerImpl(ManagedLedgerFactoryImpl factory, BookKeeper bookKeeper,
MetaStore store, ManagedLedgerConfig config,
OrderedScheduler scheduledExecutor,
String name, final Supplier<Boolean> mlOwnershipChecker) {
super(factory, bookKeeper, store, config, scheduledExecutor, name, mlOwnershipChecker);
this.shadowSource = TopicName.get(config.getShadowSource());
this.sourceMLName = shadowSource.getPersistenceNamingEncoding();
if (config.getTopicName().isPartitioned() && TopicName.getPartitionIndex(config.getShadowSource()) == -1) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why the name is not able to be used? It's a little confusing that we need to introduce the topic name in ManagedLedgerConfig

Or maybe we can introduce a properties?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why the name is not able to be used? It's a little confusing that we need to introduce the topic name in ManagedLedgerConfig

Good point.

  1. We need to know the TopicName of the source topic in the shadow topic. But the name here is in the format of PersistenceNamingEncoding.
  2. I get that we'd better not introduce the concept of "topic" into managed-ledger. I will move this logic to the "broker" layer. So that the source topic name is in properties and the managedLedgerName of the source topic is stored in the new field ManagedLedgerConfig.shadowSourceName.

sourceLedgersStat, stat);
}

sourceLedgersStat = stat;
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to check the data version?
Maybe the watcher gets a notification first, and then we get the response from get managed ledger info operation. Will we add the deleted ledger back?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice catch. Added a version check.

sourceLedgersStat = stat;

if (mlInfo.hasTerminatedPosition()) {
state = State.Terminated;
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you need Terminated state for a shadow ledger? If the source topic changes to the terminated state, the shadow topic will not get any new messages.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not needed actually, just keeping the original logic at first.
After another thought, we should remove this, because the source topic can be terminated but the replication to the shadow topic should go on.
So comes these updates:

  1. Removed Terminated state from ShadowManagedLedger.
  2. Overrides asyncTerminate and return fail directly.

Comment on lines 240 to 244
if (state == State.Terminated) {
addOperation.failed(new ManagedLedgerException.ManagedLedgerTerminatedException(
"Managed ledger was already terminated"));
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like we don't need to check if the topic is terminated.
And if the broker receives the zookeeper notification first, then the shadow topic changes to the terminated state. But the shadow replicator hasn't reached the end of the source topic. In this case, the consumer connected to the shadow topic will have a different view.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, exactly.

currentLedgerEntries = position.getEntryId();
currentLedgerSize += addOperation.data.readableBytes();
addOperation.initiateShadowWrite();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

How about the position's ledger ID that is not equal to the current ledger ID? It looks like the addOperation will never be complete.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed, and add ut in ShadowManagedLedgerImplTest

@Jason918
Copy link
Contributor Author

@codelipenghui Comments all addressed. PTAL.

- finish processSourceManagedLedgerInfo
- finish internalAsyncAddEntry
- ShadowTopicTest pass
- ShadowReplicatorTest pass

Add test cases
@Jason918 Jason918 merged commit 5b062f3 into apache:master Nov 29, 2022
lifepuzzlefun pushed a commit to lifepuzzlefun/pulsar that referenced this pull request Dec 9, 2022
lifepuzzlefun pushed a commit to lifepuzzlefun/pulsar that referenced this pull request Jan 10, 2023
@momo-jun
Copy link
Contributor

Hi @Jason918, do you have any updates for documenting this feature?
Since 2.11 has been released, now it's good timing to start the doc update in the next version.

@Jason918
Copy link
Contributor Author

Hi @Jason918, do you have any updates for documenting this feature?
Since 2.11 has been released, now it's good timing to start the doc update in the next version.

@momo-jun Thanks for the reminding, I will try to come up with the doc update before the 3.0.0 release.

@Jason918 Jason918 deleted the pip-180-dev branch February 17, 2023 02:26
@StevenLuMT
Copy link
Member

Hi @Jason918, do you have any updates for documenting this feature?
Since 2.11 has been released, now it's good timing to start the doc update in the next version.

@momo-jun Thanks for the reminding, I will try to come up with the doc update before the 3.0.0 release.

@momo-jun I have communicated with @Jason918 , I'll help him update the documentation

@momo-jun
Copy link
Contributor

Thanks @Jason918 @StevenLuMT. Feel free to ping me if you need any assistance with docs.

@StevenLuMT
Copy link
Member

Thanks @Jason918 @StevenLuMT. Feel free to ping me if you need any assistance with docs.

Thanks @momo-jun ,my WeChat ID is 863199780, add me, keep fast communication

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/broker doc-required Your PR changes impact docs and you will update later. ready-to-test type/feature The PR added a new feature or issue requested a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants