Skip to content

Commit 48bd3b3

Browse files
committed
Support Lucene NativeFSLockFactory too
1 parent 58fb83d commit 48bd3b3

File tree

6 files changed

+108
-17
lines changed

6 files changed

+108
-17
lines changed

OpenGrok

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@
4343
# options for CTags program (for its --options
4444
# switch), default is DATA_ROOT/etc/ctags.config
4545
# - OPENGROK_MANDOC Full path to mandoc(1) binary
46-
# - OPENGROK_LOCKING Lucene SimpleFSLockFactory on|off (default off)
46+
# - OPENGROK_LOCKING Locking mode on|off|simple|native (default off)
47+
# ("on" is an alias for "simple")
4748
# - JAVA_HOME Full Path to Java Installation Root
4849
# - JAVA Full Path to java binary (to enable 64bit JDK)
4950
# - JAVA_OPTS Java options (e.g. for JVM memory increase

src/org/opensolaris/opengrok/configuration/Configuration.java

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,18 @@ public final class Configuration {
168168
private String webappLAF;
169169
private RemoteSCM remoteScmSupported;
170170
private boolean optimizeDatabase;
171+
/**
172+
* @deprecated This is kept around so not to break object deserialization.
173+
* <p>Anyone who is using `--lock on` will now be setting
174+
* {@link #luceneLocking} and resetting this field back to its default
175+
* value. This should mean that the configuration is written leaving out
176+
* this deprecated property; so after some time it can be retired with the
177+
* expectation that zero or a miniscule number of production configurations
178+
* still have this deprecated property.
179+
*/
180+
@Deprecated
171181
private boolean usingLuceneLocking;
182+
private String luceneLocking = LuceneLockName.OFF;
172183
private boolean compressXref;
173184
private boolean indexVersionedFilesOnly;
174185
private boolean tagsEnabled;
@@ -913,16 +924,35 @@ public void setOptimizeDatabase(boolean optimizeDatabase) {
913924
this.optimizeDatabase = optimizeDatabase;
914925
}
915926

927+
@Deprecated
916928
public boolean isUsingLuceneLocking() {
917-
return usingLuceneLocking;
929+
return LuceneLockName.SIMPLE.equals(luceneLocking) ||
930+
LuceneLockName.ON.equals(luceneLocking);
918931
}
919932

933+
@Deprecated
920934
public boolean getUsingLuceneLocking() {
921-
return usingLuceneLocking;
935+
return isUsingLuceneLocking();
922936
}
923937

938+
@Deprecated
924939
public void setUsingLuceneLocking(boolean useLuceneLocking) {
925-
this.usingLuceneLocking = useLuceneLocking;
940+
setLuceneLocking(useLuceneLocking ? LuceneLockName.ON :
941+
LuceneLockName.OFF);
942+
}
943+
944+
public String getLuceneLocking() {
945+
return luceneLocking;
946+
}
947+
948+
/**
949+
* @param value off|on|simple|native where "on" is an alias for "simple".
950+
* Any other value is a fallback alias for "off" (with a logged warning).
951+
*/
952+
public void setLuceneLocking(String value) {
953+
this.luceneLocking = value;
954+
// Set the following to default(boolean) regardless of `value'.
955+
this.usingLuceneLocking = false;
926956
}
927957

928958
public void setCompressXref(boolean compressXref) {
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* CDDL HEADER START
3+
*
4+
* The contents of this file are subject to the terms of the
5+
* Common Development and Distribution License (the "License").
6+
* You may not use this file except in compliance with the License.
7+
*
8+
* See LICENSE.txt included in this distribution for the specific
9+
* language governing permissions and limitations under the License.
10+
*
11+
* When distributing Covered Code, include this CDDL HEADER in each
12+
* file and include the License file at LICENSE.txt.
13+
* If applicable, add the following below this CDDL HEADER, with the
14+
* fields enclosed by brackets "[]" replaced with your own identifying
15+
* information: Portions Copyright [yyyy] [name of copyright owner]
16+
*
17+
* CDDL HEADER END
18+
*/
19+
20+
/*
21+
* Copyright (c) 2017, Chris Fraire <[email protected]>.
22+
*/
23+
24+
package org.opensolaris.opengrok.configuration;
25+
26+
/**
27+
* Represents a container for OpenGrok's names of Lucene lock modes.
28+
*/
29+
public class LuceneLockName {
30+
public static final String OFF = "off";
31+
/**
32+
* An alias for {@link #SIMPLE}
33+
*/
34+
public static final String ON = "on";
35+
public static final String SIMPLE = "simple";
36+
public static final String NATIVE = "native";
37+
38+
/** private to enforce static */
39+
private LuceneLockName() {
40+
}
41+
}

src/org/opensolaris/opengrok/configuration/RuntimeEnvironment.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,12 +1047,8 @@ public void setOptimizeDatabase(boolean optimizeDatabase) {
10471047
threadConfig.get().setOptimizeDatabase(optimizeDatabase);
10481048
}
10491049

1050-
public boolean isUsingLuceneLocking() {
1051-
return threadConfig.get().isUsingLuceneLocking();
1052-
}
1053-
1054-
public void setUsingLuceneLocking(boolean useLuceneLocking) {
1055-
threadConfig.get().setUsingLuceneLocking(useLuceneLocking);
1050+
public String getLuceneLocking() {
1051+
return threadConfig.get().getLuceneLocking();
10561052
}
10571053

10581054
public boolean isIndexVersionedFilesOnly() {

src/org/opensolaris/opengrok/index/IndexDatabase.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
import org.apache.lucene.search.TopDocs;
6666
import org.apache.lucene.store.FSDirectory;
6767
import org.apache.lucene.store.LockFactory;
68+
import org.apache.lucene.store.NativeFSLockFactory;
6869
import org.apache.lucene.store.NoLockFactory;
6970
import org.apache.lucene.store.SimpleFSLockFactory;
7071
import org.apache.lucene.util.BytesRef;
@@ -73,6 +74,7 @@
7374
import org.opensolaris.opengrok.analysis.Definitions;
7475
import org.opensolaris.opengrok.analysis.FileAnalyzer;
7576
import org.opensolaris.opengrok.analysis.FileAnalyzer.Genre;
77+
import org.opensolaris.opengrok.configuration.LuceneLockName;
7678
import org.opensolaris.opengrok.configuration.Project;
7779
import org.opensolaris.opengrok.configuration.RuntimeEnvironment;
7880
import org.opensolaris.opengrok.configuration.messages.Message;
@@ -142,7 +144,7 @@ public IndexDatabase() throws IOException {
142144
*/
143145
public IndexDatabase(Project project) throws IOException {
144146
this.project = project;
145-
lockfact = SimpleFSLockFactory.INSTANCE;
147+
lockfact = NoLockFactory.INSTANCE;
146148
initialize();
147149
}
148150

@@ -271,9 +273,7 @@ private void initialize() throws IOException {
271273
}
272274
}
273275

274-
if (!env.isUsingLuceneLocking()) {
275-
lockfact = NoLockFactory.INSTANCE;
276-
}
276+
lockfact = pickLockFactory(env);
277277
indexDirectory = FSDirectory.open(indexDir.toPath(), lockfact);
278278
ignoredNames = env.getIgnoredNames();
279279
includedNames = env.getIncludedNames();
@@ -1328,4 +1328,21 @@ private Writer getXrefWriter(FileAnalyzer fa, String path) throws IOException {
13281328
// no Xref for this analyzer
13291329
return null;
13301330
}
1331+
1332+
LockFactory pickLockFactory(RuntimeEnvironment env) {
1333+
String luceneLocking = env.getLuceneLocking();
1334+
switch (luceneLocking) {
1335+
case LuceneLockName.OFF:
1336+
return NoLockFactory.INSTANCE;
1337+
case LuceneLockName.ON:
1338+
case LuceneLockName.SIMPLE:
1339+
return SimpleFSLockFactory.INSTANCE;
1340+
case LuceneLockName.NATIVE:
1341+
return NativeFSLockFactory.INSTANCE;
1342+
default:
1343+
LOGGER.log(Level.WARNING, "Unknown Lucene locking mode: {0}",
1344+
luceneLocking);
1345+
return NoLockFactory.INSTANCE;
1346+
}
1347+
}
13311348
}

src/org/opensolaris/opengrok/index/Indexer.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import org.opensolaris.opengrok.Info;
4848
import org.opensolaris.opengrok.analysis.AnalyzerGuru;
4949
import org.opensolaris.opengrok.configuration.Configuration;
50+
import org.opensolaris.opengrok.configuration.LuceneLockName;
5051
import org.opensolaris.opengrok.configuration.Project;
5152
import org.opensolaris.opengrok.configuration.RuntimeEnvironment;
5253
import org.opensolaris.opengrok.configuration.messages.Message;
@@ -342,6 +343,9 @@ public static String[] parseOptions(String[] argv) throws ParseException {
342343
String program = "opengrok.jar";
343344
final String[] ON_OFF = {ON, OFF};
344345
final String[] REMOTE_REPO_CHOICES = {ON, OFF, DIRBASED, UIONLY};
346+
final String[] LUCENE_LOCKS = {LuceneLockName.ON,
347+
LuceneLockName.OFF, LuceneLockName.SIMPLE,
348+
LuceneLockName.NATIVE};
345349

346350
if (argv.length == 0) {
347351
argv = usage; // will force usage output
@@ -468,9 +472,11 @@ public static String[] parseOptions(String[] argv) throws ParseException {
468472
cfg.getIgnoredNames().add((String)pattern);
469473
});
470474

471-
parser.on("-l", "--lock", "=on|off", ON_OFF, Boolean.class,
472-
"Turn on|off locking of the Lucene database during index generation.").Do( v -> {
473-
cfg.setUsingLuceneLocking((Boolean)v);
475+
parser.on("-l", "--lock", "=on|off|simple|native", LUCENE_LOCKS,
476+
"Set OpenGrok/Lucene locking mode of the Lucene database",
477+
"during index generation. \"on\" is an alias for \"simple\".",
478+
"Default is off.").Do( v -> {
479+
cfg.setLuceneLocking((String)v);
474480
});
475481

476482
parser.on("--leadingWildCards", "=on|off", ON_OFF, Boolean.class,

0 commit comments

Comments
 (0)