Skip to content

shutdown search executor at the end of indexing #4013

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 26, 2022
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 @@ -203,6 +203,15 @@ private ExecutorService newSearchExecutor() {
});
}

public void shutdownSearchExecutor() {
getSearchExecutor().shutdownNow();
try {
getSearchExecutor().awaitTermination(getIndexerCommandTimeout(), TimeUnit.SECONDS);
} catch (InterruptedException e) {
LOGGER.log(Level.WARNING, "failed to await shutdown of search executor", e);
}
}

public ExecutorService getRevisionExecutor() {
return lzRevisionExecutor.get();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ public static void main(String[] argv) {
System.err.println("Exception: " + e.getLocalizedMessage());
System.exit(1);
} finally {
env.shutdownSearchExecutor();
stats.report(LOGGER, "Indexer finished", "indexer.total");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
*/
package org.opengrok.indexer.index;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
Expand All @@ -40,6 +41,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand Down Expand Up @@ -177,22 +179,19 @@ void testRescanProjects() throws Exception {
assertEquals(p1.getTabSize(), newP1.getTabSize(), "project tabsize");
}

/**
* Test of doIndexerExecution method, of class Indexer.
*/
@Test
void testMain() {
System.out.println("Generate index by using command line options");
void testParseOptions() throws ParseException {
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
String[] argv = {"-S", "-P", "-H", "-Q", "off", "-s",
repository.getSourceRoot(), "-d", repository.getDataRoot(),
String[] argv = {"-S", "-P", "-H", "-Q", "off",
"-s", repository.getSourceRoot(),
"-d", repository.getDataRoot(),
"-v", "-c", env.getCtags()};
Indexer.main(argv);
assertDoesNotThrow(() -> Indexer.parseOptions(argv));
}

private static class MyIndexChangeListener implements IndexChangedListener {

final Queue<String> files = new ConcurrentLinkedQueue<>();
final Queue<String> addedFiles = new ConcurrentLinkedQueue<>();
final Queue<String> removedFiles = new ConcurrentLinkedQueue<>();

@Override
Expand All @@ -201,7 +200,7 @@ public void fileAdd(String path, String analyzer) {

@Override
public void fileAdded(String path, String analyzer) {
files.add(path);
addedFiles.add(path);
}

@Override
Expand All @@ -218,21 +217,21 @@ public void fileRemoved(String path) {
}

public void reset() {
this.files.clear();
this.addedFiles.clear();
this.removedFiles.clear();
}
}

/**
* Test indexing w.r.t. setIndexVersionedFilesOnly() setting,
* i.e. if this option is set to true, index only files tracked by SCM.
* @throws Exception
*/
@Test
void testIndexWithSetIndexVersionedFilesOnly() throws Exception {
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
env.setSourceRoot(repository.getSourceRoot());
env.setDataRoot(repository.getDataRoot());
env.setHistoryEnabled(true);
env.setRepositories(repository.getSourceRoot());

List<RepositoryInfo> repos = env.getRepositories();
Expand All @@ -252,14 +251,14 @@ void testIndexWithSetIndexVersionedFilesOnly() throws Exception {
MyIndexChangeListener listener = new MyIndexChangeListener();
idb.addIndexChangedListener(listener);
idb.update();
assertEquals(2, listener.files.size());
assertEquals(2, listener.addedFiles.size());
repository.purgeData();
RuntimeEnvironment.getInstance().setIndexVersionedFilesOnly(true);
idb = new IndexDatabase(project);
listener = new MyIndexChangeListener();
idb.addIndexChangedListener(listener);
idb.update();
assertEquals(1, listener.files.size());
assertEquals(1, listener.addedFiles.size());
RuntimeEnvironment.getInstance().setIndexVersionedFilesOnly(false);
} else {
System.out.println("Skipping test. Repository for rfe2575 not found or an sccs I could use in path.");
Expand Down Expand Up @@ -334,6 +333,7 @@ void testRemoveFileOnFileChange() throws Exception {
env.setSourceRoot(testrepo.getSourceRoot());
env.setDataRoot(testrepo.getDataRoot());
env.setRepositories(testrepo.getSourceRoot());
env.setHistoryEnabled(true);

// Create history cache.
Indexer.getInstance().prepareIndexer(env, true, true,
Expand Down Expand Up @@ -413,6 +413,7 @@ void testBug3430() throws Exception {
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
env.setSourceRoot(repository.getSourceRoot());
env.setDataRoot(repository.getDataRoot());
RuntimeEnvironment.getInstance().setIndexVersionedFilesOnly(false);

Project project = new Project("bug3430");
project.setPath("/bug3430");
Expand All @@ -421,7 +422,7 @@ void testBug3430() throws Exception {
MyIndexChangeListener listener = new MyIndexChangeListener();
idb.addIndexChangedListener(listener);
idb.update();
assertEquals(1, listener.files.size());
assertEquals(1, listener.addedFiles.size());
}

/**
Expand All @@ -432,6 +433,7 @@ void testIncrementalIndexAddRemoveFile() throws Exception {
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
env.setSourceRoot(repository.getSourceRoot());
env.setDataRoot(repository.getDataRoot());
RuntimeEnvironment.getInstance().setIndexVersionedFilesOnly(false);

// Make the test consistent. If run in sequence with other tests, env.hasProjects() returns true.
// The same should work for standalone test run.
Expand All @@ -447,21 +449,20 @@ void testIncrementalIndexAddRemoveFile() throws Exception {
MyIndexChangeListener listener = new MyIndexChangeListener();
idb.addIndexChangedListener(listener);
idb.update();
assertEquals(1, listener.files.size());
assertEquals(1, listener.addedFiles.size());
listener.reset();
repository.addDummyFile(ppath);
idb.update();
assertEquals(1, listener.files.size(), "No new file added");
assertEquals(1, listener.addedFiles.size(), "No new file added");
repository.removeDummyFile(ppath);
idb.update();
assertEquals(1, listener.files.size(), "(added)files changed unexpectedly");
assertEquals(1, listener.addedFiles.size(), "(added)files changed unexpectedly");
assertEquals(1, listener.removedFiles.size(), "Didn't remove the dummy file");
assertEquals(listener.files.peek(), listener.removedFiles.peek(), "Should have added then removed the same file");
assertEquals(listener.addedFiles.peek(), listener.removedFiles.peek(), "Should have added then removed the same file");
}

/**
* Test that named pipes are not indexed.
* @throws Exception
*/
@Test
@EnabledIf("mkfifoInPath")
Expand All @@ -485,7 +486,7 @@ void testBug11896() throws Exception {
idb.addIndexChangedListener(listener);
System.out.println("Trying to index a special file - FIFO in this case.");
idb.update();
assertEquals(0, listener.files.size());
assertEquals(0, listener.addedFiles.size());
}

boolean mkfifoInPath() {
Expand All @@ -494,7 +495,6 @@ boolean mkfifoInPath() {

/**
* Should include the existing project.
* @throws Exception
*/
@Test
void testDefaultProjectsSingleProject() throws Exception {
Expand All @@ -505,14 +505,14 @@ void testDefaultProjectsSingleProject() throws Exception {
Indexer.getInstance().prepareIndexer(env, true, true,
null, null);
env.setDefaultProjectsFromNames(new TreeSet<>(Collections.singletonList("/c")));
assertNotNull(env.getDefaultProjects());
assertEquals(1, env.getDefaultProjects().size());
assertEquals(new TreeSet<>(Collections.singletonList("c")),
env.getDefaultProjects().stream().map(Project::getName).collect(Collectors.toSet()));
}

/**
* Should discard the non existing project.
* @throws Exception
* Should discard the non-existing project.
*/
@Test
void testDefaultProjectsNonExistent() throws Exception {
Expand All @@ -530,14 +530,14 @@ void testDefaultProjectsNonExistent() throws Exception {
Indexer.getInstance().prepareIndexer(env, true, true,
null, null);
env.setDefaultProjectsFromNames(projectSet);
assertNotNull(env.getDefaultProjects());
assertEquals(4, env.getDefaultProjects().size());
assertEquals(new TreeSet<>(Arrays.asList("lisp", "pascal", "perl", "data")),
env.getDefaultProjects().stream().map(Project::getName).collect(Collectors.toSet()));
}

/**
* Should include all projects in the source root.
* @throws Exception
*/
@Test
void testDefaultProjectsAll() throws Exception {
Expand All @@ -555,6 +555,7 @@ void testDefaultProjectsAll() throws Exception {
null, null);
env.setDefaultProjectsFromNames(defaultProjects);
Set<String> projects = new TreeSet<>(Arrays.asList(new File(repository.getSourceRoot()).list()));
assertNotNull(env.getDefaultProjects());
assertEquals(projects.size(), env.getDefaultProjects().size());
assertEquals(projects, env.getDefaultProjects().stream().map(Project::getName).collect(Collectors.toSet()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

/*
* Copyright (c) 2007, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2022, Oracle and/or its affiliates. All rights reserved.
* Portions Copyright (c) 2018, 2019, Chris Fraire <[email protected]>.
*/
package org.opengrok.web;
Expand Down Expand Up @@ -58,8 +58,7 @@
*
* @author Trond Norbye
*/
public final class WebappListener
implements ServletContextListener, ServletRequestListener {
public final class WebappListener implements ServletContextListener, ServletRequestListener {

private static final Logger LOGGER = LoggerFactory.getLogger(WebappListener.class);
private final Timer startupTimer = Timer.builder("webapp.startup.latency").
Expand Down Expand Up @@ -167,6 +166,7 @@ public void contextDestroyed(final ServletContextEvent servletContextEvent) {
env.stopExpirationTimer();
try {
env.shutdownRevisionExecutor();
env.shutdownSearchExecutor();
} catch (InterruptedException e) {
LOGGER.log(Level.WARNING, "Could not shutdown revision executor", e);
}
Expand Down