dsmiley commented on code in PR #1302:
URL: https://github.com/apache/solr/pull/1302#discussion_r1081572121
##########
solr/core/src/java/org/apache/solr/schema/ManagedIndexSchemaFactory.java:
##########
@@ -198,88 +198,94 @@ public ManagedIndexSchema create(
this.loader = config.getResourceLoader();
InputStream schemaInputStream = 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)) {
+ 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 {
- schemaInputStream = loader.openResource(resourceName);
- loadedResource = resourceName;
- shouldUpgrade = true;
- } catch (IOException e) {
+ // 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);
+ }
+ if (null == schemaInputStream) {
+ // The managed schema file could not be found - load the non-managed
schema
try {
- // Retry to load the managed schema, in case it was created since
the first attempt
- byte[] data = zkClient.getData(managedSchemaPath, null, stat,
true);
- schemaZkVersion = stat.getVersion();
- schemaInputStream = new ByteArrayInputStream(data);
- loadedResource = managedSchemaPath;
- warnIfNonManagedSchemaExists();
- } catch (Exception e1) {
- if (e1 instanceof InterruptedException) {
- Thread.currentThread().interrupt(); // Restore the interrupted
status
+ schemaInputStream = loader.openResource(resourceName);
+ loadedResource = resourceName;
+ shouldUpgrade = true;
+ } catch (IOException e) {
+ try {
+ // Retry to load the managed schema, in case it was created
since the first attempt
+ byte[] data = zkClient.getData(managedSchemaPath, null, stat,
true);
+ schemaZkVersion = stat.getVersion();
+ schemaInputStream = new ByteArrayInputStream(data);
+ loadedResource = managedSchemaPath;
+ warnIfNonManagedSchemaExists();
+ } catch (Exception e1) {
+ if (e1 instanceof InterruptedException) {
+ Thread.currentThread().interrupt(); // Restore the interrupted
status
+ }
+ final String msg =
+ "Error loading both non-managed schema '"
+ + resourceName
+ + "' and managed schema '"
+ + managedSchemaResourceName
+ + "'";
+ log.error(msg, e);
+ throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
msg, e);
}
- final String msg =
- "Error loading both non-managed schema '"
- + resourceName
- + "' and managed schema '"
- + managedSchemaResourceName
- + "'";
- log.error(msg, e);
- throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, msg,
e);
}
}
}
+ InputSource inputSource = new InputSource(schemaInputStream);
+
inputSource.setSystemId(SystemIdResolver.createSystemIdFromResourceName(loadedResource));
Review Comment:
I don't think a SchemaFactory needs to be thread-safe. I see that they are
always created in order to call create() and then are thrown away, not saved
for potential re-use. Ideally if we annotate this class with
`net.jcip.annotations.NotThreadSafe` one would hope tooling could be smarter to
understand that THREAD_SAFETY_VIOLATION is impossible here. Lift doesn't do
its own analysis, it delegates to tools like "Infer" which has a module
"RacerD" that implements this particular THREAD_SAFETY_VIOLATION analysis. I
was looking into this last week -- it's kind of fascinating. I want to help
RacerD help Lift help us. When I look at RacerD docs, it sadly seems a bit
dated; doesn't recognized popular annotations like NotThreadSafe; it has its
own. In this case, an annotation
[ThreadConfined](https://fbinfer.com/docs/1.0.0/checker-racerd/#threadconfined)
should be equivalent. I'll report an issue there and to Lift as well.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]