Search in sources :

Example 11 with TraceTimer

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

the class ReceiveCommits method processCommands.

ReceiveCommitsResult processCommands(Collection<ReceiveCommand> commands, MultiProgressMonitor progress) throws StorageException {
    checkState(!used, "Tried to re-use a ReceiveCommits objects that is single-use only");
    long start = TimeUtil.nowNanos();
    parsePushOptions();
    String clientProvidedDeadlineValue = Iterables.getLast(pushOptions.get("deadline"), /* defaultValue= */
    null);
    int commandCount = commands.size();
    try (TraceContext traceContext = TraceContext.newTrace(tracePushOption.isPresent(), tracePushOption.orElse(null), (tagName, traceId) -> addMessage(tagName + ": " + traceId));
        PerformanceLogContext performanceLogContext = new PerformanceLogContext(config, performanceLoggers);
        TraceTimer traceTimer = newTimer("processCommands", Metadata.builder().resourceCount(commandCount))) {
        RequestInfo requestInfo = RequestInfo.builder(RequestInfo.RequestType.GIT_RECEIVE, user, traceContext).project(project.getNameKey()).build();
        requestListeners.runEach(l -> l.onRequest(requestInfo));
        traceContext.addTag(RequestId.Type.RECEIVE_ID, new RequestId(project.getNameKey().get()));
        // Log the push options here, rather than in parsePushOptions(), so that they are included
        // into the trace if tracing is enabled.
        logger.atFine().log("push options: %s", receivePack.getPushOptions());
        Task commandProgress = progress.beginSubTask("refs", UNKNOWN);
        commands = commands.stream().map(c -> wrapReceiveCommand(c, commandProgress)).collect(toList());
        try (RequestStateContext requestStateContext = RequestStateContext.open().addRequestStateProvider(progress).addRequestStateProvider(deadlineCheckerFactory.create(start, requestInfo, clientProvidedDeadlineValue))) {
            processCommandsUnsafe(commands, progress);
            rejectRemaining(commands, INTERNAL_SERVER_ERROR);
        } catch (InvalidDeadlineException e) {
            rejectRemaining(commands, e.getMessage());
        } catch (RuntimeException e) {
            Optional<RequestCancelledException> requestCancelledException = RequestCancelledException.getFromCausalChain(e);
            if (!requestCancelledException.isPresent()) {
                Throwables.throwIfUnchecked(e);
            }
            cancellationMetrics.countCancelledRequest(requestInfo, requestCancelledException.get().getCancellationReason());
            StringBuilder msg = new StringBuilder(requestCancelledException.get().formatCancellationReason());
            if (requestCancelledException.get().getCancellationMessage().isPresent()) {
                msg.append(String.format(" (%s)", requestCancelledException.get().getCancellationMessage().get()));
            }
            rejectRemaining(commands, msg.toString());
        }
        // This sends error messages before the 'done' string of the progress monitor is sent.
        // Currently, the test framework relies on this ordering to understand if pushes completed
        // successfully.
        sendErrorMessages();
        commandProgress.end();
        loggingTags = traceContext.getTags();
        logger.atFine().log("Processing commands done.");
    }
    progress.end();
    return result.build();
}
Also used : Task(com.google.gerrit.server.git.MultiProgressMonitor.Task) RequestStateContext(com.google.gerrit.server.cancellation.RequestStateContext) RequestId(com.google.gerrit.server.logging.RequestId) Optional(java.util.Optional) RequestInfo(com.google.gerrit.server.RequestInfo) PerformanceLogContext(com.google.gerrit.server.logging.PerformanceLogContext) InvalidDeadlineException(com.google.gerrit.server.InvalidDeadlineException) TraceTimer(com.google.gerrit.server.logging.TraceContext.TraceTimer) TraceContext(com.google.gerrit.server.logging.TraceContext)

Example 12 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(Change.Id changeId) {
    try (TraceTimer ignored = TraceContext.newTimer("Clear all reviewed flags of change", Metadata.builder().changeId(changeId.get()).build());
        Connection con = ds.getConnection();
        PreparedStatement stmt = con.prepareStatement("DELETE FROM account_patch_reviews WHERE change_id = ?")) {
        stmt.setInt(1, changeId.get());
        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 13 with TraceTimer

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

the class JdbcAccountPatchReviewStore method findReviewed.

@Override
public Optional<PatchSetWithReviewedFiles> findReviewed(PatchSet.Id psId, Account.Id accountId) {
    try (TraceTimer ignored = TraceContext.newTimer("Find reviewed flags", Metadata.builder().patchSetId(psId.get()).accountId(accountId.get()).build());
        Connection con = ds.getConnection();
        PreparedStatement stmt = con.prepareStatement("SELECT patch_set_id, file_name FROM account_patch_reviews APR1 " + "WHERE account_id = ? AND change_id = ? AND patch_set_id = " + "(SELECT MAX(patch_set_id) FROM account_patch_reviews APR2 WHERE " + "APR1.account_id = APR2.account_id " + "AND APR1.change_id = APR2.change_id " + "AND patch_set_id <= ?)")) {
        stmt.setInt(1, accountId.get());
        stmt.setInt(2, psId.changeId().get());
        stmt.setInt(3, psId.get());
        try (ResultSet rs = stmt.executeQuery()) {
            if (rs.next()) {
                PatchSet.Id id = PatchSet.id(psId.changeId(), rs.getInt("patch_set_id"));
                ImmutableSet.Builder<String> builder = ImmutableSet.builder();
                do {
                    builder.add(rs.getString("file_name"));
                } while (rs.next());
                return Optional.of(AccountPatchReviewStore.PatchSetWithReviewedFiles.create(id, builder.build()));
            }
            return Optional.empty();
        }
    } catch (SQLException e) {
        throw convertError("select", e);
    }
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) SQLException(java.sql.SQLException) TraceTimer(com.google.gerrit.server.logging.TraceContext.TraceTimer) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) PatchSet(com.google.gerrit.entities.PatchSet)

Example 14 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) {
    try (TraceTimer ignored = TraceContext.newTimer("Clear all reviewed flags of patch set", Metadata.builder().patchSetId(psId.get()).build());
        Connection con = ds.getConnection();
        PreparedStatement stmt = con.prepareStatement("DELETE FROM account_patch_reviews " + "WHERE change_id = ? AND patch_set_id = ?")) {
        stmt.setInt(1, psId.changeId().get());
        stmt.setInt(2, psId.get());
        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 15 with TraceTimer

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

the class JdbcAccountPatchReviewStore method markReviewed.

@Override
public void markReviewed(PatchSet.Id psId, Account.Id accountId, Collection<String> paths) {
    if (paths == null || paths.isEmpty()) {
        return;
    }
    try (TraceTimer ignored = TraceContext.newTimer("Mark files as reviewed", Metadata.builder().patchSetId(psId.get()).accountId(accountId.get()).resourceCount(paths.size()).build());
        Connection con = ds.getConnection();
        PreparedStatement stmt = con.prepareStatement("INSERT INTO account_patch_reviews " + "(account_id, change_id, patch_set_id, file_name) VALUES " + "(?, ?, ?, ?)")) {
        for (String path : paths) {
            stmt.setInt(1, accountId.get());
            stmt.setInt(2, psId.changeId().get());
            stmt.setInt(3, psId.get());
            stmt.setString(4, path);
            stmt.addBatch();
        }
        stmt.executeBatch();
    } catch (SQLException e) {
        StorageException ormException = convertError("insert", e);
        if (ormException instanceof DuplicateKeyException) {
            return;
        }
        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)

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