use of com.google.gerrit.server.logging.TraceContext.TraceTimer in project gerrit by GerritCodeReview.
the class AccountIndexerImpl method index.
@Override
public void index(Account.Id id) {
Optional<AccountState> accountState = byIdCache.get(id);
if (accountState.isPresent()) {
logger.atFine().log("Replace account %d in index", id.get());
} else {
logger.atFine().log("Delete account %d from index", id.get());
}
for (Index<Account.Id, AccountState> i : getWriteIndexes()) {
// Evict the cache to get an up-to-date value for sure.
if (accountState.isPresent()) {
try (TraceTimer traceTimer = TraceContext.newTimer("Replacing account in index", Metadata.builder().accountId(id.get()).indexVersion(i.getSchema().getVersion()).build())) {
i.replace(accountState.get());
} catch (RuntimeException e) {
throw new StorageException(String.format("Failed to replace account %d in index version %d", id.get(), i.getSchema().getVersion()), e);
}
} else {
try (TraceTimer traceTimer = TraceContext.newTimer("Deleting account in index", Metadata.builder().accountId(id.get()).indexVersion(i.getSchema().getVersion()).build())) {
i.delete(id);
} catch (RuntimeException e) {
throw new StorageException(String.format("Failed to delete account %d from index version %d", id.get(), i.getSchema().getVersion()), e);
}
}
}
fireAccountIndexedEvent(id.get());
}
use of com.google.gerrit.server.logging.TraceContext.TraceTimer in project gerrit by GerritCodeReview.
the class ReceiveCommits method requestReplaceAndValidateComments.
/**
* Update an existing change. If draft comments are to be published, these are validated and may
* be withheld.
*
* @return True if the command succeeded, false if it was rejected.
*/
private boolean requestReplaceAndValidateComments(ReceiveCommand cmd, boolean checkMergedInto, Change change, RevCommit newCommit) throws IOException {
try (TraceTimer traceTimer = newTimer("requestReplaceAndValidateComments")) {
if (change.isClosed()) {
reject(cmd, changeFormatter.changeClosed(ChangeReportFormatter.Input.builder().setChange(change).build()));
return false;
}
ReplaceRequest req = new ReplaceRequest(change.getId(), newCommit, cmd, checkMergedInto);
if (replaceByChange.containsKey(req.ontoChange)) {
reject(cmd, "duplicate request");
return false;
}
if (magicBranch != null && magicBranch.shouldPublishComments()) {
List<HumanComment> drafts = commentsUtil.draftByChangeAuthor(notesFactory.createChecked(change), user.getAccountId());
ImmutableList<CommentForValidation> draftsForValidation = drafts.stream().map(comment -> CommentForValidation.create(CommentSource.HUMAN, comment.lineNbr > 0 ? CommentType.INLINE_COMMENT : CommentType.FILE_COMMENT, comment.message, comment.message.length())).collect(toImmutableList());
CommentValidationContext ctx = CommentValidationContext.create(change.getChangeId(), change.getProject().get(), change.getDest().branch());
ImmutableList<CommentValidationFailure> commentValidationFailures = PublishCommentUtil.findInvalidComments(ctx, commentValidators, draftsForValidation);
magicBranch.setWithholdComments(!commentValidationFailures.isEmpty());
commentValidationFailures.forEach(failure -> addMessage("Comment validation failure: " + failure.getMessage(), ValidationMessage.Type.WARNING));
}
replaceByChange.put(req.ontoChange, req);
return true;
}
}
use of com.google.gerrit.server.logging.TraceContext.TraceTimer in project gerrit by GerritCodeReview.
the class ReceiveCommits method markExplicitBasesUninteresting.
private void markExplicitBasesUninteresting() throws IOException {
try (TraceTimer traceTimer = newTimer("markExplicitBasesUninteresting")) {
logger.atFine().log("Marking %d base commits uninteresting", magicBranch.baseCommit.size());
for (RevCommit c : magicBranch.baseCommit) {
receivePack.getRevWalk().markUninteresting(c);
}
Ref targetRef = receivePackRefCache.exactRef(magicBranch.dest.branch());
if (targetRef != null) {
logger.atFine().log("Marking target ref %s (%s) uninteresting", magicBranch.dest.branch(), targetRef.getObjectId().name());
receivePack.getRevWalk().markUninteresting(receivePack.getRevWalk().parseCommit(targetRef.getObjectId()));
}
}
}
use of com.google.gerrit.server.logging.TraceContext.TraceTimer in project gerrit by GerritCodeReview.
the class ReceiveCommits method parseRewind.
private void parseRewind(ReceiveCommand cmd) throws PermissionBackendException {
try (TraceTimer traceTimer = newTimer("parseRewind")) {
try {
receivePack.getRevWalk().parseCommit(cmd.getNewId());
} catch (IOException e) {
throw new StorageException(String.format("Invalid object %s for %s creation", cmd.getNewId().name(), cmd.getRefName()), e);
}
logger.atFine().log("Rewinding %s", cmd);
if (!validRefOperation(cmd)) {
return;
}
validateRegularPushCommits(BranchNameKey.create(project.getNameKey(), cmd.getRefName()), cmd);
if (cmd.getResult() != NOT_ATTEMPTED) {
return;
}
Optional<AuthException> err = checkRefPermission(cmd, RefPermission.FORCE_UPDATE);
if (err.isPresent()) {
rejectProhibited(cmd, err.get());
}
}
}
use of com.google.gerrit.server.logging.TraceContext.TraceTimer in project gerrit by GerritCodeReview.
the class ReceiveCommits method setUpWalkForSelectingChanges.
private RevCommit setUpWalkForSelectingChanges() throws IOException {
try (TraceTimer traceTimer = newTimer("setUpWalkForSelectingChanges")) {
RevWalk rw = receivePack.getRevWalk();
RevCommit start = rw.parseCommit(magicBranch.cmd.getNewId());
rw.reset();
rw.sort(RevSort.TOPO);
rw.sort(RevSort.REVERSE, true);
receivePack.getRevWalk().markStart(start);
if (magicBranch.baseCommit != null) {
markExplicitBasesUninteresting();
} else if (magicBranch.merged) {
logger.atFine().log("Marking parents of merged commit %s uninteresting", start.name());
for (RevCommit c : start.getParents()) {
rw.markUninteresting(c);
}
} else {
markHeadsAsUninteresting(rw, magicBranch.dest != null ? magicBranch.dest.branch() : null);
}
return start;
}
}
Aggregations