-
Notifications
You must be signed in to change notification settings - Fork 674
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
SOLR-17541: LBSolrClient implementations should agree on 'getClient()' semantics #2899
Changes from all commits
5261cd3
bc8c888
a249169
1f8a307
90bf9e2
51676f5
db76064
605bdc7
508af0d
39177b4
35651b8
19577dc
ca59536
67c8b8f
7b90862
1539d97
8f17279
effedb9
29a3445
50470cd
f423bd2
6176a99
783f815
e8c998d
e035a0c
99282aa
45b9e10
7df3c3b
90bd2ec
f984d12
28aec3b
30dcdb3
730aad0
071fb04
05eb1ea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,9 +40,8 @@ | |
public class CloudHttp2SolrClient extends CloudSolrClient { | ||
|
||
private final ClusterStateProvider stateProvider; | ||
private final LBHttp2SolrClient<Http2SolrClient> lbClient; | ||
private final LBHttp2SolrClient<Http2SolrClient.Builder> lbClient; | ||
private final Http2SolrClient myClient; | ||
private final boolean clientIsInternal; | ||
|
||
/** | ||
* Create a new client object that connects to Zookeeper and is always aware of the SolrCloud | ||
|
@@ -54,8 +53,8 @@ public class CloudHttp2SolrClient extends CloudSolrClient { | |
*/ | ||
protected CloudHttp2SolrClient(Builder builder) { | ||
super(builder.shardLeadersOnly, builder.parallelUpdates, builder.directUpdatesToLeadersOnly); | ||
this.clientIsInternal = builder.httpClient == null; | ||
this.myClient = createOrGetHttpClientFromBuilder(builder); | ||
var httpSolrClientBuilder = createOrGetHttpClientBuilder(builder); | ||
this.myClient = httpSolrClientBuilder.build(); | ||
this.stateProvider = createClusterStateProvider(builder); | ||
this.retryExpiryTimeNano = builder.retryExpiryTimeNano; | ||
this.defaultCollection = builder.defaultCollection; | ||
|
@@ -73,16 +72,14 @@ protected CloudHttp2SolrClient(Builder builder) { | |
// locks. | ||
this.locks = objectList(builder.parallelCacheRefreshesLocks); | ||
|
||
this.lbClient = new LBHttp2SolrClient.Builder<Http2SolrClient>(myClient).build(); | ||
this.lbClient = new LBHttp2SolrClient.Builder<>(httpSolrClientBuilder).build(); | ||
} | ||
|
||
private Http2SolrClient createOrGetHttpClientFromBuilder(Builder builder) { | ||
if (builder.httpClient != null) { | ||
return builder.httpClient; | ||
} else if (builder.internalClientBuilder != null) { | ||
return builder.internalClientBuilder.build(); | ||
private Http2SolrClient.Builder createOrGetHttpClientBuilder(Builder builder) { | ||
if (builder.internalClientBuilder != null) { | ||
return builder.internalClientBuilder; | ||
} else { | ||
return new Http2SolrClient.Builder().build(); | ||
return new Http2SolrClient.Builder(); | ||
} | ||
} | ||
|
||
|
@@ -129,7 +126,7 @@ private ClusterStateProvider createHttp2ClusterStateProvider( | |
|
||
private void closeMyClientIfNeeded() { | ||
try { | ||
if (clientIsInternal && myClient != null) { | ||
if (myClient != null) { | ||
myClient.close(); | ||
} | ||
} catch (Exception e) { | ||
|
@@ -148,7 +145,7 @@ public void close() throws IOException { | |
} | ||
|
||
@Override | ||
public LBHttp2SolrClient<Http2SolrClient> getLbClient() { | ||
public LBHttp2SolrClient<Http2SolrClient.Builder> getLbClient() { | ||
return lbClient; | ||
} | ||
|
||
|
@@ -171,7 +168,6 @@ public static class Builder { | |
protected Collection<String> zkHosts = new ArrayList<>(); | ||
protected List<String> solrUrls = new ArrayList<>(); | ||
protected String zkChroot; | ||
protected Http2SolrClient httpClient; | ||
protected boolean shardLeadersOnly = true; | ||
protected boolean directUpdatesToLeadersOnly = false; | ||
protected boolean parallelUpdates = true; | ||
|
@@ -404,23 +400,6 @@ public Builder withCollectionCacheTtl(long timeToLive, TimeUnit unit) { | |
return this; | ||
} | ||
|
||
/** | ||
* Set the internal http client. | ||
* | ||
* <p>Note: closing the httpClient instance is at the responsibility of the caller. | ||
* | ||
* @param httpClient http client | ||
* @return this | ||
*/ | ||
public Builder withHttpClient(Http2SolrClient httpClient) { | ||
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. not sure we want to take this away from users 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. This is the most controversial part of this PR, and I do not want to merge a potentially disruptive API change like this without buy-in. I do not think this is much of a burden though, because the Builder has The purpose of forcing this is that 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.
which still exists, so if a user somehow has a client but not a builder but needs one due to the API change you introduce, they have this option.
Well written James! +1 |
||
if (this.internalClientBuilder != null) { | ||
throw new IllegalStateException( | ||
"The builder can't accept an httpClient AND an internalClientBuilder, only one of those can be provided"); | ||
} | ||
this.httpClient = httpClient; | ||
return this; | ||
} | ||
|
||
/** | ||
* If provided, the CloudHttp2SolrClient will build it's internal Http2SolrClient using this | ||
* builder (instead of the empty default one). Providing this builder allows users to configure | ||
|
@@ -430,10 +409,6 @@ public Builder withHttpClient(Http2SolrClient httpClient) { | |
* @return this | ||
*/ | ||
public Builder withInternalClientBuilder(Http2SolrClient.Builder internalClientBuilder) { | ||
if (this.httpClient != null) { | ||
throw new IllegalStateException( | ||
"The builder can't accept an httpClient AND an internalClientBuilder, only one of those can be provided"); | ||
} | ||
this.internalClientBuilder = internalClientBuilder; | ||
return this; | ||
} | ||
|
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.
WDYT @iamsanjay ?