diff options
author | Terry Parker | 2015-01-29 16:17:00 +0000 |
---|---|---|
committer | Terry Parker | 2015-01-29 20:29:38 +0000 |
commit | 08a6a77656f8b30f83c8ffefb52bfb8fd76f8f95 (patch) | |
tree | dcd310bf6916e53345475c7b23ac2562aebcf693 /org.eclipse.search | |
parent | 8041d58d7588a3871f4593462b7fa1686de64058 (diff) | |
download | eclipse.platform.text-08a6a77656f8b30f83c8ffefb52bfb8fd76f8f95.tar.gz eclipse.platform.text-08a6a77656f8b30f83c8ffefb52bfb8fd76f8f95.tar.xz eclipse.platform.text-08a6a77656f8b30f83c8ffefb52bfb8fd76f8f95.zip |
Bug 458704 - Fix failing FileSearchTestI20150203-1300I20150129-1830
Update the TextSearchRequestor's API to support parallelization
and fix existing subclasses and tests.
Also add an optimization to process all files in a single job if
the maximum number of threads for the job group is 1, which can
occur on single processor machines or if the TextSearchRequestor
passed to the TextSearchEngine.search() does not support
parallelism. This removes some unnecessary job scheduling.
Change-Id: I5baaf1dc3910a527338dc12e7fa4575269470833
Signed-off-by: Terry Parker <tparker@google.com>
Diffstat (limited to 'org.eclipse.search')
5 files changed, 52 insertions, 5 deletions
diff --git a/org.eclipse.search/META-INF/MANIFEST.MF b/org.eclipse.search/META-INF/MANIFEST.MF index c3c4ec53bd1..aa11e5e8e11 100644 --- a/org.eclipse.search/META-INF/MANIFEST.MF +++ b/org.eclipse.search/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.search; singleton:=true -Bundle-Version: 3.9.200.qualifier +Bundle-Version: 3.10.0.qualifier Bundle-Activator: org.eclipse.search.internal.ui.SearchPlugin Bundle-ActivationPolicy: lazy Bundle-Vendor: %providerName diff --git a/org.eclipse.search/new search/org/eclipse/search/core/text/TextSearchRequestor.java b/org.eclipse.search/new search/org/eclipse/search/core/text/TextSearchRequestor.java index 7858bfabd17..84d3242321b 100644 --- a/org.eclipse.search/new search/org/eclipse/search/core/text/TextSearchRequestor.java +++ b/org.eclipse.search/new search/org/eclipse/search/core/text/TextSearchRequestor.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 2015 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Terry Parker <tparker@google.com> (Google Inc.) - Bug 441016 - Speed up text search by parallelizing it using JobGroups *******************************************************************************/ package org.eclipse.search.core.text; @@ -32,6 +33,14 @@ import org.eclipse.core.resources.IFile; * even if no match can be found. * </p> * <p> + * {@link TextSearchEngine#search(TextSearchScope, TextSearchRequestor, java.util.regex.Pattern, + * org.eclipse.core.runtime.IProgressMonitor)} can perform parallel processing. + * To support parallel processing, subclasses of this class must synchronize access + * to any shared data accumulated by or accessed by overrides of the {@link #acceptFile(IFile)}, + * {@link #reportBinaryFile(IFile)} and {@link #acceptPatternMatch(TextSearchMatchAccess)} + * methods, and override the {@link #canRunInParallel()} method to return true. + * </p> + * <p> * The order of the search results is unspecified and may vary from request to request; * when displaying results, clients should not rely on the order but should instead arrange the results * in an order that would be more meaningful to the user. @@ -75,6 +84,10 @@ public abstract class TextSearchRequestor { * <p> * The default behaviour is to search the file for matches. * </p> + * <p> + * If {@link #canRunInParallel()} returns true, this method may be called in parallel by different threads, + * so any access or updates to collections of results or other shared state must be synchronized. + * </p> * @param file the file resource to be searched. * @return If false, no pattern matches will be reported for the content of this file. * @throws CoreException implementors can throw a {@link CoreException} if accessing the resource fails or another @@ -94,6 +107,10 @@ public abstract class TextSearchRequestor { * reported for this file with {@link #acceptPatternMatch(TextSearchMatchAccess)}. * </p> * <p> + * If {@link #canRunInParallel()} returns true, this method may be called in parallel by different threads, + * so any access or updates to collections of results or other shared state must be synchronized. + * </p> + * <p> * The default behaviour is to skip binary files * </p> * @@ -106,6 +123,10 @@ public abstract class TextSearchRequestor { /** * Accepts the given search match and decides if the search should continue for this file. + * <p> + * If {@link #canRunInParallel()} returns true, this method may be called in parallel by different threads, + * so any access or updates to collections of results or other shared state must be synchronized. + * </p> * * @param matchAccess gives access to information of the match found. The matchAccess is not a value * object. Its value might change after this method is finished, and the element might be reused. @@ -117,4 +138,22 @@ public abstract class TextSearchRequestor { return true; } + /** + * Reports whether this TextSearchRequestor supports executing the text search algorithm + * in parallel. + * <p> + * Subclasses should override this method and return true if they desire faster search results + * and their {@link #acceptFile(IFile)}, {@link #reportBinaryFile(IFile)} and + * {@link #acceptPatternMatch(TextSearchMatchAccess)} methods are thread-safe. + * </p> + * <p> + * The default behavior is to not use parallelism when running a text search. + * </p> + * + * @return If true, the text search will be run in parallel. + * @since 3.10 + */ + public boolean canRunInParallel() { + return false; + } } diff --git a/org.eclipse.search/pom.xml b/org.eclipse.search/pom.xml index 0b5d13afeb8..b07c2ab906d 100644 --- a/org.eclipse.search/pom.xml +++ b/org.eclipse.search/pom.xml @@ -18,6 +18,6 @@ </parent> <groupId>org.eclipse.search</groupId> <artifactId>org.eclipse.search</artifactId> - <version>3.9.200-SNAPSHOT</version> + <version>3.10.0-SNAPSHOT</version> <packaging>eclipse-plugin</packaging> </project> diff --git a/org.eclipse.search/search/org/eclipse/search/internal/core/text/TextSearchVisitor.java b/org.eclipse.search/search/org/eclipse/search/internal/core/text/TextSearchVisitor.java index 4464e3c582b..8ee4d3b1ad5 100644 --- a/org.eclipse.search/search/org/eclipse/search/internal/core/text/TextSearchVisitor.java +++ b/org.eclipse.search/search/org/eclipse/search/internal/core/text/TextSearchVisitor.java @@ -214,8 +214,12 @@ public class TextSearchVisitor { fNumberOfScannedFiles= 0; fNumberOfFilesToScan= files.length; fCurrentFile= null; - int jobCount = Math.round((files.length + FILES_PER_JOB - 1) / FILES_PER_JOB); - final JobGroup jobGroup= new TextSearchJobGroup("Text Search", NUMBER_OF_LOGICAL_THREADS, jobCount); //$NON-NLS-1$ + int maxThreads= fCollector.canRunInParallel() ? NUMBER_OF_LOGICAL_THREADS : 1; + int jobCount= 1; + if (maxThreads > 1) { + jobCount= Math.round((files.length + FILES_PER_JOB - 1) / FILES_PER_JOB); + } + final JobGroup jobGroup= new TextSearchJobGroup("Text Search", maxThreads, jobCount); //$NON-NLS-1$ long startTime= TRACING ? System.currentTimeMillis() : 0; Job monitorUpdateJob= new Job(SearchMessages.TextSearchVisitor_progress_updating_job) { diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileSearchQuery.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileSearchQuery.java index 6204333413c..6ab5a309e32 100644 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileSearchQuery.java +++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileSearchQuery.java @@ -63,6 +63,10 @@ public class FileSearchQuery implements ISearchQuery { } + public boolean canRunInParallel() { + return true; + } + public boolean acceptFile(IFile file) throws CoreException { if (fIsLightweightAutoRefresh && !file.exists()) return false; |