Skip to content

Commit 927782e

Browse files
idodeclareVladimir Kotal
authored andcommitted
Subsume --checkIndexVersion into regular run
1 parent 3276371 commit 927782e

File tree

3 files changed

+39
-32
lines changed

3 files changed

+39
-32
lines changed

OpenGrok

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,10 @@ ${BZR:+-Dorg.opensolaris.opengrok.history.Bazaar=$BZR} \
449449
ASSIGNMENTS="`echo $OPENGROK_ASSIGNMENTS | sed 's/[:space:]+/_/g'`"
450450
ASSIGNMENTS="-A `echo $ASSIGNMENTS | sed 's/,/ -A /g'`"
451451
fi
452+
453+
if [ -f "${XML_CONFIGURATION}" ]; then
454+
CHK_INDEX_CONF="${XML_CONFIGURATION}"
455+
fi
452456
}
453457

454458
#
@@ -857,21 +861,6 @@ CreateRuntimeRequirements()
857861
fi
858862
}
859863

860-
CheckIndexVersion()
861-
{
862-
if [ ! -f "${XML_CONFIGURATION}" ]
863-
then
864-
return
865-
fi
866-
if ! MinimalInvocation --checkIndexVersion \
867-
-R "${XML_CONFIGURATION}" -d "${DATA_ROOT}" "$@"
868-
then
869-
echo "\nIndex version check failed. You might want to remove all data" \
870-
"under the data root directory ${DATA_ROOT} and reindex.\n"
871-
exit 1
872-
fi
873-
}
874-
875864
MinimalInvocation()
876865
{
877866
${DO} ${JAVA} ${JAVA_OPTS} ${PROPERTIES} \
@@ -900,6 +889,7 @@ CommonInvocation()
900889
${ASSIGNMENTS} \
901890
${READ_XML_CONF} \
902891
${WEBAPP_CONFIG} \
892+
${CHK_INDEX_CONF:+--checkIndexVersion} ${CHK_INDEX_CONF} \
903893
${OPENGROK_PROFILER:+--profiler} \
904894
"${@}"
905895
}
@@ -1086,14 +1076,12 @@ case "${1}" in
10861076

10871077
update)
10881078
ValidateConfiguration
1089-
CheckIndexVersion
10901079
CreateRuntimeRequirements
10911080
UpdateGeneratedData && UpdateDescriptionCache
10921081
;;
10931082

10941083
updateQuietly)
10951084
ValidateConfiguration
1096-
CheckIndexVersion
10971085
CreateRuntimeRequirements
10981086
QUIET="-q"
10991087
VERBOSE=""
@@ -1120,7 +1108,6 @@ case "${1}" in
11201108
SRC_ROOT="${2}"
11211109
fi
11221110
ValidateConfiguration
1123-
CheckIndexVersion
11241111
CreateRuntimeRequirements
11251112
UpdateGeneratedData && UpdateDescriptionCache
11261113
;;
@@ -1135,7 +1122,6 @@ case "${1}" in
11351122
FatalError "need configuration via OPENGROK_READ_XML_CONFIGURATION"
11361123
fi
11371124
ValidateConfiguration
1138-
CheckIndexVersion $@
11391125
CreateRuntimeRequirements
11401126
UpdateDataPartial $@
11411127
;;

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,15 @@
1919

2020
/*
2121
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
22+
* Portions Copyright (c) 2018, Chris Fraire <[email protected]>.
2223
*/
2324
package org.opensolaris.opengrok.index;
2425

2526
import java.io.File;
2627
import java.io.IOException;
2728
import java.util.List;
29+
import java.util.logging.Level;
30+
import java.util.logging.Logger;
2831
import org.apache.lucene.index.IndexNotFoundException;
2932
import org.apache.lucene.index.SegmentInfos;
3033
import org.apache.lucene.store.Directory;
@@ -33,13 +36,17 @@
3336
import org.apache.lucene.store.NativeFSLockFactory;
3437
import org.apache.lucene.util.Version;
3538
import org.opensolaris.opengrok.configuration.Configuration;
39+
import org.opensolaris.opengrok.logger.LoggerFactory;
3640

