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
Add epoch for connection handler to handle create producer timeout. #5571
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
08fd3ed
Add epoch for connection handler to handle create producer timeout.
codelipenghui edae5d1
Fix comments
codelipenghui 760b5b3
Avoid iterating over the producers map
codelipenghui 38ebf2a
Fix unit tests issue
codelipenghui 56764ce
Add concurrent update check.
codelipenghui 7fc26ea
Fix unit tests.
codelipenghui File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 |
---|---|---|
|
@@ -367,7 +367,7 @@ public synchronized void addFailed(ManagedLedgerException exception, Object ctx) | |
isFenced = true; | ||
// close all producers | ||
List<CompletableFuture<Void>> futures = Lists.newArrayList(); | ||
producers.forEach(producer -> futures.add(producer.disconnect())); | ||
producers.values().forEach(producer -> futures.add(producer.disconnect())); | ||
FutureUtil.waitForAll(futures).handle((BiFunction<Void, Throwable, Void>) (aVoid, throwable) -> { | ||
decrementPendingWriteOpsAndCheck(); | ||
return null; | ||
|
@@ -424,9 +424,20 @@ public void addProducer(Producer producer) throws BrokerServiceException { | |
log.debug("[{}] {} Got request to create producer ", topic, producer.getProducerName()); | ||
} | ||
|
||
if (!producers.add(producer)) { | ||
throw new NamingException( | ||
"Producer with name '" + producer.getProducerName() + "' is already connected to topic"); | ||
Producer existProducer = producers.putIfAbsent(producer.getProducerName(), producer); | ||
if (existProducer != null) { | ||
boolean canOverwrite = false; | ||
if (existProducer.equals(producer) && !existProducer.isUserProvidedProducerName() | ||
&& !producer.isUserProvidedProducerName() && producer.getEpoch() > existProducer.getEpoch()) { | ||
existProducer.close(); | ||
canOverwrite = true; | ||
} | ||
if (canOverwrite) { | ||
producers.put(producer.getProducerName(), producer); | ||
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. use replace and check the return result |
||
} else { | ||
throw new NamingException( | ||
"Producer with name '" + producer.getProducerName() + "' is already connected to topic"); | ||
} | ||
} | ||
|
||
USAGE_COUNT_UPDATER.incrementAndGet(this); | ||
|
@@ -445,7 +456,7 @@ public void addProducer(Producer producer) throws BrokerServiceException { | |
|
||
private boolean hasRemoteProducers() { | ||
AtomicBoolean foundRemote = new AtomicBoolean(false); | ||
producers.forEach(producer -> { | ||
producers.values().forEach(producer -> { | ||
if (producer.isRemote()) { | ||
foundRemote.set(true); | ||
} | ||
|
@@ -491,7 +502,8 @@ private synchronized CompletableFuture<Void> closeReplProducersIfNoBacklog() { | |
@Override | ||
public void removeProducer(Producer producer) { | ||
checkArgument(producer.getTopic() == this); | ||
if (producers.remove(producer)) { | ||
|
||
if (producers.remove(producer.getProducerName(), producer)) { | ||
// decrement usage only if this was a valid producer close | ||
USAGE_COUNT_UPDATER.decrementAndGet(this); | ||
if (log.isDebugEnabled()) { | ||
|
@@ -825,7 +837,7 @@ private CompletableFuture<Void> delete(boolean failIfHasSubscriptions, | |
if (closeIfClientsConnected) { | ||
List<CompletableFuture<Void>> futures = Lists.newArrayList(); | ||
replicators.forEach((cluster, replicator) -> futures.add(replicator.disconnect())); | ||
producers.forEach(producer -> futures.add(producer.disconnect())); | ||
producers.values().forEach(producer -> futures.add(producer.disconnect())); | ||
subscriptions.forEach((s, sub) -> futures.add(sub.disconnect())); | ||
FutureUtil.waitForAll(futures).thenRun(() -> { | ||
closeClientFuture.complete(null); | ||
|
@@ -935,7 +947,7 @@ public CompletableFuture<Void> close() { | |
List<CompletableFuture<Void>> futures = Lists.newArrayList(); | ||
|
||
replicators.forEach((cluster, replicator) -> futures.add(replicator.disconnect())); | ||
producers.forEach(producer -> futures.add(producer.disconnect())); | ||
producers.values().forEach(producer -> futures.add(producer.disconnect())); | ||
subscriptions.forEach((s, sub) -> futures.add(sub.disconnect())); | ||
|
||
FutureUtil.waitForAll(futures).thenRun(() -> { | ||
|
@@ -1277,7 +1289,7 @@ public void updateRates(NamespaceStats nsStats, NamespaceBundleStats bundleStats | |
|
||
// start publisher stats | ||
topicStatsStream.startList("publishers"); | ||
producers.forEach(producer -> { | ||
producers.values().forEach(producer -> { | ||
producer.updateRates(); | ||
PublisherStats publisherStats = producer.getStats(); | ||
|
||
|
@@ -1464,7 +1476,7 @@ public TopicStats getStats() { | |
|
||
ObjectObjectHashMap<String, PublisherStats> remotePublishersStats = new ObjectObjectHashMap<String, PublisherStats>(); | ||
|
||
producers.forEach(producer -> { | ||
producers.values().forEach(producer -> { | ||
PublisherStats publisherStats = producer.getStats(); | ||
stats.msgRateIn += publisherStats.msgRateIn; | ||
stats.msgThroughputIn += publisherStats.msgThroughputIn; | ||
|
@@ -1696,7 +1708,7 @@ public CompletableFuture<Void> onPoliciesUpdate(Policies data) { | |
|
||
this.updateMaxPublishRate(data); | ||
|
||
producers.forEach(producer -> { | ||
producers.values().forEach(producer -> { | ||
producer.checkPermissions(); | ||
producer.checkEncryption(); | ||
}); | ||
|
@@ -1772,7 +1784,7 @@ public CompletableFuture<MessageId> terminate() { | |
ledger.asyncTerminate(new TerminateCallback() { | ||
@Override | ||
public void terminateComplete(Position lastCommittedPosition, Object ctx) { | ||
producers.forEach(Producer::disconnect); | ||
producers.values().forEach(Producer::disconnect); | ||
subscriptions.forEach((name, sub) -> sub.topicTerminated()); | ||
|
||
PositionImpl lastPosition = (PositionImpl) lastCommittedPosition; | ||
|
This file contains 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.
use
producers.replace(producer.getProducerName(), existingProducer, producer)
to make sure one can successfully add the producer.