Search in sources :

Example 1 with StalenessCheckResult

use of com.google.gerrit.server.index.StalenessCheckResult in project gerrit by GerritCodeReview.

the class AccountIndexerImpl method reindexIfStale.

@Override
public boolean reindexIfStale(Account.Id id) {
    try {
        StalenessCheckResult stalenessCheckResult = stalenessChecker.check(id);
        if (stalenessCheckResult.isStale()) {
            logger.atInfo().log("Reindexing stale document %s", stalenessCheckResult);
            index(id);
            return true;
        }
    } catch (IOException e) {
        throw new StorageException(e);
    }
    return false;
}
Also used : StalenessCheckResult(com.google.gerrit.server.index.StalenessCheckResult) IOException(java.io.IOException) StorageException(com.google.gerrit.exceptions.StorageException)

Example 2 with StalenessCheckResult

use of com.google.gerrit.server.index.StalenessCheckResult in project gerrit by GerritCodeReview.

the class GroupIndexerImpl method reindexIfStale.

@Override
public boolean reindexIfStale(AccountGroup.UUID uuid) {
    try {
        StalenessCheckResult stalenessCheckResult = stalenessChecker.check(uuid);
        if (stalenessCheckResult.isStale()) {
            logger.atInfo().log("Reindexing stale document %s", stalenessCheckResult);
            index(uuid);
            return true;
        }
    } catch (IOException e) {
        throw new StorageException(e);
    }
    return false;
}
Also used : StalenessCheckResult(com.google.gerrit.server.index.StalenessCheckResult) IOException(java.io.IOException) StorageException(com.google.gerrit.exceptions.StorageException)

Example 3 with StalenessCheckResult

use of com.google.gerrit.server.index.StalenessCheckResult in project gerrit by GerritCodeReview.

the class StalenessChecker method check.

/**
 * Returns a {@link StalenessCheckResult} with structured information about staleness of the
 * provided {@link com.google.gerrit.entities.Project.NameKey}.
 */
public StalenessCheckResult check(Project.NameKey project) {
    ProjectData projectData = projectCache.get(project).orElseThrow(illegalState(project)).toProjectData();
    ProjectIndex i = indexes.getSearchIndex();
    if (i == null) {
        return StalenessCheckResult.notStale();
    }
    Optional<FieldBundle> result = i.getRaw(project, QueryOptions.create(indexConfig, 0, 1, FIELDS));
    if (!result.isPresent()) {
        return StalenessCheckResult.stale("Document %s missing from index", project);
    }
    SetMultimap<Project.NameKey, RefState> indexedRefStates = RefState.parseStates(result.get().getValue(ProjectField.REF_STATE));
    SetMultimap<Project.NameKey, RefState> currentRefStates = MultimapBuilder.hashKeys().hashSetValues().build();
    projectData.tree().stream().filter(p -> p.getProject().getConfigRefState() != null).forEach(p -> currentRefStates.put(p.getProject().getNameKey(), RefState.create(RefNames.REFS_CONFIG, p.getProject().getConfigRefState())));
    if (currentRefStates.equals(indexedRefStates)) {
        return StalenessCheckResult.notStale();
    }
    return StalenessCheckResult.stale("Document has unexpected ref states (%s != %s)", currentRefStates, indexedRefStates);
}
Also used : RefState(com.google.gerrit.index.RefState) ProjectCache.illegalState(com.google.gerrit.server.project.ProjectCache.illegalState) ImmutableSet(com.google.common.collect.ImmutableSet) IndexConfig(com.google.gerrit.index.IndexConfig) ProjectCache(com.google.gerrit.server.project.ProjectCache) MultimapBuilder(com.google.common.collect.MultimapBuilder) ProjectField(com.google.gerrit.index.project.ProjectField) Inject(com.google.inject.Inject) QueryOptions(com.google.gerrit.index.QueryOptions) ProjectData(com.google.gerrit.index.project.ProjectData) SetMultimap(com.google.common.collect.SetMultimap) StalenessCheckResult(com.google.gerrit.server.index.StalenessCheckResult) ProjectIndex(com.google.gerrit.index.project.ProjectIndex) ProjectIndexCollection(com.google.gerrit.index.project.ProjectIndexCollection) Project(com.google.gerrit.entities.Project) RefNames(com.google.gerrit.entities.RefNames) FieldBundle(com.google.gerrit.index.query.FieldBundle) Optional(java.util.Optional) RefState(com.google.gerrit.index.RefState) FieldBundle(com.google.gerrit.index.query.FieldBundle) ProjectIndex(com.google.gerrit.index.project.ProjectIndex) ProjectData(com.google.gerrit.index.project.ProjectData)

Aggregations

StalenessCheckResult (com.google.gerrit.server.index.StalenessCheckResult)3 StorageException (com.google.gerrit.exceptions.StorageException)2 IOException (java.io.IOException)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 MultimapBuilder (com.google.common.collect.MultimapBuilder)1 SetMultimap (com.google.common.collect.SetMultimap)1 Project (com.google.gerrit.entities.Project)1 RefNames (com.google.gerrit.entities.RefNames)1 IndexConfig (com.google.gerrit.index.IndexConfig)1 QueryOptions (com.google.gerrit.index.QueryOptions)1 RefState (com.google.gerrit.index.RefState)1 ProjectData (com.google.gerrit.index.project.ProjectData)1 ProjectField (com.google.gerrit.index.project.ProjectField)1 ProjectIndex (com.google.gerrit.index.project.ProjectIndex)1 ProjectIndexCollection (com.google.gerrit.index.project.ProjectIndexCollection)1 FieldBundle (com.google.gerrit.index.query.FieldBundle)1 ProjectCache (com.google.gerrit.server.project.ProjectCache)1 ProjectCache.illegalState (com.google.gerrit.server.project.ProjectCache.illegalState)1 Inject (com.google.inject.Inject)1 Optional (java.util.Optional)1