Skip to content

Commit

Permalink
minor: don't create an unused thread (#2514)
Browse files Browse the repository at this point in the history
  • Loading branch information
psalagnac authored Jul 22, 2024
1 parent 0da7a78 commit d567066
Showing 1 changed file with 28 additions and 31 deletions.
59 changes: 28 additions & 31 deletions solr/core/src/java/org/apache/solr/cloud/SyncStrategy.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import org.apache.solr.common.params.CoreAdminParams.CoreAdminAction;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.SuppressForbidden;
import org.apache.solr.core.CoreContainer;
import org.apache.solr.core.CoreDescriptor;
import org.apache.solr.core.SolrCore;
Expand Down Expand Up @@ -346,39 +345,37 @@ public void requestRecoveries() {
}
}

@SuppressForbidden(reason = "Passed to an executor with a naming thread factory")
private void requestRecovery(
final ZkNodeProps leaderProps, final String baseUrl, final String coreName)
throws SolrServerException, IOException {
Thread thread =
new Thread(
() -> {
if (isClosed) {
log.info("We have been closed, won't request recovery");
return;
}
RequestRecovery recoverRequestCmd = new RequestRecovery();
recoverRequestCmd.setAction(CoreAdminAction.REQUESTRECOVERY);
recoverRequestCmd.setCoreName(coreName);
try (SolrClient client =
new Http2SolrClient.Builder(baseUrl)
.withHttpClient(solrClient)
.withConnectionTimeout(30000, TimeUnit.MILLISECONDS)
.withIdleTimeout(120000, TimeUnit.MILLISECONDS)
.build()) {
client.request(recoverRequestCmd);
} catch (Throwable t) {
log.error(
"{}: Could not tell a replica to recover",
ZkCoreNodeProps.getCoreUrl(leaderProps),
t);
if (t instanceof Error) {
throw (Error) t;
}
}
});
thread.setDaemon(true);
updateExecutor.execute(thread);
Runnable runnable =
() -> {
if (isClosed) {
log.info("We have been closed, won't request recovery");
return;
}
RequestRecovery recoverRequestCmd = new RequestRecovery();
recoverRequestCmd.setAction(CoreAdminAction.REQUESTRECOVERY);
recoverRequestCmd.setCoreName(coreName);
try (SolrClient client =
new Http2SolrClient.Builder(baseUrl)
.withHttpClient(solrClient)
.withConnectionTimeout(30000, TimeUnit.MILLISECONDS)
.withIdleTimeout(120000, TimeUnit.MILLISECONDS)
.build()) {
client.request(recoverRequestCmd);
} catch (Throwable t) {
log.error(
"{}: Could not tell a replica to recover",
ZkCoreNodeProps.getCoreUrl(leaderProps),
t);
if (t instanceof Error) {
throw (Error) t;
}
}
};

updateExecutor.execute(runnable);
}

public static ModifiableSolrParams params(String... params) {
Expand Down

0 comments on commit d567066

Please sign in to comment.