You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mv...@apache.org on 2012/03/23 15:11:28 UTC
svn commit: r1304357 - in /lucene/dev/branches/branch_3x/solr: ./
core/src/java/org/apache/solr/core/ core/src/test-files/solr/conf/
core/src/test/org/apache/solr/core/
Author: mvg
Date: Fri Mar 23 14:11:28 2012
New Revision: 1304357
URL: http://svn.apache.org/viewvc?rev=1304357&view=rev
Log:
SOLR-3156: Check for Lucene directory locks at startup.
Added:
lucene/dev/branches/branch_3x/solr/core/src/test-files/solr/conf/solrconfig-nativelock.xml
lucene/dev/branches/branch_3x/solr/core/src/test-files/solr/conf/solrconfig-simplelock.xml
lucene/dev/branches/branch_3x/solr/core/src/test/org/apache/solr/core/SolrCoreCheckLockOnStartupTest.java
Modified:
lucene/dev/branches/branch_3x/solr/CHANGES.txt
lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/core/SolrCore.java
Modified: lucene/dev/branches/branch_3x/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/solr/CHANGES.txt?rev=1304357&r1=1304356&r2=1304357&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/solr/CHANGES.txt (original)
+++ lucene/dev/branches/branch_3x/solr/CHANGES.txt Fri Mar 23 14:11:28 2012
@@ -313,6 +313,9 @@ Other Changes
* SOLR-2712: expecting fl=score to return all fields is now deprecated.
In solr 4.0, this will only return the score. (ryan)
+* SOLR-3156: Check for Lucene directory locks at startup. In previous versions
+ this check was only performed during modifying (e.g. adding and deleting
+ documents) the index. (Luca Cavanna via Martijn van Groningen)
Build
----------------------
Modified: lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/core/SolrCore.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/core/SolrCore.java?rev=1304357&r1=1304356&r2=1304357&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/core/SolrCore.java (original)
+++ lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/core/SolrCore.java Fri Mar 23 14:11:28 2012
@@ -17,11 +17,13 @@
package org.apache.solr.core;
+import org.apache.commons.io.IOUtils;
import org.apache.lucene.index.IndexDeletionPolicy;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.LockObtainFailedException;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.params.CommonParams.EchoParamStyle;
@@ -31,18 +33,9 @@ import org.apache.solr.common.util.Simpl
import org.apache.solr.handler.admin.ShowFileRequestHandler;
import org.apache.solr.handler.component.*;
import org.apache.solr.highlight.SolrHighlighter;
-import org.apache.solr.request.*;
+import org.apache.solr.request.SolrQueryRequest;
+import org.apache.solr.request.SolrRequestHandler;
import org.apache.solr.response.*;
-import org.apache.solr.response.BinaryResponseWriter;
-import org.apache.solr.response.JSONResponseWriter;
-import org.apache.solr.response.PHPResponseWriter;
-import org.apache.solr.response.PHPSerializedResponseWriter;
-import org.apache.solr.response.PythonResponseWriter;
-import org.apache.solr.response.QueryResponseWriter;
-import org.apache.solr.response.RawResponseWriter;
-import org.apache.solr.response.RubyResponseWriter;
-import org.apache.solr.response.SolrQueryResponse;
-import org.apache.solr.response.XMLResponseWriter;
import org.apache.solr.schema.IndexSchema;
import org.apache.solr.search.QParserPlugin;
import org.apache.solr.search.SolrFieldCacheMBean;
@@ -57,21 +50,19 @@ import org.apache.solr.update.processor.
import org.apache.solr.update.processor.UpdateRequestProcessorFactory;
import org.apache.solr.util.RefCounted;
import org.apache.solr.util.plugin.NamedListInitializedPlugin;
-import org.apache.solr.util.plugin.SolrCoreAware;
import org.apache.solr.util.plugin.PluginInfoInitialized;
-import org.apache.commons.io.IOUtils;
+import org.apache.solr.util.plugin.SolrCoreAware;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.xml.sax.SAXException;
import javax.xml.parsers.ParserConfigurationException;
-
import java.io.*;
+import java.lang.reflect.Constructor;
+import java.net.URL;
import java.util.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import java.net.URL;
-import java.lang.reflect.Constructor;
/**
@@ -380,14 +371,19 @@ public final class SolrCore implements S
initIndexReaderFactory();
- if (indexExists && firstTime && removeLocks) {
+ if (indexExists && firstTime) {
// to remove locks, the directory must already exist... so we create it
// if it didn't exist already...
Directory dir = SolrIndexWriter.getDirectory(indexDir, getDirectoryFactory(), solrConfig.mainIndexConfig);
if (dir != null) {
if (IndexWriter.isLocked(dir)) {
- log.warn(logid+"WARNING: Solr index directory '" + indexDir + "' is locked. Unlocking...");
- IndexWriter.unlock(dir);
+ if (removeLocks) {
+ log.warn(logid + "WARNING: Solr index directory '{}' is locked. Unlocking...", indexDir);
+ IndexWriter.unlock(dir);
+ } else {
+ log.error(logid + "Solr index directory '{}' is locked. Throwing exception", indexDir);
+ throw new LockObtainFailedException("Index locked for write for core " + name);
+ }
}
dir.close();
}
Added: lucene/dev/branches/branch_3x/solr/core/src/test-files/solr/conf/solrconfig-nativelock.xml
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/solr/core/src/test-files/solr/conf/solrconfig-nativelock.xml?rev=1304357&view=auto
==============================================================================
--- lucene/dev/branches/branch_3x/solr/core/src/test-files/solr/conf/solrconfig-nativelock.xml (added)
+++ lucene/dev/branches/branch_3x/solr/core/src/test-files/solr/conf/solrconfig-nativelock.xml Fri Mar 23 14:11:28 2012
@@ -0,0 +1,33 @@
+<?xml version="1.0" ?>
+
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<config>
+ <!--
+ Config file used by SolrCoreCheckLockOnStartupTest#testNativeLockErrorOnStartup
+ It requires the native lockType
+ -->
+ <jmx />
+
+ <dataDir>${solr.data.dir:}</dataDir>
+
+ <luceneMatchVersion>${tests.luceneMatchVersion:LUCENE_CURRENT}</luceneMatchVersion>
+
+ <indexDefaults>
+ <lockType>native</lockType>
+ </indexDefaults>
+</config>
Added: lucene/dev/branches/branch_3x/solr/core/src/test-files/solr/conf/solrconfig-simplelock.xml
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/solr/core/src/test-files/solr/conf/solrconfig-simplelock.xml?rev=1304357&view=auto
==============================================================================
--- lucene/dev/branches/branch_3x/solr/core/src/test-files/solr/conf/solrconfig-simplelock.xml (added)
+++ lucene/dev/branches/branch_3x/solr/core/src/test-files/solr/conf/solrconfig-simplelock.xml Fri Mar 23 14:11:28 2012
@@ -0,0 +1,33 @@
+<?xml version="1.0" ?>
+
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<config>
+ <!--
+ Config file used by SolrCoreCheckLockOnStartupTest#testSimpleLockErrorOnStartup
+ It requires the simple lockType
+ -->
+ <jmx />
+
+ <dataDir>${solr.data.dir:}</dataDir>
+
+ <luceneMatchVersion>${tests.luceneMatchVersion:LUCENE_CURRENT}</luceneMatchVersion>
+
+ <indexDefaults>
+ <lockType>simple</lockType>
+ </indexDefaults>
+</config>
Added: lucene/dev/branches/branch_3x/solr/core/src/test/org/apache/solr/core/SolrCoreCheckLockOnStartupTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/solr/core/src/test/org/apache/solr/core/SolrCoreCheckLockOnStartupTest.java?rev=1304357&view=auto
==============================================================================
--- lucene/dev/branches/branch_3x/solr/core/src/test/org/apache/solr/core/SolrCoreCheckLockOnStartupTest.java (added)
+++ lucene/dev/branches/branch_3x/solr/core/src/test/org/apache/solr/core/SolrCoreCheckLockOnStartupTest.java Fri Mar 23 14:11:28 2012
@@ -0,0 +1,101 @@
+package org.apache.solr.core;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.index.IndexWriterConfig;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.LockObtainFailedException;
+import org.apache.lucene.store.NativeFSLockFactory;
+import org.apache.lucene.store.SimpleFSLockFactory;
+import org.apache.lucene.util.Version;
+import org.apache.solr.SolrTestCaseJ4;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.File;
+
+public class SolrCoreCheckLockOnStartupTest extends SolrTestCaseJ4 {
+
+ @Before
+ public void setUp() throws Exception {
+ super.setUp();
+
+ System.setProperty("solr.directoryFactory", "org.apache.solr.core.SimpleFSDirectoryFactory");
+
+ //explicitly creates the temp dataDir so we know where the index will be located
+ createTempDir();
+
+ IndexWriterConfig indexWriterConfig = new IndexWriterConfig(Version.LUCENE_36, null);
+ Directory directory = newFSDirectory(new File(dataDir, "index"));
+ //creates a new index on the known location
+ new IndexWriter(
+ directory,
+ indexWriterConfig.setOpenMode(IndexWriterConfig.OpenMode.CREATE)
+ ).close();
+ directory.close();
+ }
+
+ @Test
+ public void testSimpleLockErrorOnStartup() throws Exception {
+
+ Directory directory = newFSDirectory(new File(dataDir, "index"), new SimpleFSLockFactory());
+ //creates a new IndexWriter without releasing the lock yet
+ IndexWriter indexWriter = new IndexWriter(directory, new IndexWriterConfig(Version.LUCENE_36, null));
+
+ try {
+ //opening a new core on the same index
+ initCore("solrconfig-simplelock.xml", "schema.xml");
+ fail("Expected " + LockObtainFailedException.class.getSimpleName());
+ } catch (Throwable t) {
+ assertTrue(t instanceof RuntimeException);
+ assertNotNull(t.getCause());
+ assertTrue(t.getCause() instanceof RuntimeException);
+ assertNotNull(t.getCause().getCause());
+ assertTrue(t.getCause().getCause() instanceof LockObtainFailedException);
+ } finally {
+ indexWriter.close();
+ directory.close();
+ deleteCore();
+ }
+ }
+
+ @Test
+ public void testNativeLockErrorOnStartup() throws Exception {
+
+ Directory directory = newFSDirectory(new File(dataDir, "index"), new NativeFSLockFactory());
+ //creates a new IndexWriter without releasing the lock yet
+ IndexWriter indexWriter = new IndexWriter(directory, new IndexWriterConfig(Version.LUCENE_36, null));
+
+ try {
+ //opening a new core on the same index
+ initCore("solrconfig-nativelock.xml", "schema.xml");
+ fail("Expected " + LockObtainFailedException.class.getSimpleName());
+ } catch(Throwable t) {
+ assertTrue(t instanceof RuntimeException);
+ assertNotNull(t.getCause());
+ assertTrue(t.getCause() instanceof RuntimeException);
+ assertNotNull(t.getCause().getCause());
+ assertTrue(t.getCause().getCause() instanceof LockObtainFailedException);
+ } finally {
+ indexWriter.close();
+ directory.close();
+ deleteCore();
+ }
+ }
+}