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