Search in sources :

Example 26 with TraceTimer

use of com.google.gerrit.server.logging.TraceContext.TraceTimer in project gerrit by GerritCodeReview.

the class ProjectIndexerImpl method index.

@Override
public void index(Project.NameKey nameKey) {
    Optional<ProjectState> projectState = projectCache.get(nameKey);
    if (projectState.isPresent()) {
        logger.atFine().log("Replace project %s in index", nameKey.get());
        ProjectData projectData = projectState.get().toProjectData();
        for (ProjectIndex i : getWriteIndexes()) {
            try (TraceTimer traceTimer = TraceContext.newTimer("Replacing project", Metadata.builder().projectName(nameKey.get()).indexVersion(i.getSchema().getVersion()).build())) {
                i.replace(projectData);
            } catch (RuntimeException e) {
                throw new StorageException(String.format("Failed to replace project %s in index version %d", nameKey.get(), i.getSchema().getVersion()), e);
            }
        }
        fireProjectIndexedEvent(nameKey.get());
    } else {
        logger.atFine().log("Delete project %s from index", nameKey.get());
        for (ProjectIndex i : getWriteIndexes()) {
            try (TraceTimer traceTimer = TraceContext.newTimer("Deleting project", Metadata.builder().projectName(nameKey.get()).indexVersion(i.getSchema().getVersion()).build())) {
                i.delete(nameKey);
            } catch (RuntimeException e) {
                throw new StorageException(String.format("Failed to delete project %s from index version %d", nameKey.get(), i.getSchema().getVersion()), e);
            }
        }
    }
}
Also used : TraceTimer(com.google.gerrit.server.logging.TraceContext.TraceTimer) ProjectState(com.google.gerrit.server.project.ProjectState) ProjectIndex(com.google.gerrit.index.project.ProjectIndex) StorageException(com.google.gerrit.exceptions.StorageException) ProjectData(com.google.gerrit.index.project.ProjectData)

Example 27 with TraceTimer

use of com.google.gerrit.server.logging.TraceContext.TraceTimer in project gerrit by GerritCodeReview.

the class Reachable method fromRefs.

boolean fromRefs(Project.NameKey project, Repository repo, RevCommit commit, List<Ref> refs, Optional<CurrentUser> optionalUserProvider) {
    try (RevWalk rw = new RevWalk(repo)) {
        Collection<Ref> filtered = optionalUserProvider.map(permissionBackend::user).orElse(permissionBackend.currentUser()).project(project).filter(refs, repo, RefFilterOptions.defaults());
        Collection<RevCommit> visible = new ArrayList<>();
        for (Ref r : filtered) {
            try {
                visible.add(rw.parseCommit(r.getObjectId()));
            } catch (IncorrectObjectTypeException notCommit) {
                // is common in the Linux kernel or git.git repository.
                continue;
            } catch (MissingObjectException notHere) {
                // Log the problem with this branch, but keep processing.
                logger.atWarning().log("Reference %s in %s points to dangling object %s", r.getName(), repo.getDirectory(), r.getObjectId());
                continue;
            }
        }
        // from the reachability check, do the trace here:
        try (TraceTimer timer = TraceContext.newTimer("ReachabilityChecker.areAllReachable", Metadata.builder().projectName(project.get()).resourceCount(refs.size()).build())) {
            ReachabilityChecker checker = rw.getObjectReader().createReachabilityChecker(rw);
            Optional<RevCommit> unreachable = checker.areAllReachable(ImmutableList.of(rw.parseCommit(commit)), visible.stream());
            return !unreachable.isPresent();
        }
    } catch (IOException | PermissionBackendException e) {
        logger.atSevere().withCause(e).log("Cannot verify permissions to commit object %s in repository %s", commit.name(), project);
        return false;
    }
}
Also used : ReachabilityChecker(org.eclipse.jgit.revwalk.ReachabilityChecker) ArrayList(java.util.ArrayList) IncorrectObjectTypeException(org.eclipse.jgit.errors.IncorrectObjectTypeException) PermissionBackendException(com.google.gerrit.server.permissions.PermissionBackendException) IOException(java.io.IOException) RevWalk(org.eclipse.jgit.revwalk.RevWalk) MissingObjectException(org.eclipse.jgit.errors.MissingObjectException) Ref(org.eclipse.jgit.lib.Ref) TraceTimer(com.google.gerrit.server.logging.TraceContext.TraceTimer) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 28 with TraceTimer

use of com.google.gerrit.server.logging.TraceContext.TraceTimer in project gerrit by GerritCodeReview.

the class JdbcAccountPatchReviewStore method markReviewed.

