forked from IQSS/dataverse
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request IQSS#10241 from Recherche-Data-Gouv/10161-Http2Sol…
…rClient Migration HttpSolrClient to Http2SolrClient and ConcurrentUpdateHttp2SolrClient
- Loading branch information
Showing
12 changed files
with
275 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[HttpSolrClient](https://solr.apache.org/docs/9_4_1/solrj/org/apache/solr/client/solrj/impl/HttpSolrClient.html) is deprecated as of Solr 9, and which will be removed in a future major release of Solr. It's recommended to use [Http2SolrClient](https://solr.apache.org/docs/9_4_1/solrj/org/apache/solr/client/solrj/impl/Http2SolrClient.html) instead. | ||
|
||
[Solr documentation](https://solr.apache.org/guide/solr/latest/deployment-guide/solrj.html#types-of-solrclients) describe it as a _async, non-blocking and general-purpose client that leverage HTTP/2 using the Jetty Http library_. | ||
|
||
With Solr 9.4.1, the Http2SolrClient is indicate as experimental. But since the 9.6 version of Solr, this mention is no longer maintained. | ||
|
||
The ConcurrentUpdateHttp2SolrClient is now also used in some cases, which is supposed to be more efficient for indexing. | ||
|
||
For more information, see issue [#10161](https://github.com/IQSS/dataverse/issues/10161) and pull request [#10241](https://github.com/IQSS/dataverse/pull/10241) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/main/java/edu/harvard/iq/dataverse/search/AbstractSolrClientService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package edu.harvard.iq.dataverse.search; | ||
|
||
import java.io.IOException; | ||
import java.util.logging.Logger; | ||
|
||
import org.apache.solr.client.solrj.SolrClient; | ||
|
||
import edu.harvard.iq.dataverse.settings.JvmSettings; | ||
import edu.harvard.iq.dataverse.util.SystemConfig; | ||
import jakarta.ejb.EJB; | ||
|
||
/** | ||
* Generics methods for Solr clients implementations | ||
* | ||
* @author jeromeroucou | ||
*/ | ||
public abstract class AbstractSolrClientService { | ||
private static final Logger logger = Logger.getLogger(AbstractSolrClientService.class.getCanonicalName()); | ||
|
||
@EJB | ||
SystemConfig systemConfig; | ||
|
||
public abstract void init(); | ||
public abstract void close(); | ||
public abstract SolrClient getSolrClient(); | ||
public abstract void setSolrClient(SolrClient solrClient); | ||
|
||
public void close(SolrClient solrClient) { | ||
if (solrClient != null) { | ||
try { | ||
solrClient.close(); | ||
} catch (IOException e) { | ||
logger.warning("Solr closing error: " + e); | ||
} | ||
solrClient = null; | ||
} | ||
} | ||
|
||
public void reInitialize() { | ||
close(); | ||
init(); | ||
} | ||
|
||
public String getSolrUrl() { | ||
// Get from MPCONFIG. Might be configured by a sysadmin or simply return the | ||
// default shipped with resources/META-INF/microprofile-config.properties. | ||
final String protocol = JvmSettings.SOLR_PROT.lookup(); | ||
final String path = JvmSettings.SOLR_PATH.lookup(); | ||
return protocol + "://" + this.systemConfig.getSolrHostColonPort() + path; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/main/java/edu/harvard/iq/dataverse/search/SolrClientIndexService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package edu.harvard.iq.dataverse.search; | ||
|
||
import java.util.logging.Logger; | ||
|
||
import org.apache.solr.client.solrj.SolrClient; | ||
import org.apache.solr.client.solrj.impl.ConcurrentUpdateHttp2SolrClient; | ||
import org.apache.solr.client.solrj.impl.Http2SolrClient; | ||
|
||
import jakarta.annotation.PostConstruct; | ||
import jakarta.annotation.PreDestroy; | ||
import jakarta.ejb.Singleton; | ||
import jakarta.inject.Named; | ||
|
||
/** | ||
* Solr client to provide insert/update/delete operations. | ||
* Don't use this service with queries to Solr, use {@link SolrClientService} instead. | ||
*/ | ||
@Named | ||
@Singleton | ||
public class SolrClientIndexService extends AbstractSolrClientService { | ||
|
||
private static final Logger logger = Logger.getLogger(SolrClientIndexService.class.getCanonicalName()); | ||
|
||
private SolrClient solrClient; | ||
|
||
@PostConstruct | ||
public void init() { | ||
solrClient = new ConcurrentUpdateHttp2SolrClient.Builder( | ||
getSolrUrl(), new Http2SolrClient.Builder().build()).build(); | ||
} | ||
|
||
@PreDestroy | ||
public void close() { | ||
close(solrClient); | ||
} | ||
|
||
public SolrClient getSolrClient() { | ||
// Should never happen - but? | ||
if (solrClient == null) { | ||
init(); | ||
} | ||
return solrClient; | ||
} | ||
|
||
public void setSolrClient(SolrClient solrClient) { | ||
this.solrClient = solrClient; | ||
} | ||
|
||
} |
Oops, something went wrong.