IJPL-425: move shouldPause predicate from IndexUpdateRunner to IndexUpdateRunner.FileSet

And further should be moved to "FileSet.asChannel"

GitOrigin-RevId: 449d98f262d539d2cbf470d40180be05f7e910ab
This commit is contained in:
Andrei.Kuznetsov
2024-06-23 14:30:06 +02:00
committed by intellij-monorepo-bot
parent dd12274ee1
commit 8c0b177355
4 changed files with 25 additions and 21 deletions

View File

@@ -134,39 +134,39 @@ public final class UnindexedFilesIndexer extends DumbModeTask {
IndexingRequestToken indexingRequest = myProject.getService(ProjectIndexingDependenciesService.class).getLatestIndexingRequestToken();
IndexUpdateRunner indexUpdateRunner = new IndexUpdateRunner(myIndex, indexingRequest);
IndexUpdateRunner.FileSet fileSets = getExplicitlyRequestedFilesSets();
IndexUpdateRunner.FileSet fileSets = getExplicitlyRequestedFilesSets(pauseCondition);
if (!fileSets.isEmpty()) {
doIndexFiles(projectDumbIndexingHistory, indexUpdateRunner, fileSets, reporter, pauseCondition);
doIndexFiles(projectDumbIndexingHistory, indexUpdateRunner, fileSets, reporter);
}
// Order is important: getRefreshedFiles may return some subset of getExplicitlyRequestedFilesSets files (e.g., new files)
// We first index explicitly requested files, this will also mark indexed files as "up-to-date", then we index remaining dirty files
fileSets = getRefreshedFiles(projectDumbIndexingHistory);
fileSets = getRefreshedFiles(projectDumbIndexingHistory, pauseCondition);
if (!fileSets.isEmpty()) {
doIndexFiles(projectDumbIndexingHistory, indexUpdateRunner, fileSets, reporter, pauseCondition);
doIndexFiles(projectDumbIndexingHistory, indexUpdateRunner, fileSets, reporter);
}
}
private IndexUpdateRunner.FileSet getRefreshedFiles(@NotNull ProjectDumbIndexingHistoryImpl projectDumbIndexingHistory) {
private IndexUpdateRunner.FileSet getRefreshedFiles(@NotNull ProjectDumbIndexingHistoryImpl projectDumbIndexingHistory,
@NotNull Function0<@NotNull Boolean> pauseCondition) {
String filesetName = "Refreshed files";
Collection<FileIndexingRequest> files =
new ProjectChangedFilesScanner(myProject).scan(projectDumbIndexingHistory);
return new IndexUpdateRunner.FileSet(myProject, filesetName, QueuedFiles.fromRequestsCollection(files, Collections.emptyList()));
return new IndexUpdateRunner.FileSet(myProject, filesetName, QueuedFiles.fromRequestsCollection(files, Collections.emptyList()),
pauseCondition);
}
@NotNull
private IndexUpdateRunner.FileSet getExplicitlyRequestedFilesSets() {
return new IndexUpdateRunner.FileSet(myProject, "<indexing queue>", files);
private IndexUpdateRunner.@NotNull FileSet getExplicitlyRequestedFilesSets(@NotNull Function0<@NotNull Boolean> pauseCondition) {
return new IndexUpdateRunner.FileSet(myProject, "<indexing queue>", files, pauseCondition);
}
private void doIndexFiles(@NotNull ProjectDumbIndexingHistoryImpl projectDumbIndexingHistory,
IndexUpdateRunner indexUpdateRunner,
IndexUpdateRunner.FileSet fileSet,
@NotNull IndexingProgressReporter2 reporter,
@NotNull Function0<@NotNull Boolean> pauseCondition) {
@NotNull IndexingProgressReporter2 reporter) {
IndexUpdateRunner.IndexingInterruptedException exception = null;
try {
indexUpdateRunner.indexFiles(myProject, fileSet, projectDumbIndexingHistory, reporter, pauseCondition);
indexUpdateRunner.indexFiles(myProject, fileSet, projectDumbIndexingHistory, reporter);
}
catch (IndexUpdateRunner.IndexingInterruptedException e) {
exception = e;

View File

@@ -31,6 +31,7 @@ import kotlinx.coroutines.channels.consumeEach
import kotlinx.coroutines.sync.Semaphore
import kotlinx.coroutines.sync.withPermit
import org.jetbrains.annotations.ApiStatus
import org.jetbrains.annotations.TestOnly
import java.io.FileNotFoundException
import java.io.IOException
import java.nio.file.NoSuchFileException
@@ -56,7 +57,13 @@ class IndexUpdateRunner(fileBasedIndex: FileBasedIndexImpl,
*/
class IndexingInterruptedException(cause: Throwable) : Exception(cause)
class FileSet(project: Project, val debugName: String, internal val filesOriginal: QueuedFiles) {
class FileSet(
project: Project, val debugName: String,
internal val filesOriginal: QueuedFiles,
val shouldPause: () -> Boolean,
) {
@TestOnly
constructor(project: Project, debugName: String, filesOriginal: QueuedFiles) : this(project, debugName, filesOriginal, { false })
val statistics: IndexingFileSetStatistics = IndexingFileSetStatistics(project, debugName)
fun isEmpty(): Boolean = filesOriginal.isEmpty
@@ -71,11 +78,10 @@ class IndexUpdateRunner(fileBasedIndex: FileBasedIndexImpl,
fileSet: FileSet,
projectDumbIndexingHistory: ProjectDumbIndexingHistoryImpl,
progressReporter: IndexingProgressReporter2,
shouldPause: () -> Boolean,
) {
val startTime = System.nanoTime()
try {
doIndexFiles(project, fileSet, progressReporter, shouldPause)
doIndexFiles(project, fileSet, progressReporter)
}
catch (e: RuntimeException) {
throw IndexingInterruptedException(e)
@@ -94,7 +100,6 @@ class IndexUpdateRunner(fileBasedIndex: FileBasedIndexImpl,
private fun doIndexFiles(
project: Project, fileSet: FileSet,
progressReporter: IndexingProgressReporter2,
shouldPause: () -> Boolean,
) {
if (fileSet.isEmpty()) {
return
@@ -102,7 +107,7 @@ class IndexUpdateRunner(fileBasedIndex: FileBasedIndexImpl,
val contentLoader: CachedFileContentLoader = CurrentProjectHintedCachedFileContentLoader(project)
runConcurrently(project, fileSet, shouldPause) { fileIndexingRequest ->
runConcurrently(project, fileSet) { fileIndexingRequest ->
blockingContext {
val presentableLocation = getPresentableLocationBeingIndexed(project, fileIndexingRequest.file)
progressReporter.setLocationBeingIndexed(presentableLocation)
@@ -120,7 +125,6 @@ class IndexUpdateRunner(fileBasedIndex: FileBasedIndexImpl,
private fun runConcurrently(
project: Project,
fileSet: FileSet,
shouldPause: () -> Boolean,
task: suspend (FileIndexingRequest) -> Unit,
) {
runBlockingCancellable {
@@ -129,7 +133,7 @@ class IndexUpdateRunner(fileBasedIndex: FileBasedIndexImpl,
launch(Dispatchers.IO + CoroutineName("Indexing(${project.locationHash},$threadNr)")) {
channel.consumeEach { fileIndexingJob ->
ensureActive()
while (shouldPause()) delay(1) // TODO: get rid of legacy suspender
while (fileSet.shouldPause()) delay(1) // TODO: get rid of legacy suspender
GLOBAL_INDEXING_SEMAPHORE.withPermit {
task(fileIndexingJob)

View File

@@ -300,7 +300,7 @@ class DumbServiceImplTest {
.indexFiles(project, IndexUpdateRunner.FileSet(project, "child",
PerProjectIndexingQueue.QueuedFiles.fromFilesCollection(listOf(child), emptyList())),
ProjectDumbIndexingHistoryImpl(project),
IndexingProgressReporter2.createEmpty(), { false })
IndexingProgressReporter2.createEmpty())
}
}
catch (e: ProcessCanceledException) {

View File

@@ -120,7 +120,7 @@ public class PersistencePerformanceTest extends BasePlatformTestCase {
new IndexUpdateRunner.FileSet(getProject(), "test files",
QueuedFiles.fromRequestsCollection(files, Collections.emptyList())),
new ProjectDumbIndexingHistoryImpl(getProject()),
IndexingProgressReporter2.Companion.createEmpty(), () -> false);
IndexingProgressReporter2.Companion.createEmpty());
}
catch (Exception e) {
throw new RuntimeException(e);