You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2022/08/13 03:24:16 UTC
[GitHub] [pulsar] coderzc opened a new pull request, #17082: [fix][broker] Skip not connectable URL when get redirectionUrl.
coderzc opened a new pull request, #17082:
URL: https://github.com/apache/pulsar/pull/17082
Fixes #17080
### Motivation
The test failed root cause is have not connectable URL in the `serviceUrl` and ServiceNameReSolver will randomly select a URL to return when getting `resolveHostUri` for the first time.
### Modifications
Cycle getting the `resolveHostUri` and check connectivity to find a connected URL.
### Verifying this change
- [x] Make sure that the change passes the CI checks.
*(Please pick either of the following options)*
This change is a trivial rework / code cleanup without any test coverage.
*(or)*
This change is already covered by existing tests, such as *(please describe tests)*.
*(or)*
This change added tests and can be verified as follows:
*(example:)*
- *Added integration tests for end-to-end deployment with large payloads (10MB)*
- *Extended integration test for recovery after broker failure*
### Does this pull request potentially affect one of the following parts:
*If `yes` was chosen, please highlight the changes*
- Dependencies (does it add or upgrade a dependency): (yes / no)
- The public API: (yes / no)
- The schema: (yes / no / don't know)
- The default values of configurations: (yes / no)
- The wire protocol: (yes / no)
- The rest endpoints: (yes / no)
- The admin cli options: (yes / no)
- Anything that affects deployment: (yes / no / don't know)
### Documentation
Check the box below or label this PR directly.
Need to update docs?
- [ ] `doc-required`
(Your PR needs to update docs and you will update later)
- [x] `doc-not-needed`
(Please explain why)
- [ ] `doc`
(Your PR contains doc changes)
- [ ] `doc-complete`
(Docs have been already added)
--
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] coderzc commented on pull request #17082: [fix][broker] Skip not connectable URL when get redirectionUrl
Posted by GitBox <gi...@apache.org>.
coderzc commented on PR #17082:
URL: https://github.com/apache/pulsar/pull/17082#issuecomment-1214769307
/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] mattisonchao commented on pull request #17082: [fix][broker] Skip not connectable URL when get redirectionUrl
Posted by GitBox <gi...@apache.org>.
mattisonchao commented on PR #17082:
URL: https://github.com/apache/pulsar/pull/17082#issuecomment-1216054517
Question:
> have not connectable URL in the serviceUrl
Why do we have it? Is there a way to stop this from happening?
It's better to fix the problem where it occurs than to check it later.
--
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] coderzc commented on a diff in pull request #17082: [fix][broker] Skip not connectable URL when get redirectionUrl
Posted by GitBox <gi...@apache.org>.
coderzc commented on code in PR #17082:
URL: https://github.com/apache/pulsar/pull/17082#discussion_r945411974
##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/web/PulsarWebResource.java:
##########
@@ -493,13 +502,47 @@ private URI getRedirectionUrl(ClusterData differentClusterData) throws Malformed
} else {
serviceNameResolver.updateServiceUrl(differentClusterData.getServiceUrl());
}
- URL webUrl = new URL(serviceNameResolver.resolveHostUri().toString());
- return UriBuilder.fromUri(uri.getRequestUri()).host(webUrl.getHost()).port(webUrl.getPort()).build();
+ return getConnectableURI(serviceNameResolver);
} catch (PulsarClientException.InvalidServiceURL exception) {
throw new MalformedURLException(exception.getMessage());
}
}
+ private CompletableFuture<URI> getConnectableURI(PulsarServiceNameResolver serviceNameResolver) {
+ return CompletableFuture.supplyAsync(() -> {
+ String hostUri = serviceNameResolver.resolveHostUri().toString();
+ String firstHostUri = hostUri;
+ boolean connectable = false;
+ URL webUrl = null;
+ do {
+ try {
+ webUrl = new URL(hostUri);
+ Socket socket = new Socket();
+ socket.connect(new InetSocketAddress(webUrl.getHost(), webUrl.getPort()), 5000);
+ socket.close();
+ connectable = true;
+ } catch (Exception e) {
+ log.warn("Unable connect to url:{}", hostUri);
+ hostUri = serviceNameResolver.resolveHostUri().toString();
+
+ if (firstHostUri.equals(hostUri)) {
+ break;
+ }
+ }
+ } while (!connectable);
+
+ if (webUrl == null) {
+ try {
+ webUrl = new URL(hostUri);
+ } catch (MalformedURLException e) {
+ throw new RestException(e);
+ }
+ }
+
+ return UriBuilder.fromUri(uri.getRequestUri()).host(webUrl.getHost()).port(webUrl.getPort()).build();
+ }, pulsar.getExecutor());
+ }
+
Review Comment:
> We may add this logic to PulsarServiceNameResolver
This seems odd, since the method also needs to verify URI is an HTTP protocol
--
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] github-actions[bot] commented on pull request #17082: [fix][broker] Skip not connectable URL when get redirectionUrl
Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on PR #17082:
URL: https://github.com/apache/pulsar/pull/17082#issuecomment-1269217987
The pr had no activity for 30 days, mark with Stale label.
--
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] coderzc closed pull request #17082: [fix][broker] Skip not connectable URL when get redirectionUrl
Posted by "coderzc (via GitHub)" <gi...@apache.org>.
coderzc closed pull request #17082: [fix][broker] Skip not connectable URL when get redirectionUrl
URL: https://github.com/apache/pulsar/pull/17082
--
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] Jason918 commented on pull request #17082: [fix][broker] Skip not connectable URL when get redirectionUrl
Posted by GitBox <gi...@apache.org>.
Jason918 commented on PR #17082:
URL: https://github.com/apache/pulsar/pull/17082#issuecomment-1229156225
@Technoboy- @codelipenghui @mattisonchao PTAL.
--
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] github-actions[bot] commented on pull request #17082: [fix][broker] Skip not connectable URL when get redirectionUrl
Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on PR #17082:
URL: https://github.com/apache/pulsar/pull/17082#issuecomment-1356979675
The pr had no activity for 30 days, mark with Stale label.
--
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] coderzc commented on pull request #17082: [fix][broker] Skip not connectable URL when get redirectionUrl
Posted by GitBox <gi...@apache.org>.
coderzc commented on PR #17082:
URL: https://github.com/apache/pulsar/pull/17082#issuecomment-1216066752
> Question:
>
> > have not connectable URL in the serviceUrl
>
>
>
>
>
> Why do we have it? Is there a way to remove this from happening?
>
> It's better to fix the problem where it occurs than to check it later.
>
>
>
> Thanks a lot!
I think it may be due to miswriting or network reasons that it is temporarily unable to connect.
--
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] eolivelli commented on a diff in pull request #17082: [fix][broker] Skip not connectable URL when get redirectionUrl
Posted by GitBox <gi...@apache.org>.
eolivelli commented on code in PR #17082:
URL: https://github.com/apache/pulsar/pull/17082#discussion_r956763118
##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/web/PulsarWebResource.java:
##########
@@ -493,13 +502,47 @@ private URI getRedirectionUrl(ClusterData differentClusterData) throws Malformed
} else {
serviceNameResolver.updateServiceUrl(differentClusterData.getServiceUrl());
}
- URL webUrl = new URL(serviceNameResolver.resolveHostUri().toString());
- return UriBuilder.fromUri(uri.getRequestUri()).host(webUrl.getHost()).port(webUrl.getPort()).build();
+ return getConnectableURI(serviceNameResolver);
} catch (PulsarClientException.InvalidServiceURL exception) {
throw new MalformedURLException(exception.getMessage());
}
}
+ private CompletableFuture<URI> getConnectableURI(PulsarServiceNameResolver serviceNameResolver) {
+ return CompletableFuture.supplyAsync(() -> {
+ String hostUri = serviceNameResolver.resolveHostUri().toString();
+ String firstHostUri = hostUri;
+ boolean connectable = false;
+ URL webUrl = null;
+ do {
+ try {
+ webUrl = new URL(hostUri);
+ Socket socket = new Socket();
+ socket.connect(new InetSocketAddress(webUrl.getHost(), webUrl.getPort()), 5000);
Review Comment:
This is going to create dunmy TCP connections to Pulsar brokers.
I don't think that the broker will be happy.
If you need thus feature that we must add a configuration flag to enable this new behaviour
--
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] Technoboy- commented on a diff in pull request #17082: [fix][broker] Skip not connectable URL when get redirectionUrl
Posted by GitBox <gi...@apache.org>.
Technoboy- commented on code in PR #17082:
URL: https://github.com/apache/pulsar/pull/17082#discussion_r945399502
##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/web/PulsarWebResource.java:
##########
@@ -493,13 +502,47 @@ private URI getRedirectionUrl(ClusterData differentClusterData) throws Malformed
} else {
serviceNameResolver.updateServiceUrl(differentClusterData.getServiceUrl());
}
- URL webUrl = new URL(serviceNameResolver.resolveHostUri().toString());
- return UriBuilder.fromUri(uri.getRequestUri()).host(webUrl.getHost()).port(webUrl.getPort()).build();
+ return getConnectableURI(serviceNameResolver);
} catch (PulsarClientException.InvalidServiceURL exception) {
throw new MalformedURLException(exception.getMessage());
}
}
+ private CompletableFuture<URI> getConnectableURI(PulsarServiceNameResolver serviceNameResolver) {
+ return CompletableFuture.supplyAsync(() -> {
+ String hostUri = serviceNameResolver.resolveHostUri().toString();
+ String firstHostUri = hostUri;
+ boolean connectable = false;
+ URL webUrl = null;
+ do {
+ try {
+ webUrl = new URL(hostUri);
+ Socket socket = new Socket();
+ socket.connect(new InetSocketAddress(webUrl.getHost(), webUrl.getPort()), 5000);
+ socket.close();
+ connectable = true;
+ } catch (Exception e) {
+ log.warn("Unable connect to url:{}", hostUri);
+ hostUri = serviceNameResolver.resolveHostUri().toString();
+
+ if (firstHostUri.equals(hostUri)) {
+ break;
+ }
+ }
+ } while (!connectable);
+
+ if (webUrl == null) {
+ try {
+ webUrl = new URL(hostUri);
+ } catch (MalformedURLException e) {
+ throw new RestException(e);
+ }
+ }
+
+ return UriBuilder.fromUri(uri.getRequestUri()).host(webUrl.getHost()).port(webUrl.getPort()).build();
+ }, pulsar.getExecutor());
+ }
+
Review Comment:
We may add this logic to PulsarServiceNameResolver
--
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] eolivelli commented on a diff in pull request #17082: [fix][broker] Skip not connectable URL when get redirectionUrl
Posted by GitBox <gi...@apache.org>.
eolivelli commented on code in PR #17082:
URL: https://github.com/apache/pulsar/pull/17082#discussion_r956763118
##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/web/PulsarWebResource.java:
##########
@@ -493,13 +502,47 @@ private URI getRedirectionUrl(ClusterData differentClusterData) throws Malformed
} else {
serviceNameResolver.updateServiceUrl(differentClusterData.getServiceUrl());
}
- URL webUrl = new URL(serviceNameResolver.resolveHostUri().toString());
- return UriBuilder.fromUri(uri.getRequestUri()).host(webUrl.getHost()).port(webUrl.getPort()).build();
+ return getConnectableURI(serviceNameResolver);
} catch (PulsarClientException.InvalidServiceURL exception) {
throw new MalformedURLException(exception.getMessage());
}
}
+ private CompletableFuture<URI> getConnectableURI(PulsarServiceNameResolver serviceNameResolver) {
+ return CompletableFuture.supplyAsync(() -> {
+ String hostUri = serviceNameResolver.resolveHostUri().toString();
+ String firstHostUri = hostUri;
+ boolean connectable = false;
+ URL webUrl = null;
+ do {
+ try {
+ webUrl = new URL(hostUri);
+ Socket socket = new Socket();
+ socket.connect(new InetSocketAddress(webUrl.getHost(), webUrl.getPort()), 5000);
Review Comment:
This is going to create dunmy TCP connections to Pulsar brokers.
I don't think that the network monitors/auditing tools will be happy.
If you need thus feature that we must add a configuration flag to enable this new behaviour
--
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 a diff in pull request #17082: [fix][broker] Skip not connectable URL when get redirectionUrl.
Posted by GitBox <gi...@apache.org>.
codelipenghui commented on code in PR #17082:
URL: https://github.com/apache/pulsar/pull/17082#discussion_r945207831
##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/web/PulsarWebResource.java:
##########
@@ -493,13 +494,39 @@ private URI getRedirectionUrl(ClusterData differentClusterData) throws Malformed
} else {
serviceNameResolver.updateServiceUrl(differentClusterData.getServiceUrl());
}
- URL webUrl = new URL(serviceNameResolver.resolveHostUri().toString());
+ URL webUrl = getConnectableURL(serviceNameResolver);
return UriBuilder.fromUri(uri.getRequestUri()).host(webUrl.getHost()).port(webUrl.getPort()).build();
} catch (PulsarClientException.InvalidServiceURL exception) {
throw new MalformedURLException(exception.getMessage());
}
}
+ private URL getConnectableURL(PulsarServiceNameResolver serviceNameResolver) throws MalformedURLException {
Review Comment:
We should make this method pure async. This is called from the metadata callback thread.
--
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] congbobo184 commented on pull request #17082: [fix][broker] Skip not connectable URL when get redirectionUrl
Posted by GitBox <gi...@apache.org>.
congbobo184 commented on PR #17082:
URL: https://github.com/apache/pulsar/pull/17082#issuecomment-1318546944
@coderzc hi, I move this PR to release/2.9.5, if you have any questions, please ping me. thanks.
--
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