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();
}
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);
}
}
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);
}
}
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);
}
}
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;
}
}
Aggregations