@Override
public boolean markReviewed(PatchSet.Id psId, Account.Id accountId, String path) {
    try (TraceTimer ignored = TraceContext.newTimer("Mark file as reviewed", Metadata.builder().patchSetId(psId.get()).accountId(accountId.get()).filePath(path).build());
        Connection con = ds.getConnection();
        PreparedStatement stmt = con.prepareStatement("INSERT INTO account_patch_reviews " + "(account_id, change_id, patch_set_id, file_name) VALUES " + "(?, ?, ?, ?)")) {
        stmt.setInt(1, accountId.get());
        stmt.setInt(2, psId.changeId().get());
        stmt.setInt(3, psId.get());
        stmt.setString(4, path);
        stmt.executeUpdate();
        return true;
    } catch (SQLException e) {
        StorageException ormException = convertError("insert", e);
        if (ormException instanceof DuplicateKeyException) {
            return false;
        }
        throw ormException;
    }
}
Also used : SQLException(java.sql.SQLException) TraceTimer(com.google.gerrit.server.logging.TraceContext.TraceTimer) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) StorageException(com.google.gerrit.exceptions.StorageException) DuplicateKeyException(com.google.gerrit.exceptions.DuplicateKeyException)

Example 29 with TraceTimer

use of com.google.gerrit.server.logging.TraceContext.TraceTimer in project gerrit by GerritCodeReview.

the class JdbcAccountPatchReviewStore method clearReviewed.

@Override
public void clearReviewed(PatchSet.Id psId, Account.Id accountId, String path) {
    try (TraceTimer ignored = TraceContext.newTimer("Clear reviewed flag", Metadata.builder().patchSetId(psId.get()).accountId(accountId.get()).filePath(path).build());
        Connection con = ds.getConnection();
        PreparedStatement stmt = con.prepareStatement("DELETE FROM account_patch_reviews " + "WHERE account_id = ? AND change_id = ? AND " + "patch_set_id = ? AND file_name = ?")) {
        stmt.setInt(1, accountId.get());
        stmt.setInt(2, psId.changeId().get());
        stmt.setInt(3, psId.get());
        stmt.setString(4, path);
        stmt.executeUpdate();
    } catch (SQLException e) {
        throw convertError("delete", e);
    }
}
Also used : SQLException(java.sql.SQLException) TraceTimer(com.google.gerrit.server.logging.TraceContext.TraceTimer) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement)

Example 30 with TraceTimer

use of com.google.gerrit.server.logging.TraceContext.TraceTimer in project gerrit by GerritCodeReview.

the class ApprovalInference method forPatchSet.

/**
 * Returns all approvals that apply to the given patch set. Honors copied approvals from previous
 * patch-set.
 */
Iterable<PatchSetApproval> forPatchSet(ChangeNotes notes, PatchSet ps, RevWalk rw, Config repoConfig) {
    ProjectState project;
    try (TraceTimer traceTimer = TraceContext.newTimer("Computing labels for patch set", Metadata.builder().changeId(notes.load().getChangeId().get()).patchSetId(ps.id().get()).build())) {
        project = projectCache.get(notes.getProjectName()).orElseThrow(illegalState(notes.getProjectName()));
        Collection<PatchSetApproval> approvals = getForPatchSetWithoutNormalization(notes, project, ps, rw, repoConfig);
        return labelNormalizer.normalize(notes, approvals).getNormalized();
    }
}
Also used : TraceTimer(com.google.gerrit.server.logging.TraceContext.TraceTimer) ProjectState(com.google.gerrit.server.project.ProjectState) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval)

Aggregations

TraceTimer (com.google.gerrit.server.logging.TraceContext.TraceTimer)46 StorageException (com.google.gerrit.exceptions.StorageException)17 IOException (java.io.IOException)14 RevCommit (org.eclipse.jgit.revwalk.RevCommit)12 RevWalk (org.eclipse.jgit.revwalk.RevWalk)12 AuthException (com.google.gerrit.extensions.restapi.AuthException)11 Ref (org.eclipse.jgit.lib.Ref)11 HumanComment (com.google.gerrit.entities.HumanComment)8 RefNames.isConfigRef (com.google.gerrit.entities.RefNames.isConfigRef)8 Change (com.google.gerrit.entities.Change)7 PatchSet (com.google.gerrit.entities.PatchSet)7 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)7 ChangeNotes (com.google.gerrit.server.notedb.ChangeNotes)7 ObjectId (org.eclipse.jgit.lib.ObjectId)7 ImmutableList (com.google.common.collect.ImmutableList)6 BranchNameKey (com.google.gerrit.entities.BranchNameKey)6 Project (com.google.gerrit.entities.Project)6 InvalidDeadlineException (com.google.gerrit.server.InvalidDeadlineException)6 RequestId (com.google.gerrit.server.logging.RequestId)6 PermissionBackendException (com.google.gerrit.server.permissions.PermissionBackendException)6