You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@atlas.apache.org by sa...@apache.org on 2019/06/11 22:57:35 UTC

[atlas] branch master updated: ATLAS-3275 Basic Search with "query" string throws "Problem accessing /solr/vertex_index/freetext".

This is an automated email from the ASF dual-hosted git repository.

sarath pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/atlas.git


The following commit(s) were added to refs/heads/master by this push:
     new f2cb641  ATLAS-3275 Basic Search with "query" string throws "Problem accessing /solr/vertex_index/freetext".
f2cb641 is described below

commit f2cb641e36678c508ed2e952f9d35040b80ec12b
Author: skoritala <sk...@cloudera.com>
AuthorDate: Tue Jun 11 06:53:56 2019 -0700

    ATLAS-3275 Basic Search with "query" string throws "Problem accessing /solr/vertex_index/freetext".
    
        Made the return objects from V2 SOLR apis are handled correctly for error scenario.
        Made the code change to re-use solr client object. to avoid excessive Zookeeper Connections that are not getting closed.
    
    Signed-off-by: Sarath Subramanian <sa...@apache.org>
---
 .../graphdb/janus/AtlasJanusGraphIndexClient.java  | 50 ++++++++++++++++++----
 .../janusgraph/diskstorage/solr/Solr6Index.java    | 39 ++++++++++++++---
 2 files changed, 73 insertions(+), 16 deletions(-)

diff --git a/graphdb/janus/src/main/java/org/apache/atlas/repository/graphdb/janus/AtlasJanusGraphIndexClient.java b/graphdb/janus/src/main/java/org/apache/atlas/repository/graphdb/janus/AtlasJanusGraphIndexClient.java
index 16be93f..4b441bf 100644
--- a/graphdb/janus/src/main/java/org/apache/atlas/repository/graphdb/janus/AtlasJanusGraphIndexClient.java
+++ b/graphdb/janus/src/main/java/org/apache/atlas/repository/graphdb/janus/AtlasJanusGraphIndexClient.java
@@ -18,6 +18,7 @@
 package org.apache.atlas.repository.graphdb.janus;
 
 import com.google.common.annotations.VisibleForTesting;
+import org.apache.atlas.exception.AtlasBaseException;
 import org.apache.atlas.repository.graphdb.AtlasGraph;
 import org.apache.atlas.repository.graphdb.AtlasGraphIndexClient;
 import org.apache.atlas.repository.graphdb.AtlasGraphManagement;
@@ -27,6 +28,8 @@ import org.apache.solr.client.solrj.SolrClient;
 import org.apache.solr.client.solrj.SolrRequest;
 import org.apache.solr.client.solrj.SolrServerException;
 import org.apache.solr.client.solrj.request.V2Request;
