use of com.google.gerrit.exceptions.StorageException in project gerrit by GerritCodeReview.
the class RobotCommentUpdate method applyImpl.
@Override
protected CommitBuilder applyImpl(RevWalk rw, ObjectInserter ins, ObjectId curr) throws IOException {
CommitBuilder cb = new CommitBuilder();
cb.setMessage("Update robot comments");
try {
return storeCommentsInNotes(rw, ins, curr, cb);
} catch (ConfigInvalidException e) {
throw new StorageException(e);
}
}
use of com.google.gerrit.exceptions.StorageException in project gerrit by GerritCodeReview.
the class ProjectsConsistencyChecker method executeQueryAndAutoCloseChanges.
private ImmutableList<ChangeInfo> executeQueryAndAutoCloseChanges(Predicate<ChangeData> basePredicate, Set<Change.Id> seenChanges, List<Predicate<ChangeData>> predicates, boolean fix, Map<Change.Key, ObjectId> changeIdToMergedSha1, List<ObjectId> mergedSha1s) {
if (predicates.isEmpty()) {
return ImmutableList.of();
}
try {
List<ChangeData> queryResult = retryHelper.changeIndexQuery("projectsConsistencyCheckerQueryChanges", q -> q.setRequestedFields(ChangeField.CHANGE, ChangeField.PATCH_SET).query(and(basePredicate, or(predicates)))).call();
// Result for this query that we want to return to the client.
ImmutableList.Builder<ChangeInfo> autoCloseableChangesByBranch = ImmutableList.builder();
for (ChangeData autoCloseableChange : queryResult) {
// earlier queries.
if (seenChanges.add(autoCloseableChange.getId())) {
retryHelper.changeUpdate("projectsConsistencyCheckerAutoCloseChanges", () -> {
// Auto-close by change
if (changeIdToMergedSha1.containsKey(autoCloseableChange.change().getKey())) {
autoCloseableChangesByBranch.add(changeJson(fix, changeIdToMergedSha1.get(autoCloseableChange.change().getKey())).format(autoCloseableChange));
return null;
}
// Auto-close by commit
for (ObjectId patchSetSha1 : autoCloseableChange.patchSets().stream().map(PatchSet::commitId).collect(toSet())) {
if (mergedSha1s.contains(patchSetSha1)) {
autoCloseableChangesByBranch.add(changeJson(fix, patchSetSha1).format(autoCloseableChange));
break;
}
}
return null;
}).call();
}
}
return autoCloseableChangesByBranch.build();
} catch (Exception e) {
Throwables.throwIfUnchecked(e);
throw new StorageException(e);
}
}
use of com.google.gerrit.exceptions.StorageException in project gerrit by GerritCodeReview.
the class ReviewersUtil method suggestAccounts.
private List<Account.Id> suggestAccounts(SuggestReviewers suggestReviewers) throws BadRequestException {
try (Timer0.Context ctx = metrics.queryAccountsLatency.start()) {
// For performance reasons we don't use AccountQueryProvider as it would always load the
// complete account from the cache (or worse, from NoteDb) even though we only need the ID
// which we can directly get from the returned results.
Predicate<AccountState> pred = Predicate.and(AccountPredicates.isActive(), accountQueryBuilder.defaultQuery(suggestReviewers.getQuery()));
logger.atFine().log("accounts index query: %s", pred);
accountIndexRewriter.validateMaxTermsInQuery(pred);
boolean useLegacyNumericFields = accountIndexes.getSearchIndex().getSchema().useLegacyNumericFields();
FieldDef<AccountState, ?> idField = useLegacyNumericFields ? AccountField.ID : AccountField.ID_STR;
ResultSet<FieldBundle> result = accountIndexes.getSearchIndex().getSource(pred, QueryOptions.create(indexConfig, 0, suggestReviewers.getLimit(), ImmutableSet.of(idField.getName()))).readRaw();
List<Account.Id> matches = result.toList().stream().map(f -> fromIdField(f, useLegacyNumericFields)).collect(toList());
logger.atFine().log("Matches: %s", matches);
return matches;
} catch (TooManyTermsInQueryException e) {
throw new BadRequestException(e.getMessage());
} catch (QueryParseException e) {
logger.atWarning().withCause(e).log("Suggesting accounts failed, return empty result.");
return ImmutableList.of();
} catch (StorageException e) {
if (e.getCause() instanceof TooManyTermsInQueryException) {
throw new BadRequestException(e.getMessage());
}
if (e.getCause() instanceof QueryParseException) {
return ImmutableList.of();
}
throw e;
}
}
use of com.google.gerrit.exceptions.StorageException in project gerrit by GerritCodeReview.
the class JdbcAccountPatchReviewStore method markReviewed.
@Override
public boolean markReviewed(PatchSet.Id psId, Account.Id accountId, String path) {
try (TraceTimer ignored = TraceContext.newTimer("Mark file as reviewed", Metadata.builder().patchSetId(psId.get()).accountId(accountId.get()).filePath(path).build());
Connection con = ds.getConnection();
PreparedStatement stmt = con.prepareStatement("INSERT INTO account_patch_reviews " + "(account_id, change_id, patch_set_id, file_name) VALUES " + "(?, ?, ?, ?)")) {
stmt.setInt(1, accountId.get());
stmt.setInt(2, psId.changeId().get());
stmt.setInt(3, psId.get());
stmt.setString(4, path);
stmt.executeUpdate();
return true;
} catch (SQLException e) {
StorageException ormException = convertError("insert", e);
if (ormException instanceof DuplicateKeyException) {
return false;
}
throw ormException;
}
}
use of com.google.gerrit.exceptions.StorageException in project gerrit by GerritCodeReview.
the class NoteDbSchemaUpdater method requiredUpgrades.
@VisibleForTesting
static ImmutableList<Integer> requiredUpgrades(int currentVersion, ImmutableSortedSet<Integer> allVersions) {
int firstVersion = allVersions.first();
int latestVersion = allVersions.last();
if (currentVersion == latestVersion) {
return ImmutableList.of();
} else if (currentVersion > latestVersion) {
throw new StorageException(String.format("Cannot downgrade NoteDb schema from version %d to %d", currentVersion, latestVersion));
}
int firstUpgradeVersion;
if (currentVersion == 0) {
// Bootstrap NoteDb version to minimum supported schema number.
firstUpgradeVersion = firstVersion;
} else {
if (currentVersion < firstVersion - 1) {
throw new StorageException(String.format("Cannot skip NoteDb schema from version %d to %d", currentVersion, firstVersion));
}
firstUpgradeVersion = currentVersion + 1;
}
return IntStream.rangeClosed(firstUpgradeVersion, latestVersion).boxed().collect(toImmutableList());
}
Aggregations