[improve][admin,broker] Add option to unloadNamespaceBundle with bundle Affinity broker url #7
[improve][admin,broker] Add option to unloadNamespaceBundle with bundle Affinity broker url #7vineeth1995 wants to merge 14 commits intomasterfrom
Conversation
feb9f76 to
d601cb7
Compare
| if (destinationBroker != null) { | ||
| if (!this.isLeaderBroker()) { | ||
| LeaderBroker leaderBroker = pulsar().getLeaderElectionService().getCurrentLeader().get(); | ||
| String leaderBrokerUrl = leaderBroker.getServiceUrl(); |
There was a problem hiding this comment.
this will not work in case of https. we need to select URL based on the request type HTTP or HTTPS?
you can find reference at: https://github.com/apache/pulsar/blob/master/pulsar-broker/src/main/java/org/apache/pulsar/broker/lookup/TopicLookupBase.java#L104
There was a problem hiding this comment.
This will work based on incoming requests ( http or https).
| String leaderBrokerUrl = leaderBroker.getServiceUrl(); | ||
| try { | ||
| URL redirectUrl = new URL(leaderBrokerUrl); | ||
| URI redirect = UriBuilder.fromUri(uri.getRequestUri()).host(redirectUrl.getHost()) |
There was a problem hiding this comment.
also, it's better to separate out this logic in a separate method
eg: validateLeader(httpRequest) this sends redirect response by throwing temporaryRedirect-Exception if current broker is not leader.
| false).build(); | ||
|
|
||
| // Redirect | ||
| log.debug("Redirecting the rest call to leader - {}, bundleRange - {}", redirect, bundleRange); |
There was a problem hiding this comment.
always try to keep log.debug under if -> if(log.isDebugEnabled)
| @PathParam("namespace") String namespace, @PathParam("bundle") String bundleRange, | ||
| @QueryParam("authoritative") @DefaultValue("false") boolean authoritative) { | ||
| @QueryParam("authoritative") @DefaultValue("false") boolean authoritative, | ||
| @QueryParam("destinationBroker") String destinationBroker) { |
There was a problem hiding this comment.
we need to update the doc in admin-api-topics.md file
| } | ||
|
|
||
| public void setNamespaceBundleAffinity (String bundleRange, String destinationBroker) { | ||
| if (destinationBroker != null) { |
There was a problem hiding this comment.
try to avoid nested if cyclomatic complexity. instead do
if (StringUtils.isBlank(destinationBroker)) {
return;
}
|
|
||
| void setNamespaceBundleAffinity(String bundle, String broker); | ||
|
|
||
| String removeNamespaceBundleAffinity(String bundle); |
There was a problem hiding this comment.
ideally, if we have set api then we can avoid delete API. do we really need delete API? can we just call set with null value for removing affinity.
There was a problem hiding this comment.
removeNamespaceBundleAffinity also serves the purpose of get heree
There was a problem hiding this comment.
I mean instead of calling remove, can we just call set(bundle, null) -> null broker means remove affinity.?
|
test-case failure can you verify if it's failing for you as well |
Yes, it passes for me in the local |
| String leaderBrokerUrl = leaderBroker.getServiceUrl(); | ||
| try { | ||
| URL redirectUrl = new URL(leaderBrokerUrl); | ||
| URI redirect = UriBuilder.fromUri(uri.getRequestUri()).host(redirectUrl.getHost()) |
There was a problem hiding this comment.
shouldn't it be based on http-request that comes from user . I guess I gave code reference earlier?
There was a problem hiding this comment.
here uri is the input request uri. So if the input request has https, uri. getRequestUri() returns https url and we are only replacing host and port. The same is being used here.
rdhabalia
left a comment
There was a problem hiding this comment.
LGTM. minor comments. you can address them and can create PR in open source.
|
|
||
| // Redirect | ||
| if (log.isDebugEnabled()) { | ||
| log.debug("Redirecting the rest call to leader - {}", redirect); |
There was a problem hiding this comment.
Redirecting the request call to leader
| .port(webUrl.get().getPort()).replaceQueryParam("authoritative", | ||
| newAuthoritative).build(); | ||
|
|
||
| newAuthoritative).replaceQueryParam("destinationBroker", |
There was a problem hiding this comment.
if destinationBroker is optional then if we don't pass it then by default value will be null. so, is it necessary to pass null value for destinationBroker ? or can we just make any change here if we are any passing null value?
There was a problem hiding this comment.
We are replacing the param with null because if destination broker is not null in the input request, it will again try to call leader broker to add the input to bundle affinity map which is already done before this step.
| getAdmin().namespaces().unload(namespace); | ||
| } else { | ||
| getAdmin().namespaces().unloadNamespaceBundle(namespace, bundle); | ||
| if (destinationBroker == null) { |
There was a problem hiding this comment.
we should avoid if/else here. what if we just call unloadNamespaceBundle with null destination. As it's passed as a query-param, server is anyway ignoring the value of destinationBroker if it has null value. right?
getAdmin().namespaces().unloadNamespaceBundle(namespace, bundle, destinationBroker);
52794a3 to
39a9810
Compare
b17fcc4 to
85800be
Compare
… bundle Affinity broker url
…bundle Affinity broker url
…le Affinity broker url
…le Affinity broker url
…le Affinity broker url
…le Affinity broker url
…le Affinity broker url
…le Affinity broker url
…le Affinity broker url
…le Affinity broker url
…le Affinity broker url
…le Affinity broker url
…le Affinity broker url
85800be to
e86bdb1
Compare
|
The pr had no activity for 30 days, mark with Stale label. |
Motivation
To provide an option for admin to unload namespace bundle with broker url to which the bundle has to be assigned to after the unload.
Modifications
Add an option to provide brokerWebServiceAddress (Ex: https://broker1.com:4443) while unloadingNamespaceBundle in the admin CLI and make corresponding changes in the pulsar-client-admin-api to support this.
Changes in pulsar-broker unloadNamespaceBundle API to accommodate broker url while unloading.
Add functionality in LoadManger implementation to select affinity broker for a bundle while trying to assign unloaded bundle to broker.
Verifying this change
This change added tests and can be verified as follows:
Does this pull request potentially affect one of the following parts:
If the box was checked, please highlight the changes
Documentation
docdoc-requireddoc-not-neededdoc-completeMatching PR in forked repository
PR in forked repository: