Search in sources :

Example 21 with TraceTimer

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

the class StarredChangesUtil method updateLabels.

private void updateLabels(Repository repo, String refName, ObjectId oldObjectId, Collection<String> labels) throws IOException, InvalidLabelsException {
    try (TraceTimer traceTimer = TraceContext.newTimer("Update star labels", Metadata.builder().noteDbRefName(refName).resourceCount(labels.size()).build());
        RevWalk rw = new RevWalk(repo)) {
        RefUpdate u = repo.updateRef(refName);
        u.setExpectedOldObjectId(oldObjectId);
        u.setForceUpdate(true);
        u.setNewObjectId(writeLabels(repo, labels));
        u.setRefLogIdent(serverIdent.get());
        u.setRefLogMessage("Update star labels", true);
        RefUpdate.Result result = u.update(rw);
        switch(result) {
            case NEW:
            case FORCED:
            case NO_CHANGE:
            case FAST_FORWARD:
                gitRefUpdated.fire(allUsers, u, null);
                return;
            case LOCK_FAILURE:
                throw new LockFailureException(String.format("Update star labels on ref %s failed", refName), u);
            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("Update star labels on ref %s failed: %s", refName, result.name()));
        }
    }
}
Also used : TraceTimer(com.google.gerrit.server.logging.TraceContext.TraceTimer) RevWalk(org.eclipse.jgit.revwalk.RevWalk) 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 22 with TraceTimer

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

the class RevisionResource method getETag.

@Override
public String getETag() {
    try (TraceTimer ignored = TraceContext.newTimer("Compute revision ETag", Metadata.builder().changeId(change.getId().get()).patchSetId(ps.number()).projectName(change.getProject().get()).build())) {
        Hasher h = Hashing.murmur3_128().newHasher();
        prepareETag(h, getUser());
        return h.hash().toString();
    }
}
Also used : Hasher(com.google.common.hash.Hasher) TraceTimer(com.google.gerrit.server.logging.TraceContext.TraceTimer)

Example 23 with TraceTimer

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

the class GroupNameNotes method loadAllGroups.

/**
 * Loads the {@code GroupReference}s (name/UUID pairs) for all groups.
 *
 * <p>Even though group UUIDs should be unique, this class doesn't enforce it. For this reason,
 * it's technically possible that two of the {@code GroupReference}s have a duplicate UUID but a
 * different name. In practice, this shouldn't occur unless we introduce a bug in the future.
 *
 * @param repository the repository which holds the commits of the notes
 * @return the {@code GroupReference}s of all existing groups/notes
 * @throws IOException if the repository can't be accessed for some reason
 * @throws ConfigInvalidException if one of the notes is in an invalid state
 */
public static ImmutableList<GroupReference> loadAllGroups(Repository repository) throws IOException, ConfigInvalidException {
    Ref ref = repository.exactRef(RefNames.REFS_GROUPNAMES);
    if (ref == null) {
        return ImmutableList.of();
    }
    try (TraceTimer ignored = TraceContext.newTimer("Loading all groups", Metadata.builder().noteDbRefName(RefNames.REFS_GROUPNAMES).build());
        RevWalk revWalk = new RevWalk(repository);
        ObjectReader reader = revWalk.getObjectReader()) {
        RevCommit notesCommit = revWalk.parseCommit(ref.getObjectId());
        NoteMap noteMap = NoteMap.read(reader, notesCommit);
        Multiset<GroupReference> groupReferences = HashMultiset.create();
        for (Note note : noteMap) {
            GroupReference groupReference = getGroupReference(reader, note.getData());
            int numOfOccurrences = groupReferences.add(groupReference, 1);
            if (numOfOccurrences > 1) {
                GroupsNoteDbConsistencyChecker.logConsistencyProblemAsWarning("The UUID of group %s (%s) is duplicate in group name notes", groupReference.getName(), groupReference.getUUID());
            }
        }
        return ImmutableList.copyOf(groupReferences);
    }
}
Also used : Ref(org.eclipse.jgit.lib.Ref) Note(org.eclipse.jgit.notes.Note) TraceTimer(com.google.gerrit.server.logging.TraceContext.TraceTimer) ObjectReader(org.eclipse.jgit.lib.ObjectReader) NoteMap(org.eclipse.jgit.notes.NoteMap) GroupReference(com.google.gerrit.entities.GroupReference) RevWalk(org.eclipse.jgit.revwalk.RevWalk) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 24 with TraceTimer

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

the class GroupsUpdate method createGroup.

/**
 * Creates the specified group for the specified members (accounts).
 *
 * @param groupCreation an {@link InternalGroupCreation} which specifies all mandatory properties
 *     of the group
 * @param groupDelta a {@link GroupDelta} which specifies optional properties of the group. If
 *     this {@link GroupDelta} updates a property which was already specified by the {@link
 *     InternalGroupCreation}, the value of this {@link GroupDelta} wins.
 * @throws DuplicateKeyException if a group with the chosen name already exists
 * @throws IOException if indexing fails, or an error occurs while reading/writing from/to NoteDb
 * @return the created {@link InternalGroup}
 */
public InternalGroup createGroup(InternalGroupCreation groupCreation, GroupDelta groupDelta) throws DuplicateKeyException, IOException, ConfigInvalidException {
    try (TraceTimer ignored = TraceContext.newTimer("Creating group", Metadata.builder().groupName(groupDelta.getName().orElseGet(groupCreation::getNameKey).get()).build())) {
        InternalGroup createdGroup = createGroupInNoteDbWithRetry(groupCreation, groupDelta);
        evictCachesOnGroupCreation(createdGroup);
        dispatchAuditEventsOnGroupCreation(createdGroup);
        return createdGroup;
    }
}
Also used : TraceTimer(com.google.gerrit.server.logging.TraceContext.TraceTimer) InternalGroup(com.google.gerrit.entities.InternalGroup)

Example 25 with TraceTimer

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

the class GroupIndexerImpl method index.

@Override
public void index(AccountGroup.UUID uuid) {
    // Evict the cache to get an up-to-date value for sure.
    groupCache.evict(uuid);
    Optional<InternalGroup> internalGroup = groupCache.get(uuid);
    if (internalGroup.isPresent()) {
        logger.atFine().log("Replace group %s in index", uuid.get());
    } else {
        logger.atFine().log("Delete group %s from index", uuid.get());
    }
    for (Index<AccountGroup.UUID, InternalGroup> i : getWriteIndexes()) {
        if (internalGroup.isPresent()) {
            try (TraceTimer traceTimer = TraceContext.newTimer("Replacing group", Metadata.builder().groupUuid(uuid.get()).indexVersion(i.getSchema().getVersion()).build())) {
                i.replace(internalGroup.get());
            } catch (RuntimeException e) {
                throw new StorageException(String.format("Failed to replace group %s in index version %d", uuid.get(), i.getSchema().getVersion()), e);
            }
        } else {
            try (TraceTimer traceTimer = TraceContext.newTimer("Deleting group", Metadata.builder().groupUuid(uuid.get()).indexVersion(i.getSchema().getVersion()).build())) {
                i.delete(uuid);
            } catch (RuntimeException e) {
                throw new StorageException(String.format("Failed to delete group %s from index version %d", uuid.get(), i.getSchema().getVersion()), e);
            }
        }
    }
    fireGroupIndexedEvent(uuid.get());
}
Also used : TraceTimer(com.google.gerrit.server.logging.TraceContext.TraceTimer) StorageException(com.google.gerrit.exceptions.StorageException) InternalGroup(com.google.gerrit.entities.InternalGroup)

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