Provide structured information on staleness to help debugging edge cases
On googlesource.com we see a large number of changes that are stale continously, even after reindexing. This commit provides more structured information about the reason for staleness to aid further debugging. The alternative to this commit is just use logging at the point where we previously returned a boolean result. Using a structured response will also allow the tests to be more specific about the staleness reason in the future. Boolean results and logging-before-return also has the drawback that it's easy to forget the log statement when modifying code. Change-Id: I898c2f28bcb3d8b56ee1cfe6928f7b3b2684bb6c
This commit is contained in:
@@ -27,6 +27,7 @@ import com.google.gerrit.index.project.ProjectField;
|
||||
import com.google.gerrit.index.project.ProjectIndex;
|
||||
import com.google.gerrit.index.project.ProjectIndexCollection;
|
||||
import com.google.gerrit.index.query.FieldBundle;
|
||||
import com.google.gerrit.server.index.StalenessCheckResult;
|
||||
import com.google.gerrit.server.project.ProjectCache;
|
||||
import com.google.inject.Inject;
|
||||
import java.util.Optional;
|
||||
@@ -47,17 +48,18 @@ public class StalenessChecker {
|
||||
this.indexConfig = indexConfig;
|
||||
}
|
||||
|
||||
public boolean isStale(Project.NameKey project) {
|
||||
public StalenessCheckResult check(Project.NameKey project) {
|
||||
ProjectData projectData = projectCache.get(project).toProjectData();
|
||||
ProjectIndex i = indexes.getSearchIndex();
|
||||
if (i == null) {
|
||||
return false; // No index; caller couldn't do anything if it is stale.
|
||||
return StalenessCheckResult
|
||||
.notStale(); // No index; caller couldn't do anything if it is stale.
|
||||
}
|
||||
|
||||
Optional<FieldBundle> result =
|
||||
i.getRaw(project, QueryOptions.create(indexConfig, 0, 1, FIELDS));
|
||||
if (!result.isPresent()) {
|
||||
return true;
|
||||
return StalenessCheckResult.stale("Document %s missing from index", project);
|
||||
}
|
||||
|
||||
SetMultimap<Project.NameKey, RefState> indexedRefStates =
|
||||
@@ -73,6 +75,10 @@ public class StalenessChecker {
|
||||
p.getProject().getNameKey(),
|
||||
RefState.create(RefNames.REFS_CONFIG, p.getProject().getConfigRefState())));
|
||||
|
||||
return !currentRefStates.equals(indexedRefStates);
|
||||
if (currentRefStates.equals(indexedRefStates)) {
|
||||
return StalenessCheckResult.notStale();
|
||||
}
|
||||
return StalenessCheckResult.stale(
|
||||
"Document has unexpected ref states (%s != %s)", currentRefStates, indexedRefStates);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user