Search in sources :

Example 1 with TraceTimer

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

the class ExternalIdCacheLoader method reloadAllExternalIds.

private AllExternalIds reloadAllExternalIds(ObjectId notesRev) throws IOException, ConfigInvalidException {
    try (TraceTimer ignored = TraceContext.newTimer("Loading external IDs from scratch", Metadata.builder().revision(notesRev.name()).build())) {
        ImmutableSet<ExternalId> externalIds = externalIdReader.all(notesRev);
        externalIds.forEach(ExternalId::checkThatBlobIdIsSet);
        AllExternalIds allExternalIds = AllExternalIds.create(externalIds.stream());
        reloadCounter.increment(false);
        return allExternalIds;
    }
}
Also used : TraceTimer(com.google.gerrit.server.logging.TraceContext.TraceTimer)

Example 2 with TraceTimer

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

the class StarredChangesUtil method deleteRef.

private void deleteRef(Repository repo, String refName, ObjectId oldObjectId) throws IOException {
    if (ObjectId.zeroId().equals(oldObjectId)) {
        // ref doesn't exist
        return;
    }
    try (TraceTimer traceTimer = TraceContext.newTimer("Delete star labels", Metadata.builder().noteDbRefName(refName).build())) {
        RefUpdate u = repo.updateRef(refName);
        u.setForceUpdate(true);
        u.setExpectedOldObjectId(oldObjectId);
        u.setRefLogIdent(serverIdent.get());
        u.setRefLogMessage("Unstar change", true);
        RefUpdate.Result result = u.delete();
        switch(result) {
            case FORCED:
                gitRefUpdated.fire(allUsers, u, null);
                return;
            case LOCK_FAILURE:
                throw new LockFailureException(String.format("Delete star ref %s failed", refName), u);
            case NEW:
            case NO_CHANGE:
            case FAST_FORWARD:
            case IO_FAILURE:
            case NOT_ATTEMPTED:
            case REJECTED:
            case REJECTED_CURRENT_BRANCH:
            case RENAMED:
            case REJECTED_MISSING_OBJECT:
            case REJECTED_OTHER_REASON:
            default:
                throw new StorageException(String.format("Delete star ref %s failed: %s", refName, result.name()));
        }
    }
}
Also used : TraceTimer(com.google.gerrit.server.logging.TraceContext.TraceTimer) StorageException(com.google.gerrit.exceptions.StorageException) LockFailureException(com.google.gerrit.git.LockFailureException) RefUpdate(org.eclipse.jgit.lib.RefUpdate) BatchRefUpdate(org.eclipse.jgit.lib.BatchRefUpdate)

Example 3 with TraceTimer

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

the class ChangeResource method getETag.

@Override
public String getETag() {
    try (TraceTimer ignored = TraceContext.newTimer("Compute change ETag", Metadata.builder().changeId(changeData.getId().get()).projectName(changeData.project().get()).build())) {
        Hasher h = Hashing.murmur3_128().newHasher();
        if (user.isIdentifiedUser()) {
            h.putString(starredChangesUtil.getObjectId(user.getAccountId(), getId()).name(), UTF_8);
        }
        prepareETag(h, user);
        return h.hash().toString();
    }
}
Also used : Hasher(com.google.common.hash.Hasher) TraceTimer(com.google.gerrit.server.logging.TraceContext.TraceTimer)

Example 4 with TraceTimer

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

the class GroupsUpdate method updateGroup.

/**
 * Updates the specified group.
 *
 * @param groupUuid the UUID of the group to update
 * @param groupDelta a {@link GroupDelta} which indicates the desired updates on the group
 * @throws DuplicateKeyException if the new name of the group is used by another group
 * @throws IOException if indexing fails, or an error occurs while reading/writing from/to NoteDb
 * @throws NoSuchGroupException if the specified group doesn't exist
 */
public void updateGroup(AccountGroup.UUID groupUuid, GroupDelta groupDelta) throws DuplicateKeyException, IOException, NoSuchGroupException, ConfigInvalidException {
    try (TraceTimer ignored = TraceContext.newTimer("Updating group", Metadata.builder().groupUuid(groupUuid.get()).build())) {
        Optional<Instant> updatedOn = groupDelta.getUpdatedOn();
        if (!updatedOn.isPresent()) {
            updatedOn = Optional.of(TimeUtil.now());
            groupDelta = groupDelta.toBuilder().setUpdatedOn(updatedOn.get()).build();
        }
        UpdateResult result = updateGroupInNoteDbWithRetry(groupUuid, groupDelta);
        updateNameInProjectConfigsIfNecessary(result);
        evictCachesOnGroupUpdate(result);
        dispatchAuditEventsOnGroupUpdate(result, updatedOn.get());
    }
}
Also used : Instant(java.time.Instant) TraceTimer(com.google.gerrit.server.logging.TraceContext.TraceTimer)

Example 5 with TraceTimer

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

the class ChangeIndexer method indexImpl.

private void indexImpl(ChangeData cd) {
    logger.atFine().log("Reindex change %d in index.", cd.getId().get());
    for (Index<?, ChangeData> i : getWriteIndexes()) {
        try (TraceTimer traceTimer = TraceContext.newTimer("Reindexing change in index", Metadata.builder().changeId(cd.getId().get()).patchSetId(cd.currentPatchSet().number()).indexVersion(i.getSchema().getVersion()).build())) {
            if (isFirstInsertForEntry.equals(IsFirstInsertForEntry.YES)) {
                i.insert(cd);
            } else {
                i.replace(cd);
            }
        } catch (RuntimeException e) {
            throw new StorageException(String.format("Failed to reindex change %d in index version %d (current patch set = %d)", cd.getId().get(), i.getSchema().getVersion(), cd.currentPatchSet().number()), e);
        }
    }
    fireChangeIndexedEvent(cd.project().get(), cd.getId().get());
}
Also used : TraceTimer(com.google.gerrit.server.logging.TraceContext.TraceTimer) ChangeData(com.google.gerrit.server.query.change.ChangeData) StorageException(com.google.gerrit.exceptions.StorageException)

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