Skip to content

Commit 3f6755e

Browse files
author
Vladimir Kotal
authored
Project centric approach
fixes #1390
1 parent 8ac08f3 commit 3f6755e

39 files changed

+1028
-172
lines changed

OpenGrok

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ Usage()
105105

106106
exec >&2
107107
echo ""
108-
echo "Usage: ${progname} <deploy|derby|update|updateQuietly|usage|help>"
108+
echo "Usage: ${progname} <bootstrap|deploy|derby|update|updateQuietly|usage|help>"
109109
echo " ${progname} index [<directory>]"
110110
echo " ${progname} indexpart <src_root> <directory1> [..]"
111111
echo " ${progname} clearHistory <src_root> <repository_name>"
@@ -331,7 +331,7 @@ DefaultInstanceConfiguration()
331331

332332
# OPTIONAL: JVM Options
333333
JAVA_OPTS="${JAVA_OPTS:--Xmx2048m}"
334-
334+
335335
# OPTIONAL: Full Path to History Utilities
336336
BK="`Which bk`"
337337
HG="`Which hg`"
@@ -822,6 +822,8 @@ CommonInvocation()
822822
${CTAGS_OPTIONS_FILE:+-o} ${CTAGS_OPTIONS_FILE} \
823823
${OPENGROK_FLUSH_RAM_BUFFER_SIZE} ${SKIN} ${LEADING_WILDCARD} \
824824
${READ_XML_CONF} \
825+
${WEBAPP_CONFIG} \
826+
${WEBAPP_CONTEXT} \
825827
"${@}"
826828
}
827829

@@ -831,8 +833,6 @@ StdInvocation()
831833
-W ${XML_CONFIGURATION} \
832834
${SCAN_FOR_REPOSITORY} \
833835
${ENABLE_PROJECTS} \
834-
${WEBAPP_CONFIG} \
835-
${WEBAPP_CONTEXT} \
836836
-s "${SRC_ROOT}" \
837837
-d "${DATA_ROOT}" \
838838
"${@}"
@@ -1031,6 +1031,12 @@ case "${1}" in
10311031
UpdateDescriptionCache
10321032
;;
10331033

1034+
bootstrap)
1035+
ValidateConfiguration
1036+
CreateRuntimeRequirements
1037+
StdInvocation "-y"
1038+
;;
1039+
10341040
index)
10351041
if [ $# -gt 2 ]
10361042
then

README.txt

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,13 @@ Currently supported message types:
143143
reloads all authorization plugins.
144144
5) RefreshMesssage (refresh)
145145
Sent at the end of partial reindex to trigger refresh of SearcherManagers.
146+
6) ProjectMessage
147+
Used for adding/deleting projects and partial (per-project) reindex.
148+
- "add" adds project(s) and its repositories to the configuration.
149+
If the project already exists, refresh list of its repositories.
150+
- "delete" removes project(s) and its repositores from the configuration
151+
Also deletes its data under data root (but not the source code).
152+
- "indexed" mark the project(s) as indexed so it becomes visible in the UI
146153

147154
4. OpenGrok install
148155
-----------------
@@ -314,27 +321,49 @@ projects to finish syncing before running the indexer. To overcome this
314321
limitation, the index of each project can be created just after the
315322
mirroring of this project finishes.
316323

317-
Thus, the overall approach would be:
324+
Indexing of all projects (i.e. 'OpenGrok index /var/opengrok/src') in
325+
order to discover new and remove deleted projects from the configuration can be
326+
avoided. One can start with no index and no projects and then incrementally add
327+
them and index them.
318328

319-
1. create initial index of all the source code
329+
It basically works like this:
320330

321-
This will produce configuration.xml, optionally by combining the
322-
discovered projects with read-only configuration (as specified
323-
with OPENGROK_READ_XML_CONFIGURATION). This step has to be performed
324-
only once - during the initial OpenGrok setup.
331+
0. bootstrap initial configuration:
325332

326-
2. mirror and index all projects in parallel
333+
OpenGrok bootstrap
327334

328-
This is done by running indexpart command of the OpenGrok script and
329-
specifying the configuration.xml written in previous step as
330-
OPENGROK_READ_XML_CONFIGURATION. The configuration will help the indexer
331-
to discover source/data root and project to source path mapping.
335+
- this will create /var/opengrok/etc/configuration.xml with basic set of
336+
properties. If more is needed use:
332337

