SOLR-1108 -- Remove un-needed synchronization in SolrCore constructor

git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@767430 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Shalin Shekhar Mangar 2009-04-22 09:25:10 +00:00
parent 1ea1e3ca37
commit 742731754d
2 changed files with 83 additions and 83 deletions

View File

@ -234,6 +234,9 @@ Optimizations
8. SOLR-973: CommonsHttpSolrServer writes the xml directly to the server. 8. SOLR-973: CommonsHttpSolrServer writes the xml directly to the server.
(Noble Paul via shalin) (Noble Paul via shalin)
9. SOLR-1108: Remove un-needed synchronization in SolrCore constructor.
(Noble Paul via shalin)
Bug Fixes Bug Fixes
---------------------- ----------------------
1. SOLR-774: Fixed logging level display (Sean Timm via Otis Gospodnetic) 1. SOLR-774: Fixed logging level display (Sean Timm via Otis Gospodnetic)

View File

@ -354,12 +354,14 @@ public final class SolrCore implements SolrInfoMBean {
// protect via synchronized(SolrCore.class) // protect via synchronized(SolrCore.class)
private static Set<String> dirs = new HashSet<String>(); private static Set<String> dirs = new HashSet<String>();
// currently only called with SolrCore.class lock held
void initIndex() { void initIndex() {
try { try {
File dirFile = new File(getNewIndexDir()); File dirFile = new File(getNewIndexDir());
boolean indexExists = dirFile.canRead(); boolean indexExists = dirFile.canRead();
boolean firstTime = dirs.add(dirFile.getCanonicalPath()); boolean firstTime;
synchronized (SolrCore.class) {
firstTime = dirs.add(dirFile.getCanonicalPath());
}
boolean removeLocks = solrConfig.getBool("mainIndex/unlockOnStartup", false); boolean removeLocks = solrConfig.getBool("mainIndex/unlockOnStartup", false);
initDirectoryFactory(); initDirectoryFactory();
@ -483,100 +485,95 @@ public final class SolrCore implements SolrInfoMBean {
*@since solr 1.3 *@since solr 1.3
*/ */
public SolrCore(String name, String dataDir, SolrConfig config, IndexSchema schema, CoreDescriptor cd) { public SolrCore(String name, String dataDir, SolrConfig config, IndexSchema schema, CoreDescriptor cd) {
synchronized (SolrCore.class) { coreDescriptor = cd;
coreDescriptor = cd; this.setName( name );
// this is for backward compatibility (and also the reason SolrResourceLoader loader = config.getResourceLoader();
// the sync block is needed) if (dataDir == null)
instance = this; // set singleton dataDir = config.get("dataDir",cd.getDataDir());
this.setName( name );
SolrResourceLoader loader = config.getResourceLoader();
if (dataDir == null)
dataDir = config.get("dataDir",cd.getDataDir());
dataDir = SolrResourceLoader.normalizeDir(dataDir); dataDir = SolrResourceLoader.normalizeDir(dataDir);
log.info(logid+"Opening new SolrCore at " + loader.getInstanceDir() + ", dataDir="+dataDir); log.info(logid+"Opening new SolrCore at " + loader.getInstanceDir() + ", dataDir="+dataDir);
if (schema==null) { if (schema==null) {
schema = new IndexSchema(config, IndexSchema.DEFAULT_SCHEMA_FILE, null); schema = new IndexSchema(config, IndexSchema.DEFAULT_SCHEMA_FILE, null);
} }
//Initialize JMX //Initialize JMX
if (config.jmxConfig.enabled) { if (config.jmxConfig.enabled) {
infoRegistry = new JmxMonitoredMap<String, SolrInfoMBean>(name, config.jmxConfig); infoRegistry = new JmxMonitoredMap<String, SolrInfoMBean>(name, config.jmxConfig);
} else { } else {
log.info("JMX monitoring not detected for core: " + name); log.info("JMX monitoring not detected for core: " + name);
infoRegistry = new ConcurrentHashMap<String, SolrInfoMBean>(); infoRegistry = new ConcurrentHashMap<String, SolrInfoMBean>();
} }
this.schema = schema; this.schema = schema;
this.dataDir = dataDir; this.dataDir = dataDir;
this.solrConfig = config; this.solrConfig = config;
this.startTime = System.currentTimeMillis(); this.startTime = System.currentTimeMillis();
this.maxWarmingSearchers = config.getInt("query/maxWarmingSearchers",Integer.MAX_VALUE); this.maxWarmingSearchers = config.getInt("query/maxWarmingSearchers",Integer.MAX_VALUE);
booleanQueryMaxClauseCount(); booleanQueryMaxClauseCount();
parseListeners(); parseListeners();
initDeletionPolicy(); initDeletionPolicy();
initIndex(); initIndex();
initWriters(); initWriters();
initQParsers(); initQParsers();
initValueSourceParsers(); initValueSourceParsers();
this.searchComponents = loadSearchComponents( config ); this.searchComponents = loadSearchComponents( config );
// Processors initialized before the handlers // Processors initialized before the handlers
updateProcessorChains = loadUpdateProcessorChains(); updateProcessorChains = loadUpdateProcessorChains();
reqHandlers = new RequestHandlers(this); reqHandlers = new RequestHandlers(this);
reqHandlers.initHandlersFromConfig( solrConfig ); reqHandlers.initHandlersFromConfig( solrConfig );
highlighter = createHighlighter( highlighter = createHighlighter(
solrConfig.get("highlighting/@class", DefaultSolrHighlighter.class.getName()) solrConfig.get("highlighting/@class", DefaultSolrHighlighter.class.getName())
);
highlighter.initalize( solrConfig );
// Handle things that should eventually go away
initDeprecatedSupport();
final CountDownLatch latch = new CountDownLatch(1);
try {
// cause the executor to stall so firstSearcher events won't fire
// until after inform() has been called for all components.
// searchExecutor must be single-threaded for this to work
searcherExecutor.submit(new Callable() {
public Object call() throws Exception {
latch.await();
return null;
}
});
// Open the searcher *before* the update handler so we don't end up opening
// one in the middle.
// With lockless commits in Lucene now, this probably shouldn't be an issue anymore
getSearcher(false,false,null);
updateHandler = createUpdateHandler(
solrConfig.get("updateHandler/@class", DirectUpdateHandler2.class.getName())
); );
highlighter.initalize( solrConfig );
// Handle things that should eventually go away infoRegistry.put("updateHandler", updateHandler);
initDeprecatedSupport();
final CountDownLatch latch = new CountDownLatch(1); // Finally tell anyone who wants to know
loader.inform( loader );
try { loader.inform( this );
// cause the executor to stall so firstSearcher events won't fire instance = this; // set singleton for backwards compatibility
// until after inform() has been called for all components. } catch (IOException e) {
// searchExecutor must be single-threaded for this to work throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
searcherExecutor.submit(new Callable() { } finally {
public Object call() throws Exception { // allow firstSearcher events to fire
latch.await(); latch.countDown();
return null; }
}
});
// Open the searcher *before* the update handler so we don't end up opening
// one in the middle.
// With lockless commits in Lucene now, this probably shouldn't be an issue anymore
getSearcher(false,false,null);
updateHandler = createUpdateHandler(
solrConfig.get("updateHandler/@class", DirectUpdateHandler2.class.getName())
);
infoRegistry.put("updateHandler", updateHandler);
// Finally tell anyone who wants to know
loader.inform( loader );
loader.inform( this );
} catch (IOException e) {
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
} finally {
// allow firstSearcher events to fire
latch.countDown();
}
} // end synchronized
infoRegistry.put("core", this); infoRegistry.put("core", this);
} }