use of com.google.gerrit.exceptions.StorageException in project gerrit by GerritCodeReview.
the class StreamEventsApiListener method onVoteDeleted.
@Override
public void onVoteDeleted(VoteDeletedListener.Event ev) {
try {
ChangeNotes notes = getNotes(ev.getChange());
Change change = notes.getChange();
VoteDeletedEvent event = new VoteDeletedEvent(change);
event.change = changeAttributeSupplier(change, notes);
event.patchSet = patchSetAttributeSupplier(change, psUtil.current(notes));
event.comment = ev.getMessage();
event.reviewer = accountAttributeSupplier(ev.getReviewer());
event.remover = accountAttributeSupplier(ev.getWho());
event.approvals = approvalsAttributeSupplier(change, ev.getApprovals(), ev.getOldApprovals());
dispatcher.run(d -> d.postEvent(change, event));
} catch (StorageException e) {
logger.atSevere().withCause(e).log("Failed to dispatch event");
}
}
use of com.google.gerrit.exceptions.StorageException in project gerrit by GerritCodeReview.
the class AccountIT method failAfterRetryerGivesUp.
@Test
public void failAfterRetryerGivesUp() throws Exception {
List<String> status = ImmutableList.of("foo", "bar", "baz");
String fullName = "Foo";
AtomicInteger bgCounter = new AtomicInteger(0);
PersonIdent ident = serverIdent.get();
AccountsUpdate update = new AccountsUpdate(repoManager, gitReferenceUpdated, Optional.empty(), allUsers, externalIds, metaDataUpdateInternalFactory, new RetryHelper(cfg, retryMetrics, null, null, null, exceptionHooks, r -> r.withStopStrategy(StopStrategies.stopAfterAttempt(status.size())).withBlockStrategy(noSleepBlockStrategy)), extIdNotesFactory, ident, ident, () -> {
try {
accountsUpdateProvider.get().update("Set Status", admin.id(), u -> u.setStatus(status.get(bgCounter.getAndAdd(1))));
} catch (IOException | ConfigInvalidException | StorageException e) {
// Ignore, the expected exception is asserted later
}
}, Runnables.doNothing());
assertThat(bgCounter.get()).isEqualTo(0);
AccountInfo accountInfo = gApi.accounts().id(admin.id().get()).get();
assertThat(accountInfo.status).isNull();
assertThat(accountInfo.name).isNotEqualTo(fullName);
assertThrows(LockFailureException.class, () -> update.update("Set Full Name", admin.id(), u -> u.setFullName(fullName)));
assertThat(bgCounter.get()).isEqualTo(status.size());
Account updatedAccount = accounts.get(admin.id()).get().account();
assertThat(updatedAccount.status()).isEqualTo(Iterables.getLast(status));
assertThat(updatedAccount.fullName()).isEqualTo(admin.fullName());
accountInfo = gApi.accounts().id(admin.id().get()).get();
assertThat(accountInfo.status).isEqualTo(Iterables.getLast(status));
assertThat(accountInfo.name).isEqualTo(admin.fullName());
}
use of com.google.gerrit.exceptions.StorageException in project gerrit by GerritCodeReview.
the class AccountIT method atomicReadMofifyWriteExternalIds.
@Test
public void atomicReadMofifyWriteExternalIds() throws Exception {
projectOperations.allProjectsForUpdate().add(allowCapability(GlobalCapability.ACCESS_DATABASE).group(REGISTERED_USERS)).update();
Account.Id accountId = Account.id(seq.nextAccountId());
ExternalId extIdA1 = externalIdFactory.create("foo", "A-1", accountId);
accountsUpdateProvider.get().insert("Create Test Account", accountId, u -> u.addExternalId(extIdA1));
AtomicInteger bgCounterA1 = new AtomicInteger(0);
AtomicInteger bgCounterA2 = new AtomicInteger(0);
PersonIdent ident = serverIdent.get();
ExternalId extIdA2 = externalIdFactory.create("foo", "A-2", accountId);
AccountsUpdate update = new AccountsUpdate(repoManager, gitReferenceUpdated, Optional.empty(), allUsers, externalIds, metaDataUpdateInternalFactory, new RetryHelper(cfg, retryMetrics, null, null, null, exceptionHooks, r -> r.withBlockStrategy(noSleepBlockStrategy)), extIdNotesFactory, ident, ident, Runnables.doNothing(), () -> {
try {
accountsUpdateProvider.get().update("Update External ID", accountId, u -> u.replaceExternalId(extIdA1, extIdA2));
} catch (IOException | ConfigInvalidException | StorageException e) {
// Ignore, the expected exception is asserted later
}
});
assertThat(bgCounterA1.get()).isEqualTo(0);
assertThat(bgCounterA2.get()).isEqualTo(0);
assertThat(gApi.accounts().id(accountId.get()).getExternalIds().stream().map(i -> i.identity).collect(toSet())).containsExactly(extIdA1.key().get());
ExternalId extIdB1 = externalIdFactory.create("foo", "B-1", accountId);
ExternalId extIdB2 = externalIdFactory.create("foo", "B-2", accountId);
Optional<AccountState> updatedAccount = update.update("Update External ID", accountId, (a, u) -> {
if (a.externalIds().contains(extIdA1)) {
bgCounterA1.getAndIncrement();
u.replaceExternalId(extIdA1, extIdB1);
}
if (a.externalIds().contains(extIdA2)) {
bgCounterA2.getAndIncrement();
u.replaceExternalId(extIdA2, extIdB2);
}
});
assertThat(bgCounterA1.get()).isEqualTo(1);
assertThat(bgCounterA2.get()).isEqualTo(1);
assertThat(updatedAccount).isPresent();
assertThat(updatedAccount.get().externalIds()).containsExactly(extIdB2);
assertThat(accounts.get(accountId).get().externalIds()).containsExactly(extIdB2);
assertThat(gApi.accounts().id(accountId.get()).getExternalIds().stream().map(i -> i.identity).collect(toSet())).containsExactly(extIdB2.key().get());
}
use of com.google.gerrit.exceptions.StorageException in project gerrit by GerritCodeReview.
the class AccountIT method retryOnLockFailure.
@Test
public void retryOnLockFailure() throws Exception {
String status = "happy";
String fullName = "Foo";
AtomicBoolean doneBgUpdate = new AtomicBoolean(false);
PersonIdent ident = serverIdent.get();
AccountsUpdate update = new AccountsUpdate(repoManager, gitReferenceUpdated, Optional.empty(), allUsers, externalIds, metaDataUpdateInternalFactory, new RetryHelper(cfg, retryMetrics, null, null, null, exceptionHooks, r -> r.withBlockStrategy(noSleepBlockStrategy)), extIdNotesFactory, ident, ident, () -> {
if (!doneBgUpdate.getAndSet(true)) {
try {
accountsUpdateProvider.get().update("Set Status", admin.id(), u -> u.setStatus(status));
} catch (IOException | ConfigInvalidException | StorageException e) {
// Ignore, the successful update of the account is asserted later
}
}
}, Runnables.doNothing());
assertThat(doneBgUpdate.get()).isFalse();
AccountInfo accountInfo = gApi.accounts().id(admin.id().get()).get();
assertThat(accountInfo.status).isNull();
assertThat(accountInfo.name).isNotEqualTo(fullName);
Optional<AccountState> updatedAccountState = update.update("Set Full Name", admin.id(), u -> u.setFullName(fullName));
assertThat(doneBgUpdate.get()).isTrue();
assertThat(updatedAccountState).isPresent();
Account updatedAccount = updatedAccountState.get().account();
assertThat(updatedAccount.status()).isEqualTo(status);
assertThat(updatedAccount.fullName()).isEqualTo(fullName);
accountInfo = gApi.accounts().id(admin.id().get()).get();
assertThat(accountInfo.status).isEqualTo(status);
assertThat(accountInfo.name).isEqualTo(fullName);
}
use of com.google.gerrit.exceptions.StorageException in project gerrit by GerritCodeReview.
the class ConsistencyChecker method checkExpectMergedAs.
private void checkExpectMergedAs() {
if (!ObjectId.isId(fix.expectMergedAs)) {
problem("Invalid revision on expected merged commit: " + fix.expectMergedAs);
return;
}
ObjectId objId = ObjectId.fromString(fix.expectMergedAs);
RevCommit commit = parseCommit(objId, "expected merged commit");
if (commit == null) {
return;
}
try {
if (!rw.isMergedInto(commit, tip)) {
problem(String.format("Expected merged commit %s is not merged into destination ref %s (%s)", commit.name(), change().getDest().branch(), tip.name()));
return;
}
List<PatchSet.Id> thisCommitPsIds = new ArrayList<>();
for (Ref ref : repo.getRefDatabase().getRefsByPrefix(REFS_CHANGES)) {
if (!ref.getObjectId().equals(commit)) {
continue;
}
PatchSet.Id psId = PatchSet.Id.fromRef(ref.getName());
if (psId == null) {
continue;
}
try {
Change c = notesFactory.createChecked(change().getProject(), psId.changeId()).getChange();
if (!c.getDest().equals(change().getDest())) {
continue;
}
} catch (StorageException e) {
logger.atWarning().withCause(e).log("Error in consistency check of change %s", notes.getChangeId());
// Include this patch set; should cause an error below, which is good.
}
thisCommitPsIds.add(psId);
}
switch(thisCommitPsIds.size()) {
case 0:
// No patch set for this commit; insert one.
rw.parseBody(commit);
String changeId = Iterables.getFirst(ChangeUtil.getChangeIdsFromFooter(commit, urlFormatter.get()), null);
// Missing Change-Id footer is ok, but mismatched is not.
if (changeId != null && !changeId.equals(change().getKey().get())) {
problem(String.format("Expected merged commit %s has Change-Id: %s, but expected %s", commit.name(), changeId, change().getKey().get()));
return;
}
insertMergedPatchSet(commit, null, false);
break;
case 1:
// Existing patch set ref pointing to this commit.
PatchSet.Id id = thisCommitPsIds.get(0);
if (id.equals(change().currentPatchSetId())) {
// If it's the current patch set, we can just fix the status.
fixMerged(wrongChangeStatus(id, commit));
} else if (id.get() > change().currentPatchSetId().get()) {
// If it's newer than the current patch set, reuse this patch set
// ID when inserting a new merged patch set.
insertMergedPatchSet(commit, id, true);
} else {
// If it's older than the current patch set, just delete the old
// ref, and use a new ID when inserting a new merged patch set.
insertMergedPatchSet(commit, id, false);
}
break;
default:
problem(String.format("Multiple patch sets for expected merged commit %s: %s", commit.name(), thisCommitPsIds.stream().sorted(comparing(PatchSet.Id::get)).collect(toImmutableList())));
break;
}
} catch (IOException e) {
ProblemInfo problem = problem("Error looking up expected merged commit " + fix.expectMergedAs);
logger.atWarning().withCause(e).log("Error in consistency check of change %s: %s", notes.getChangeId(), problem);
}
}
Aggregations