333-
3. perform complete reindex (like in step 1)
338+
Messages -n config -t set "set propertyXY = valueFOO"
334339

335-
Once all the pre-existing projects are mirrored and indexed, run full
336-
indexer to discover projects which have been added or deleted.
337-
This will produce new configuration.xml.
340+
1. add a new project "foo":
341+
342+
Messages -t foo -n project add
343+
344+
- the project foo is now visible in the configuration however is not yet
345+
searchable. Store the config in a file so that indexer can see the project
346+
and its repositories:
347+
348+
Messages -n config -t getconf > /var/opengrok/etc/configuration.xml
349+
350+
2. index the project. It will become searchable after that.
351+
352+
OPENGROK_READ_XML_CONFIGURATION=/var/opengrok/etc/configuration.xml \
353+
OpenGrok indexpart /var/opengrok/src /foo
354+
355+
3. make the project "indexed" status of the project persistent so that if
356+
webapp is redeployed the project will be still visible:
357+
358+
Messages -n config -t getconf > /var/opengrok/etc/configuration.xml
359+
360+
361+
If an add message is sent that matches existing project, the list of
362+
repositories for that project will be refreshed. This is handy when repositories
363+
are added/deleted.
364+
365+
5.2.3.1 Logging when running partial reindex
366+
--------------------------------------------
338367

339368
When running the indexer the logs are being written to single file. Since
340369
multiple indexers are being run in parallel in step 2, their logs have to
@@ -348,7 +377,7 @@ Note the path component 'myproj' which separates the logs for given
348377
project to this directory. The creation of the per-project directory and the
349378
logging.properties file can be easily done in a script.
350379

351-
The command used in step 2 can look like this:
380+
The command used in step 2 can thus look like this:
352381