3741
/**
3842
* Index version checker
3943
*
4044
* @author Vladimir Kotal
4145
*/
4246
public class IndexVersion {
47+
private static final Logger LOGGER =
48+
LoggerFactory.getLogger(IndexVersion.class);
49+
4350
/**
4451
* exception thrown when index version does not match Lucene version
4552
*/
@@ -58,18 +65,28 @@ public IndexVersionException(String s) {
5865
*/
5966
public static void check(Configuration cfg, List<String> subFilesList) throws Exception {
6067
File indexRoot = new File(cfg.getDataRoot(), IndexDatabase.INDEX_DIR);
68+
LOGGER.log(Level.FINE, "Checking for Lucene index version mismatch in {0}",
69+
indexRoot);
6170

6271
if (!subFilesList.isEmpty()) {
6372
// Assumes projects are enabled.
6473
for (String projectName : subFilesList) {
74+
LOGGER.log(Level.FINER,
75+
"Checking Lucene index version in project {0}",
76+
projectName);
6577
checkDir(getDirectory(new File(indexRoot, projectName)));
6678
}
6779
} else {
6880
if (cfg.isProjectsEnabled()) {
6981
for (String projectName : cfg.getProjects().keySet()) {
82+
LOGGER.log(Level.FINER,
83+
"Checking Lucene index version in project {0}",
84+
projectName);
7085
checkDir(getDirectory(new File(indexRoot, projectName)));
7186
}
7287
} else {
88+
LOGGER.log(Level.FINER, "Checking Lucene index version in {0}",
89+
indexRoot);
7390
checkDir(getDirectory(indexRoot));
7491
}
7592
}

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

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,14 @@ public final class Indexer {
8181

8282
private static final Indexer index = new Indexer();
8383
private static Configuration cfg = null;
84+
private static Configuration checkIndexVersionCfg;
8485
private static boolean listRepos = false;
8586
private static boolean runIndex = true;
8687
private static boolean optimizedChanged = false;
8788
private static boolean addProjects = false;
8889
private static boolean searchRepositories = false;
8990
private static boolean noindex = false;
9091
private static boolean awaitProfiler;
91-
private static boolean checkIndexVersion = false;
9292

9393
private static boolean help;
9494
private static String helpUsage;
@@ -128,7 +128,6 @@ public static void main(String argv[]) {
128128
boolean createDict = false;
129129

130130
try {
131-
132131
argv = parseOptions(argv);
133132
if (help) {
134133
status = 1;
@@ -196,16 +195,17 @@ public static void main(String argv[]) {
196195
}
197196

198197
// Check version of index(es) versus current Lucene version and exit
199-
// with return code indicating success or failure.
200-
if (checkIndexVersion) {
201-
int retval = 0;
198+
// with return code upon failure.
199+
if (checkIndexVersionCfg != null) {
202200
try {
203-
IndexVersion.check(cfg, subFilesList);
201+
IndexVersion.check(checkIndexVersionCfg, subFilesList);
204202
} catch (IndexVersionException e) {
205-
System.err.printf("Index version check failed: %s", e);
206-
retval = 1;
203+
System.err.printf("Index version check failed: %s\n", e);
204+
System.err.printf("You might want to remove all data " +
205+
"under the DATA_ROOT and to reindex\n");
206+
status = 1;
207+
System.exit(status);
207208
}
208-
System.exit(retval);
209209
}
210210

211211
// If an user used customizations for projects he perhaps just
@@ -388,7 +388,7 @@ public static String[] parseOptions(String[] argv) throws ParseException {
388388
OptionParser configure = OptionParser.scan(parser -> {
389389
parser.on("-R configPath").Do( cfgFile -> {
390390
try {
391-
cfg = Configuration.read(new File((String)cfgFile));
391+
cfg = Configuration.read(new File((String)cfgFile));
392392
} catch(IOException e) {
393393
die(e.getMessage());
394394
}
@@ -399,7 +399,6 @@ public static String[] parseOptions(String[] argv) throws ParseException {
399399
OptionParser.accept(WebAddress.class, s -> { return parseWebAddress(s); });
400400

401401
openGrok = OptionParser.Do(parser -> {
402-
403402
parser.setPrologue(
404403
String.format("\nUsage: java -jar %s [options] [subDir1 [...]]\n", program));
405404

@@ -442,9 +441,14 @@ public static String[] parseOptions(String[] argv) throws ParseException {
442441
}
443442
);
444443

445-
parser.on("--checkIndexVersion",
444+
parser.on("--checkIndexVersion", "=/path/to/conf",
446445
"Check if current Lucene version matches index version").Do( v -> {
447-
checkIndexVersion = true;
446+
try {
447+
File cfgFile = new File((String)v);
448+
checkIndexVersionCfg = Configuration.read(cfgFile);
449+
} catch(IOException|NullPointerException e) {
450+
die(e.getMessage());
451+
}
448452
});
449453

450454
parser.on("-d", "--dataRoot", "=/path/to/data/root",

0 commit comments

Comments
 (0)