Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.apache.lucene.store.ByteBuffersDirectory;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.LockFactory;
import org.apache.lucene.store.NoLockFactory;
import org.apache.lucene.store.SingleInstanceLockFactory;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.SolrException.ErrorCode;
Expand All @@ -29,13 +30,19 @@ public class ByteBuffersDirectoryFactory extends EphemeralDirectoryFactory {

@Override
protected LockFactory createLockFactory(String rawLockType) throws IOException {
if (rawLockType != null
&& DirectoryFactory.LOCK_TYPE_NONE.equalsIgnoreCase(rawLockType.trim())) {
return NoLockFactory.INSTANCE;
}
if (!(rawLockType == null
|| DirectoryFactory.LOCK_TYPE_SINGLE.equalsIgnoreCase(rawLockType.trim()))) {
throw new SolrException(
ErrorCode.FORBIDDEN,
"ByteBuffersDirectory can only be used with the '"
+ DirectoryFactory.LOCK_TYPE_SINGLE
+ "' lock factory type.");
+ "' or '"
+ DirectoryFactory.LOCK_TYPE_NONE
+ "' lock factory types.");
}
return new SingleInstanceLockFactory();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.apache.lucene.store.ByteBuffersDirectory;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.LockFactory;
import org.apache.lucene.store.NoLockFactory;
import org.apache.lucene.store.SingleInstanceLockFactory;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.SolrException.ErrorCode;
Expand All @@ -29,13 +30,19 @@ public class RAMDirectoryFactory extends EphemeralDirectoryFactory {

@Override
protected LockFactory createLockFactory(String rawLockType) throws IOException {
if (rawLockType != null
&& DirectoryFactory.LOCK_TYPE_NONE.equalsIgnoreCase(rawLockType.trim())) {
return NoLockFactory.INSTANCE;
}
if (!(rawLockType == null
|| DirectoryFactory.LOCK_TYPE_SINGLE.equalsIgnoreCase(rawLockType.trim()))) {
throw new SolrException(
ErrorCode.FORBIDDEN,
"RAMDirectory can only be used with the '"
+ DirectoryFactory.LOCK_TYPE_SINGLE
+ "' lock factory type.");
+ "' or '"
+ DirectoryFactory.LOCK_TYPE_NONE
+ "' lock factory types.");
}
return new SingleInstanceLockFactory();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

<directoryFactory class="solr.RAMDirectoryFactory"/>
<indexConfig>
<lockType>single</lockType>
<lockType>none</lockType>
</indexConfig>

<schemaFactory class="ClassicIndexSchemaFactory"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,18 @@
import org.apache.lucene.store.ByteBuffersDirectory;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.LockFactory;
import org.apache.lucene.store.NoLockFactory;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.core.DirectoryFactory.DirContext;

/** Test-case for ByteBuffersDirectoryFactory */
public class ByteBuffersDirectoryFactoryTest extends SolrTestCaseJ4 {

public void testLockTypeNone() throws IOException {
ByteBuffersDirectoryFactory factory = new ByteBuffersDirectoryFactory();
assertSame(NoLockFactory.INSTANCE, factory.createLockFactory(DirectoryFactory.LOCK_TYPE_NONE));
}

public void testOpenReturnsTheSameForSamePath() throws IOException {
final Directory directory = new ByteBuffersDirectory();
ByteBuffersDirectoryFactory factory =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.apache.lucene.store.ByteBuffersDirectory;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.LockFactory;
import org.apache.lucene.store.NoLockFactory;
import org.apache.solr.SolrTestCase;
import org.apache.solr.core.DirectoryFactory.DirContext;

Expand All @@ -31,6 +32,11 @@ public void test() throws Exception {
dotestOpenSucceedForEmptyDir();
}

public void testLockTypeNone() throws IOException {
RAMDirectoryFactory factory = new RAMDirectoryFactory();
assertSame(NoLockFactory.INSTANCE, factory.createLockFactory(DirectoryFactory.LOCK_TYPE_NONE));
}

private void dotestOpenReturnsTheSameForSamePath() throws IOException {
final Directory directory = new ByteBuffersDirectory();
RAMDirectoryFactory factory =
Expand Down
Loading