mmiklavc commented on a change in pull request #1367: METRON-2022: Metron rest 
creates large number of connections to ZK which causes subsequent connection to 
zk fail
URL: https://github.com/apache/metron/pull/1367#discussion_r269689838
 
 

 ##########
 File path: 
metron-platform/metron-solr/src/main/java/org/apache/metron/solr/dao/SolrDao.java
 ##########
 @@ -168,18 +168,21 @@ public Document 
removeCommentFromAlert(CommentAddRemoveRequest request, Document
   }
 
   /**
-   * Builds a Solr client using the ZK hosts from the global config.
+   * Returns the SolrClient.
    * @return SolrClient
    */
   public SolrClient getSolrClient() {
-    return new CloudSolrClient.Builder().withZkHost(getZkHosts()).build();
+    if (this.client == null) {
+      throw new IllegalStateException("The SolrDao must be initialized first");
+    }
+    return this.client;
   }
 
   /**
    * Builds a Solr client using the ZK hosts specified.
    * @return SolrClient
    */
-  public SolrClient getSolrClient(List<String> zkHosts) {
+  protected SolrClient getSolrClient(List<String> zkHosts) {
     return new CloudSolrClient.Builder().withZkHost(zkHosts).build();
 
 Review comment:
   Why would we ever want to create new clients from within a DAO class? Can we 
get rid of this altogether and/or get the client creation code into a proper 
factory? I think having `getSolrClient()` return an existing client and 
`getSolrClient(List<String> zkHosts)` opens us up to a relapse of this problem.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to