+import org.apache.solr.client.solrj.response.V2Response;
+import org.apache.solr.common.util.NamedList;
 import org.janusgraph.diskstorage.solr.Solr6Index;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -83,7 +86,6 @@ public class AtlasJanusGraphIndexClient implements AtlasGraphIndexClient {
                     LOG.info("Attempting to update free text request handler {} for collection {}", FREETEXT_REQUEST_HANDLER, collectionName);
 
                     updateFreeTextRequestHandler(solrClient, collectionName, attributeName2SearchWeightMap);
-
                     LOG.info("Successfully updated free text request handler {} for collection {}..", FREETEXT_REQUEST_HANDLER, collectionName);
 
                     return;
@@ -97,7 +99,6 @@ public class AtlasJanusGraphIndexClient implements AtlasGraphIndexClient {
                     LOG.info("Attempting to create free text request handler {} for collection {}", FREETEXT_REQUEST_HANDLER, collectionName);
 
                     createFreeTextRequestHandler(solrClient, collectionName, attributeName2SearchWeightMap);
-
                     LOG.info("Successfully created free text request handler {} for collection {}", FREETEXT_REQUEST_HANDLER, collectionName);
 
                     return;
@@ -112,22 +113,53 @@ public class AtlasJanusGraphIndexClient implements AtlasGraphIndexClient {
 
             throw lastExcp != null ? new RuntimeException(msg, lastExcp) : new RuntimeException(msg);
         } finally {
+            LOG.debug("Releasing the solr client from usage.");
             Solr6Index.releaseSolrClient(solrClient);
         }
     }
 
-    private void updateFreeTextRequestHandler(SolrClient solrClient, String collectionName, Map<String, Integer> attributeName2SearchWeightMap) throws IOException, SolrServerException {
+    private V2Response validateResponseForSuccess(V2Response v2Response) throws AtlasBaseException {
+        if(v2Response == null) {
+            String msg = "Received in valid response .";
+            LOG.error(msg);
+            throw new AtlasBaseException(msg);
+        }
+        if(LOG.isDebugEnabled()) {
+            LOG.debug("V2 Response is {}", v2Response.toString());
+        }
+        NamedList<Object> response = v2Response.getResponse();
+        Object errorMessages = response.get("errorMessages");
+        if(errorMessages != null) {
+            LOG.error("Error encountered in performing response handler action.");
+            List<Object> errorObjects = (List<Object>) errorMessages;
+            Map<Object, Object> errObject = (Map<Object, Object>) errorObjects.get(0);
+            List<String> msgs = (List<String>) errObject.get("errorMessages");
+            StringBuilder sb = new StringBuilder();
+            for(String msg: msgs) {
+                sb.append(msg);
+            }
+            String errors = sb.toString();
+            String msg = String.format("Error encountered in performing response handler action. %s.", errors);
+            LOG.error(msg);
+            throw new AtlasBaseException(msg);
+        } else {
+            LOG.debug("Successfully performed response handler action. V2 Response is {}", v2Response.toString());
+        }
+        return v2Response;
+    }
+
+    private V2Response updateFreeTextRequestHandler(SolrClient solrClient, String collectionName, Map<String, Integer> attributeName2SearchWeightMap) throws IOException, SolrServerException, AtlasBaseException {
         String searchWeightString = generateSearchWeightString(graph.getManagementSystem(), collectionName, attributeName2SearchWeightMap);
         String payLoadString      = generatePayLoadForFreeText("update-requesthandler", FREETEXT_REQUEST_HANDLER, searchWeightString);
 
-        performRequestHandlerAction(collectionName, solrClient, payLoadString);
+        return performRequestHandlerAction(collectionName, solrClient, payLoadString);
     }
 
-    private void createFreeTextRequestHandler(SolrClient solrClient, String collectionName, Map<String, Integer> attributeName2SearchWeightMap) throws IOException, SolrServerException {
+    private V2Response createFreeTextRequestHandler(SolrClient solrClient, String collectionName, Map<String, Integer> attributeName2SearchWeightMap) throws IOException, SolrServerException, AtlasBaseException {
         String searchWeightString = generateSearchWeightString(graph.getManagementSystem(), collectionName, attributeName2SearchWeightMap);
         String payLoadString      = generatePayLoadForFreeText("create-requesthandler", FREETEXT_REQUEST_HANDLER, searchWeightString);
 
-        performRequestHandlerAction(collectionName, solrClient, payLoadString);
+        return performRequestHandlerAction(collectionName, solrClient, payLoadString);
     }
 
     private String generateSearchWeightString(AtlasGraphManagement management, String indexName, Map<String, Integer> searchWeightsMap) {
@@ -167,12 +199,12 @@ public class AtlasJanusGraphIndexClient implements AtlasGraphIndexClient {
                 "}", action, handlerName, qfValue);
     }
 
-    private void performRequestHandlerAction(String collectionName, SolrClient solrClient,
-                                             String actionPayLoad) throws IOException, SolrServerException {
+    private V2Response performRequestHandlerAction(String collectionName, SolrClient solrClient,
+                                             String actionPayLoad) throws IOException, SolrServerException, AtlasBaseException {
         V2Request v2Request = new V2Request.Builder(String.format("/collections/%s/config", collectionName))
                 .withMethod(SolrRequest.METHOD.POST)
                 .withPayload(actionPayLoad)
                 .build();
-        v2Request.process(solrClient);
+        return validateResponseForSuccess(v2Request.process(solrClient));
     }
 }
diff --git a/graphdb/janus/src/main/java/org/janusgraph/diskstorage/solr/Solr6Index.java b/graphdb/janus/src/main/java/org/janusgraph/diskstorage/solr/Solr6Index.java
index 23a5739..d8ad22e 100644
--- a/graphdb/janus/src/main/java/org/janusgraph/diskstorage/solr/Solr6Index.java
+++ b/graphdb/janus/src/main/java/org/janusgraph/diskstorage/solr/Solr6Index.java
@@ -139,6 +139,7 @@ public class Solr6Index implements IndexProvider {
     private static final char   CHROOT_START_CHAR = '/';
 
     private static Solr6Index instance = null;
+    public static final ConfigOption<Boolean> CREATE_SOLR_CLIENT_PER_REQUEST = new ConfigOption(SOLR_NS, "create-client-per-request", "when false, allows the sharing of solr client across other components.", org.janusgraph.diskstorage.configuration.ConfigOption.Type.LOCAL, true);
 
     private enum Mode {
         HTTP, CLOUD;
@@ -168,6 +169,7 @@ public class Solr6Index implements IndexProvider {
             .build();
 
     private static final Map<Geo, String> SPATIAL_PREDICATES = spatialPredicates();
+    private static boolean createSolrClientPerRequest;
 
     private final SolrClient solrClient;
     private final Configuration configuration;
@@ -179,6 +181,7 @@ public class Solr6Index implements IndexProvider {
     private final boolean waitSearcher;
     private final boolean kerberosEnabled;
 
+
     public Solr6Index(final Configuration config) throws BackendException {
         // Add Kerberos-enabled SolrHttpClientBuilder
         HttpClientUtil.setHttpClientBuilder(new Krb5HttpClientBuilder().getBuilder());
@@ -203,21 +206,43 @@ public class Solr6Index implements IndexProvider {
         }
 
         solrClient = createSolrClient();
-
+        createSolrClientPerRequest = config.get(CREATE_SOLR_CLIENT_PER_REQUEST);
+        if(createSolrClientPerRequest) {
+            logger.info("A new Solr Client will be created for direct interation with SOLR.");
+        } else {
+            logger.info("Solr Client will be shared for direct interation with SOLR.");
+        }
         Solr6Index.instance = this;
     }
 
     public static SolrClient getSolrClient() {
-        return Solr6Index.instance != null ? Solr6Index.instance.createSolrClient() : null;
+        if (Solr6Index.instance != null) {
+            if (createSolrClientPerRequest) {
+                logger.debug("Creating a new Solr Client.");
+                return Solr6Index.instance.createSolrClient();
+            } else {
+                logger.debug("Returning the solr client owned by Solr6Index.");
+                return Solr6Index.instance.solrClient;
+            }
+        } else {
+            logger.debug(" No Solr6Index available. Will return null");
+            return null;
+        }
     }
 
     public static void releaseSolrClient(SolrClient solrClient) {
-        if (solrClient != null) {
-            try {
-                solrClient.close();
-            } catch (IOException excp) {
-                logger.warn("Failed to close SolrClient", excp);
+        if(createSolrClientPerRequest) {
+            if (solrClient != null) {
+                try {
+                    solrClient.close();
+                } catch (IOException excp) {
+                    logger.warn("Failed to close SolrClient", excp);
+                }
             }
+            logger.debug("Closed the solr client successfully.");
+        } else {
+            logger.debug("Ignoring the closing of solr client as it is owned by Solr6Index.");
+            return;
         }
     }
     private SolrClient createSolrClient() {