-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Pipe: Do not listen to tsFiles when no sources need #17669
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
Open
Caideyipi
wants to merge
2
commits into
master
Choose a base branch
from
assigner
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+135
−35
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,7 +34,6 @@ | |
| import java.util.Objects; | ||
| import java.util.concurrent.ConcurrentHashMap; | ||
| import java.util.concurrent.ConcurrentMap; | ||
| import java.util.concurrent.atomic.AtomicInteger; | ||
|
|
||
| /** | ||
| * PipeInsertionEventListener is a singleton in each data node. | ||
|
|
@@ -51,23 +50,18 @@ public class PipeInsertionDataNodeListener { | |
| private final ConcurrentMap<Integer, PipeDataRegionAssigner> dataRegionId2Assigner = | ||
| new ConcurrentHashMap<>(); | ||
|
|
||
| private final AtomicInteger listenToTsFileSourceCount = new AtomicInteger(0); | ||
| private final AtomicInteger listenToInsertNodeSourceCount = new AtomicInteger(0); | ||
|
|
||
| //////////////////////////// start & stop //////////////////////////// | ||
|
|
||
| public synchronized void startListenAndAssign( | ||
| final int dataRegionId, final PipeRealtimeDataRegionSource source) { | ||
| dataRegionId2Assigner | ||
| .computeIfAbsent(dataRegionId, o -> new PipeDataRegionAssigner(dataRegionId)) | ||
| .startAssignTo(source); | ||
|
|
||
| if (source.isNeedListenToTsFile()) { | ||
| listenToTsFileSourceCount.incrementAndGet(); | ||
| } | ||
| if (source.isNeedListenToInsertNode()) { | ||
| listenToInsertNodeSourceCount.incrementAndGet(); | ||
| } | ||
| dataRegionId2Assigner.compute( | ||
| dataRegionId, | ||
| (id, assigner) -> { | ||
| final PipeDataRegionAssigner actualAssigner = | ||
| assigner == null ? new PipeDataRegionAssigner(dataRegionId) : assigner; | ||
| actualAssigner.startAssignTo(source); | ||
| return actualAssigner; | ||
| }); | ||
| } | ||
|
Comment on lines
+57
to
65
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ComputeIfAbsent? |
||
|
|
||
| public synchronized void stopListenAndAssign( | ||
|
|
@@ -82,13 +76,6 @@ public synchronized void stopListenAndAssign( | |
|
|
||
| assigner.stopAssignTo(source); | ||
|
|
||
| if (source.isNeedListenToTsFile()) { | ||
| listenToTsFileSourceCount.decrementAndGet(); | ||
| } | ||
| if (source.isNeedListenToInsertNode()) { | ||
| listenToInsertNodeSourceCount.decrementAndGet(); | ||
| } | ||
|
|
||
| if (assigner.notMoreSourceNeededToBeAssigned()) { | ||
| // The removed assigner will is the same as the one referenced by the variable `assigner` | ||
| dataRegionId2Assigner.remove(dataRegionId); | ||
|
|
@@ -110,14 +97,10 @@ public void listenToTsFile( | |
| final String databaseName, | ||
| final TsFileResource tsFileResource, | ||
| final boolean isLoaded) { | ||
| // We don't judge whether listenToTsFileSourceCount.get() == 0 here on purpose | ||
| // because spirces may use tsfile events when some exceptions occur in the | ||
| // insert nodes listening process. | ||
|
|
||
| final PipeDataRegionAssigner assigner = dataRegionId2Assigner.get(dataRegionId); | ||
|
|
||
| // only events from registered data region will be extracted | ||
| if (assigner == null) { | ||
| // only events from registered data region with tsfile listeners will be extracted | ||
| if (assigner == null || !assigner.shouldListenToTsFile()) { | ||
| return; | ||
| } | ||
|
|
||
|
|
@@ -131,14 +114,10 @@ public void listenToInsertNode( | |
| final String databaseName, | ||
| final InsertNode insertNode, | ||
| final TsFileResource tsFileResource) { | ||
| if (listenToInsertNodeSourceCount.get() == 0) { | ||
| return; | ||
| } | ||
|
|
||
| final PipeDataRegionAssigner assigner = dataRegionId2Assigner.get(dataRegionId); | ||
|
|
||
| // only events from registered data region will be extracted | ||
| if (assigner == null) { | ||
| // only events from registered data region with insert listeners will be extracted | ||
| if (assigner == null || !assigner.shouldListenToInsertNode()) { | ||
| return; | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Necessary to synchronize?