Skip to content

Commit 37f743e

Browse files
author
Vladimir Kotal
authored
Index version check partial (#2167)
fixes #2166
1 parent 0a268a9 commit 37f743e

File tree

4 files changed

+48
-28
lines changed

4 files changed

+48
-28
lines changed

OpenGrok

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,8 @@ CheckIndexVersion()
864864
then
865865
return
866866
fi
867-
if ! MinimalInvocation --checkIndexVersion -R "${XML_CONFIGURATION}" -d "${DATA_ROOT}"
867+
if ! MinimalInvocation --checkIndexVersion \
868+
-R "${XML_CONFIGURATION}" -d "${DATA_ROOT}" "$@"
868869
then
869870
echo "\nIndex version check failed. You might want to remove all data" \
870871
"under the data root directory ${DATA_ROOT} and reindex.\n"
@@ -1143,7 +1144,7 @@ case "${1}" in
11431144
FatalError "need configuration via OPENGROK_READ_XML_CONFIGURATION"
11441145
fi
11451146
ValidateConfiguration
1146-
CheckIndexVersion
1147+
CheckIndexVersion $@
11471148
CreateRuntimeRequirements
11481149
UpdateDataPartial $@
11491150
;;

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import java.io.File;
2626
import java.io.IOException;
27+
import java.util.List;
2728
import org.apache.lucene.index.IndexNotFoundException;
2829
import org.apache.lucene.index.SegmentInfos;
2930
import org.apache.lucene.store.Directory;
@@ -52,16 +53,25 @@ public IndexVersionException(String s) {
5253
/**
5354
* Check if version of index(es) matches major Lucene version.
5455
* @param cfg configuration
56+
* @param subFilesList list of paths. If non-empty, only projects matching these paths will be checked.
5557
* @throws Exception otherwise
5658
*/
57-
public static void check(Configuration cfg) throws Exception {
59+
public static void check(Configuration cfg, List<String> subFilesList) throws Exception {
5860
File indexRoot = new File(cfg.getDataRoot(), IndexDatabase.INDEX_DIR);
59-
if (cfg.isProjectsEnabled()) {
60-
for (String projectName : cfg.getProjects().keySet()) {
61+
62+
if (!subFilesList.isEmpty()) {
63+
// Assumes projects are enabled.
64+
for (String projectName : subFilesList) {
6165
checkDir(getDirectory(new File(indexRoot, projectName)));
6266
}
6367
} else {
64-
checkDir(getDirectory(indexRoot));
68+
if (cfg.isProjectsEnabled()) {
69+
for (String projectName : cfg.getProjects().keySet()) {
70+
checkDir(getDirectory(new File(indexRoot, projectName)));
71+
}
72+
} else {
73+
checkDir(getDirectory(indexRoot));
74+
}
6575
}
6676
}
6777

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -144,19 +144,6 @@ public static void main(String argv[]) {
144144
System.exit(status);
145145
}
146146

147-
// Check version of index(es) versus current Lucene version and exit
148-
// with return code indicating success or failure.
149-
if (checkIndexVersion) {
150-
int retval = 0;
151-
try {
152-
IndexVersion.check(cfg);
153-
} catch (IndexVersionException e) {
154-
System.err.printf("Index version check failed: %s", e);
155-
retval = 1;
156-
}
157-
System.exit(retval);
158-
}
159-
160147
if (awaitProfiler) pauseToAwaitProfiler();
161148

162149
env = RuntimeEnvironment.getInstance();
@@ -206,11 +193,24 @@ public static void main(String argv[]) {
206193
// Assemble the unprocessed command line arguments (possibly
207194
// a list of paths). This will be used to perform more fine
208195
// grained checking in invalidateRepositories().
209-
for (int optind=0; optind< argv.length; optind++) {
196+
for (int optind = 0; optind < argv.length; optind++) {
210197
String path = Paths.get(cfg.getSourceRoot(), argv[optind]).toString();
211198
subFilesList.add(path);
212199
}
213200

201+
// Check version of index(es) versus current Lucene version and exit
202+
// with return code indicating success or failure.
203+
if (checkIndexVersion) {
204+
int retval = 0;
205+
try {
206+
IndexVersion.check(cfg, subFilesList);
207+
} catch (IndexVersionException e) {
208+
System.err.printf("Index version check failed: %s", e);
209+
retval = 1;
210+
}
211+
System.exit(retval);
212+
}
213+
214214
// If an user used customizations for projects he perhaps just
215215
// used the key value for project without a name but the code
216216
// expects a name for the project. Therefore we fill the name

test/org/opensolaris/opengrok/index/IndexVersionTest.java

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
import java.nio.file.Files;
2929
import java.nio.file.Path;
3030
import java.util.ArrayList;
31+
import java.util.Arrays;
32+
import java.util.List;
3133
import org.junit.After;
3234
import static org.junit.Assert.assertNotNull;
3335
import static org.junit.Assert.assertTrue;
@@ -47,6 +49,7 @@
4749

4850
/**
4951
* Verify index version check.
52+
*
5053
* @author Vladimir Kotal
5154
*/
5255
public class IndexVersionTest {
@@ -85,32 +88,38 @@ public void tearDown() throws IOException {
8588
* Generate index(es) and check version.
8689
* @throws Exception
8790
*/
88-
private void testIndexVersion(boolean projectsEnabled) throws Exception {
91+
private void testIndexVersion(boolean projectsEnabled, List<String> subFiles) throws Exception {
8992
env.setVerbose(true);
9093
env.setHistoryEnabled(false);
9194
env.setProjectsEnabled(projectsEnabled);
9295
Indexer.getInstance().prepareIndexer(env, true, true, null,
9396
false, false, null, null, new ArrayList<>(), false);
9497
Indexer.getInstance().doIndexerExecution(true, null, null);
9598

96-
IndexVersion.check(env.getConfiguration());
99+
IndexVersion.check(env.getConfiguration(), subFiles);
97100
}
98101

99102
@Test
100103
public void testIndexVersionNoIndex() throws Exception {
101-
IndexVersion.check(env.getConfiguration());
104+
IndexVersion.check(env.getConfiguration(), new ArrayList<>());
102105
}
103106

104107
@Test
105108
@ConditionalRun(CtagsInstalled.class)
106-
public void testIndexVersionNoProjects() throws Exception {
107-
testIndexVersion(true);
109+
public void testIndexVersionProjects() throws Exception {
110+
testIndexVersion(true, new ArrayList<>());
108111
}
109112

110113
@Test
111114
@ConditionalRun(CtagsInstalled.class)
112-
public void testIndexVersionProjects() throws Exception {
113-
testIndexVersion(false);
115+
public void testIndexVersionSelectedProjects() throws Exception {
116+
testIndexVersion(true, Arrays.asList(new String[]{ "mercurial", "git" }));
117+
}
118+
119+
@Test
120+
@ConditionalRun(CtagsInstalled.class)
121+
public void testIndexVersionNoProjects() throws Exception {
122+
testIndexVersion(false, new ArrayList<>());
114123
}
115124

116125
@Test(expected = IndexVersion.IndexVersionException.class)
@@ -128,6 +137,6 @@ public void testIndexVersionOldIndex() throws Exception {
128137
FileUtilities.extractArchive(archive, indexDir);
129138
cfg.setDataRoot(oldIndexDataDir.toString());
130139
cfg.setProjectsEnabled(false);
131-
IndexVersion.check(cfg);
140+
IndexVersion.check(cfg, new ArrayList<>());
132141
}
133142
}

0 commit comments

Comments
 (0)