353382
OPENGROK_LOGGER_CONFIG_PATH=/var/opengrok/myproj.logging \
354383
OPENGROK_READ_XML_CONFIGURATION=/var/opengrok/etc/configuration.xml \

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

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import java.util.Map;
4848
import java.util.Set;
4949
import java.util.TreeSet;
50+
import java.util.concurrent.ConcurrentHashMap;
5051
import java.util.function.Predicate;
5152
import java.util.logging.Level;
5253
import java.util.logging.Logger;
@@ -177,6 +178,7 @@ public final class Configuration {
177178
private int commandTimeout; // in seconds
178179
private int indexRefreshPeriod; // in seconds
179180
private boolean scopesEnabled;
181+
private boolean projectsEnabled;
180182
private boolean foldingEnabled;
181183
private String statisticsFilePath;
182184
/*
@@ -381,7 +383,7 @@ public Configuration() {
381383
setPluginDirectory(null);
382384
setPluginStack(new AuthorizationStack(AuthControlFlag.REQUIRED, "default stack"));
383385
setPrintProgress(false);
384-
setProjects(new HashMap<>());
386+
setProjects(new ConcurrentHashMap<>());
385387
setQuickContextScan(true);
386388
//below can cause an outofmemory error, since it is defaulting to NO LIMIT
387389
setRamBufferSize(defaultRamBufferSize); //MB
@@ -668,6 +670,10 @@ public void setRepositories(List<RepositoryInfo> repositories) {
668670
this.repositories = repositories;
669671
}
670672

673+
public void addRepositories(List<RepositoryInfo> repositories) {
674+
this.repositories.addAll(repositories);
675+
}
676+
671677
public String getUrlPrefix() {
672678
return urlPrefix;
673679
}
@@ -911,27 +917,6 @@ public void setCurrentIndexedCollapseThreshold(int currentIndexedCollapseThresho
911917
this.currentIndexedCollapseThreshold = currentIndexedCollapseThreshold;
912918
}
913919

914-
private transient Date lastModified;
915-
916-
/**
917-
* Get the date of the last index update.
918-
*
919-
* @return the time of the last index update.
920-
*/
921-
public Date getDateForLastIndexRun() {
922-
if (lastModified == null) {
923-
File timestamp = new File(getDataRoot(), "timestamp");
924-
if (timestamp.exists()) {
925-
lastModified = new Date(timestamp.lastModified());
926-
}
927-
}
928-
return lastModified;
929-
}
930-
931-
public void refreshDateForLastIndexRun() {
932-
lastModified = null;
933-
}
934-
935920
/**
936921
* Get the contents of a file or empty string if the file cannot be read.
937922
*/
@@ -1137,6 +1122,14 @@ public int getMaxSearchThreadCount() {
11371122
public void setMaxSearchThreadCount(int count) {
11381123
this.MaxSearchThreadCount = count;
11391124
}
1125+
1126+
public boolean isProjectsEnabled() {
1127+
return projectsEnabled;
1128+
}
1129+
1130+
public void setProjectsEnabled(boolean flag) {
1131+
this.projectsEnabled = flag;
1132+
}
11401133

11411134
/**
11421135
* Write the current configuration to a file
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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, Oracle and/or its affiliates. All rights reserved.
22+
*/
23+
package org.opensolaris.opengrok.configuration;
24+
25+
import java.io.File;
26+
import java.io.IOException;
27+
import java.util.Date;
28+
import java.util.logging.Level;
29+
import java.util.logging.Logger;
30+
import org.opensolaris.opengrok.logger.LoggerFactory;
31+
32+
/**
33+
*
34+
*/
35+
public class IndexTimestamp {
36+
private transient Date lastModified;
37+
38+
private static final Logger LOGGER = LoggerFactory.getLogger(IndexTimestamp.class);
39+
40+
/**
41+
* Get the date of the last index update.
42+
*
43+
* @return the time of the last index update.
44+
*/
45+
public Date getDateForLastIndexRun() {
46+
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
47+
if (lastModified == null) {
48+
File timestamp = new File(env.getDataRootFile(), "timestamp");
49+
if (timestamp.exists()) {
50+
lastModified = new Date(timestamp.lastModified());
51+
}
52+
}
53+
return lastModified;
54+
}
55+
56+
public void refreshDateForLastIndexRun() {
57+
lastModified = null;
58+
}
59+
60+
public void stamp() throws IOException {
61+
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
62+
File timestamp = new File(env.getDataRootFile(), "timestamp");
63+
String purpose = "used for timestamping the index database.";
64+
if (timestamp.exists()) {
65+
if (!timestamp.setLastModified(System.currentTimeMillis())) {
66+
LOGGER.log(Level.WARNING, "Failed to set last modified time on ''{0}'', {1}",
67+
new Object[]{timestamp.getAbsolutePath(), purpose});
68+
}
69+
} else {
70+
if (!timestamp.createNewFile()) {
71+
LOGGER.log(Level.WARNING, "Failed to create file ''{0}'', {1}",
72+
new Object[]{timestamp.getAbsolutePath(), purpose});
73+
}
74+
}
75+
}
76+
}

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ public class Project implements Comparable<Project>, Nameable {
4848
*/
4949
private int tabSize;
5050

51+
/**
52+
* This marks the project as (not)ready before initial index is done.
53+
* this is to avoid all/multi-project searches referencing this project
54+
* from failing.
55+
*/
56+
private boolean indexed = false;
57+
5158
/**
5259
* Set of groups which match this project.
5360
*/
@@ -85,6 +92,10 @@ public String getPath() {
8592
return path;
8693
}
8794

95+
public boolean isIndexed() {
96+
return indexed;
97+
}
98+
8899
/**
89100
* Get the project id
90101
*
@@ -130,6 +141,10 @@ public void setPath(String path) {
130141
this.path = path;
131142
}
132143

144+
public void setIndexed(boolean flag) {
145+
this.indexed = flag;
146+
}
147+
133148
/**
134149
* Set tab size for this project. Used for expanding tabs to spaces in
135150
* xrefs.
@@ -214,7 +229,7 @@ public static Project getProject(String path) {
214229
public static Project getProject(File file) {
215230
Project ret = null;
216231
try {
217-
ret = getProject(RuntimeEnvironment.getInstance().getPathRelativeToSourceRoot(file, 0));
232+
ret = getProject(RuntimeEnvironment.getInstance().getPathRelativeToSourceRoot(file));
218233
} catch (FileNotFoundException e) { // NOPMD
219234
// ignore if not under source root
220235
} catch (IOException e) { // NOPMD

0 commit comments

Comments
 (0)