You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by "Mark Miller (JIRA)" <ji...@apache.org> on 2014/03/24 16:13:42 UTC
[jira] [Commented] (SOLR-5903) SolrCore should implement Closeable
[ https://issues.apache.org/jira/browse/SOLR-5903?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13945200#comment-13945200 ]
Mark Miller commented on SOLR-5903:
-----------------------------------
Great idea - first thing I noticed on a glance was this part where the success boolean is still defined but not used ... is this right? Seems we will cancel every time?
{noformat}
boolean success = false;
try {
@@ -299,8 +292,8 @@ final class ShardLeaderElectionContext extends ShardLeaderElectionContextBase {
} catch (Exception e) {
SolrException.log(log, "There was a problem trying to register as the leader", e);
- try {
- core = cc.getCore(coreName);
+ try (SolrCore core = cc.getCore(coreName)) {
+
if (core == null) {
throw new SolrException(ErrorCode.SERVER_ERROR,
"Fatal Error, SolrCore not found:" + coreName + " in "
@@ -312,16 +305,7 @@ final class ShardLeaderElectionContext extends ShardLeaderElectionContextBase {
// we could not publish ourselves as leader - rejoin election
rejoinLeaderElection(leaderSeqPath, core);
} finally {
- try {
- if (!success) {
- cancelElection();
- }
- } finally {
- if (core != null) {
- core.close();
- }
- }
-
+ cancelElection();
}
}
{noformat}
> SolrCore should implement Closeable
> -----------------------------------
>
> Key: SOLR-5903
> URL: https://issues.apache.org/jira/browse/SOLR-5903
> Project: Solr
> Issue Type: Improvement
> Reporter: Alan Woodward
> Assignee: Alan Woodward
> Attachments: SOLR-5903.patch
>
>
> Now that we're on Java 7, we can use try-with-resources everywhere we open/close SolrCores.
--
This message was sent by Atlassian JIRA
(v6.2#6252)
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org