You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@solr.apache.org by "dsmiley (via GitHub)" <gi...@apache.org> on 2023/02/08 19:29:21 UTC

[GitHub] [solr] dsmiley commented on a diff in pull request #1302: SOLR-16628: Ensure that InputStreams are closed after Xml parsing

dsmiley commented on code in PR #1302:
URL: https://github.com/apache/solr/pull/1302#discussion_r1100587425


##########
solr/core/src/java/org/apache/solr/schema/ManagedIndexSchemaFactory.java:
##########
@@ -197,89 +200,99 @@ public ManagedIndexSchema create(
     this.config = config;
     this.loader = config.getResourceLoader();
     InputStream schemaInputStream = null;
+    String loadedResource = null;
 
-    if (null == resourceName) {
-      resourceName = IndexSchema.DEFAULT_SCHEMA_FILE;
-    }
-
-    int schemaZkVersion = -1;
-    if (!(loader instanceof ZkSolrResourceLoader)) {
-      schemaInputStream = readSchemaLocally();
-    } else { // ZooKeeper
-      final ZkSolrResourceLoader zkLoader = (ZkSolrResourceLoader) loader;
-      final SolrZkClient zkClient = zkLoader.getZkController().getZkClient();
-      final String managedSchemaPath = lookupZKManagedSchemaPath();
-      managedSchemaResourceName =
-          managedSchemaPath.substring(managedSchemaPath.lastIndexOf("/") + 1); // not loving this
-      Stat stat = new Stat();
-      try {
-        // Attempt to load the managed schema
-        byte[] data = zkClient.getData(managedSchemaPath, null, stat, true);
-        schemaZkVersion = stat.getVersion();
-        schemaInputStream =
-            new ZkSolrResourceLoader.ZkByteArrayInputStream(data, managedSchemaPath, stat);
-        loadedResource = managedSchemaResourceName;
-        warnIfNonManagedSchemaExists();
-      } catch (InterruptedException e) {
-        // Restore the interrupted status
-        Thread.currentThread().interrupt();
-        log.warn("", e);
-      } catch (KeeperException.NoNodeException e) {
-        log.info(
-            "The schema is configured as managed, but managed schema resource {} not found - loading non-managed schema {} instead",
-            managedSchemaResourceName,
-            resourceName);
-      } catch (KeeperException e) {
-        String msg = "Error attempting to access " + managedSchemaPath;
-        log.error(msg, e);
-        throw new SolrException(ErrorCode.SERVER_ERROR, msg, e);
+    try {
+      if (null == resourceName) {
+        resourceName = IndexSchema.DEFAULT_SCHEMA_FILE;
       }
-      if (null == schemaInputStream) {
-        // The managed schema file could not be found - load the non-managed schema
+
+      int schemaZkVersion = -1;
+      if (!(loader instanceof ZkSolrResourceLoader)) {
+        Entry<String, InputStream> localSchemaInput = readSchemaLocally();

Review Comment:
   It sucks to still see this because we have a NotThreadSafe annotation, thus I wasn't anticipating the checks.  From reading the [Infer/RacerD docs in more detail](https://fbinfer.com/docs/1.0.0/all-issue-types/#thread-safety-conditions-checked-before-reporting), it appears this is because this class, despite **not** being ThreadSafe, and advertising itself as such nonetheless contains the "synchronized" keyword in one spot at the end of create().  The presence of the keyword in the code takes precedence over NotThreadSafe annotation.  It seems to me we don't need that synchronized there because the schema is not published yet.  Any way, such changes / explorations don't belong here.  I'll create a PR to toy with this.



-- 
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.

To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org