You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by "poorbarcode (via GitHub)" <gi...@apache.org> on 2023/02/13 20:08:44 UTC
[GitHub] [pulsar] poorbarcode opened a new pull request, #19505: [fix] [broker] Incorrect service name selection logic
poorbarcode opened a new pull request, #19505:
URL: https://github.com/apache/pulsar/pull/19505
Fixes #17080
### Motivation
`PulsarServiceNameResolver` is used to randomly select a service name from multiple service names, the logic is:
- select a random index of the service name list
- if the previous service name can not work, use `{previous index} + 1`
But when we call the method `PulsarWebResource.getRedirectionUrl`, it will always create a new `PulsarServiceNameResolver` instance, this reduces the above logic to only randomly select a service name.
### Modifications
But when we call the method `PulsarWebResource.getRedirectionUrl`, reuse the same `PulsarServiceNameResolver` instance.
### Documentation
<!-- DO NOT REMOVE THIS SECTION. CHECK THE PROPER BOX ONLY. -->
- [ ] `doc` <!-- Your PR contains doc changes. -->
- [ ] `doc-required` <!-- Your PR changes impact docs and you will update later -->
- [x] `doc-not-needed` <!-- Your PR changes do not impact docs -->
- [ ] `doc-complete` <!-- Docs have been already added -->
### Matching PR in forked repository
PR in forked repository:
- https://github.com/poorbarcode/pulsar/pull/66
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [fix] [broker] Incorrect service name selection logic [pulsar]
Posted by "lhotari (via GitHub)" <gi...@apache.org>.
lhotari commented on code in PR #19505:
URL: https://github.com/apache/pulsar/pull/19505#discussion_r1708681305
##########
pulsar-client/src/main/java/org/apache/pulsar/client/impl/PulsarServiceNameResolver.java:
##########
@@ -52,9 +52,8 @@ public InetSocketAddress resolveHost() {
if (list.size() == 1) {
return list.get(0);
} else {
- CURRENT_INDEX_UPDATER.getAndUpdate(this, last -> (last + 1) % list.size());
- return list.get(currentIndex);
-
+ int originalIndex = CURRENT_INDEX_UPDATER.getAndUpdate(this, last -> (last + 1) % list.size());
+ return list.get((originalIndex + 1) % list.size());
Review Comment:
I'll check with a unit test
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] poorbarcode merged pull request #19505: [fix] [broker] Incorrect service name selection logic
Posted by "poorbarcode (via GitHub)" <gi...@apache.org>.
poorbarcode merged PR #19505:
URL: https://github.com/apache/pulsar/pull/19505
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [fix] [broker] Incorrect service name selection logic [pulsar]
Posted by "lhotari (via GitHub)" <gi...@apache.org>.
lhotari commented on code in PR #19505:
URL: https://github.com/apache/pulsar/pull/19505#discussion_r1708645749
##########
pulsar-client/src/main/java/org/apache/pulsar/client/impl/PulsarServiceNameResolver.java:
##########
@@ -52,9 +52,8 @@ public InetSocketAddress resolveHost() {
if (list.size() == 1) {
return list.get(0);
} else {
- CURRENT_INDEX_UPDATER.getAndUpdate(this, last -> (last + 1) % list.size());
- return list.get(currentIndex);
-
+ int originalIndex = CURRENT_INDEX_UPDATER.getAndUpdate(this, last -> (last + 1) % list.size());
+ return list.get((originalIndex + 1) % list.size());
Review Comment:
What was the purpose of this change? It seems that the index is incremented by 2 each time. That would skip some entries in the input. It seems that the previous logic had a bug and should have been `return list.get(CURRENT_INDEX_UPDATER.getAndUpdate(this, last -> (last + 1) % list.size()));` to prevent races.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] codelipenghui commented on pull request #19505: [fix] [broker] Incorrect service name selection logic
Posted by "codelipenghui (via GitHub)" <gi...@apache.org>.
codelipenghui commented on PR #19505:
URL: https://github.com/apache/pulsar/pull/19505#issuecomment-1429076901
/pulsarbot run-failure-checks
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] michaeljmarshall commented on a diff in pull request #19505: [fix] [broker] Incorrect service name selection logic
Posted by "michaeljmarshall (via GitHub)" <gi...@apache.org>.
michaeljmarshall commented on code in PR #19505:
URL: https://github.com/apache/pulsar/pull/19505#discussion_r1107373967
##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/web/PulsarWebResource.java:
##########
@@ -96,6 +102,17 @@ public abstract class PulsarWebResource {
private static final Logger log = LoggerFactory.getLogger(PulsarWebResource.class);
+ private static final LoadingCache<String, PulsarServiceNameResolver> SERVICE_NAME_RESOLVER_CACHE =
+ Caffeine.newBuilder().expireAfterWrite(Duration.ofMinutes(5)).build(
Review Comment:
Shouldn't we expire based on access? If we expire after write, we could still get into the flaky edge case, when the cached `PulsarServiceNameResolver` gets refreshed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] poorbarcode commented on a diff in pull request #19505: [fix] [broker] Incorrect service name selection logic
Posted by "poorbarcode (via GitHub)" <gi...@apache.org>.
poorbarcode commented on code in PR #19505:
URL: https://github.com/apache/pulsar/pull/19505#discussion_r1107401109
##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/web/PulsarWebResource.java:
##########
@@ -96,6 +102,17 @@ public abstract class PulsarWebResource {
private static final Logger log = LoggerFactory.getLogger(PulsarWebResource.class);
+ private static final LoadingCache<String, PulsarServiceNameResolver> SERVICE_NAME_RESOLVER_CACHE =
+ Caffeine.newBuilder().expireAfterWrite(Duration.ofMinutes(5)).build(
Review Comment:
Good suggestion. I have pushed a new PR to fix it, could you take a look?
- https://github.com/apache/pulsar/pull/19532
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org