use of com.google.gerrit.exceptions.StorageException in project gerrit by GerritCodeReview.
the class RepoSequence method acquire.
/**
* Updates the next available sequence number in NoteDb in order to have a batch of sequence
* numbers available that can be handed out. {@link #counter} stores the next sequence number that
* can be handed out. When {@link #limit} is reached a new batch of sequence numbers needs to be
* retrieved by calling this method.
*
* <p><strong>Note:</strong> Callers are required to acquire the {@link #counterLock} before
* calling this method.
*
* @param count the number of sequence numbers which should be retrieved
*/
private void acquire(int count) {
try (Repository repo = repoManager.openRepository(projectName);
RevWalk rw = new RevWalk(repo)) {
logger.atFine().log("acquire %d ids on %s in %s", count, refName, projectName);
Optional<IntBlob> blob = IntBlob.parse(repo, refName, rw);
afterReadRef.run();
ObjectId oldId;
int next;
if (!blob.isPresent()) {
oldId = ObjectId.zeroId();
next = seed.get();
} else {
oldId = blob.get().id();
next = blob.get().value();
}
next = Math.max(floor, next);
RefUpdate refUpdate = IntBlob.tryStore(repo, rw, projectName, refName, oldId, next + count, gitRefUpdated);
RefUpdateUtil.checkResult(refUpdate);
counter = next;
limit = counter + count;
acquireCount++;
} catch (IOException e) {
throw new StorageException(e);
}
}
use of com.google.gerrit.exceptions.StorageException in project gerrit by GerritCodeReview.
the class RepoSequence method current.
public int current() {
counterLock.lock();
try (Repository repo = repoManager.openRepository(projectName);
RevWalk rw = new RevWalk(repo)) {
Optional<IntBlob> blob = IntBlob.parse(repo, refName, rw);
int current;
if (!blob.isPresent()) {
current = seed.get();
} else {
current = blob.get().value();
}
return current;
} catch (IOException e) {
throw new StorageException(e);
} finally {
counterLock.unlock();
}
}
use of com.google.gerrit.exceptions.StorageException in project gerrit by GerritCodeReview.
the class PatchScriptFactory method call.
@Override
public PatchScript call() throws LargeObjectException, AuthException, InvalidChangeOperationException, IOException, PermissionBackendException {
try {
permissionBackend.user(currentUser).change(notes).check(ChangePermission.READ);
} catch (AuthException e) {
throw new NoSuchChangeException(changeId, e);
}
if (!projectCache.get(notes.getProjectName()).map(ProjectState::statePermitsRead).orElse(false)) {
throw new NoSuchChangeException(changeId);
}
try (Repository git = repoManager.openRepository(notes.getProjectName())) {
try {
validatePatchSetId(psa);
validatePatchSetId(psb);
ObjectId aId = getAId().orElse(null);
ObjectId bId = getBId().orElse(null);
if (bId == null) {
// Change edit: create synthetic PatchSet corresponding to the edit.
Optional<ChangeEdit> edit = editReader.byChange(notes);
if (!edit.isPresent()) {
throw new NoSuchChangeException(notes.getChangeId());
}
bId = edit.get().getEditCommit();
}
return getPatchScript(git, aId, bId);
} catch (DiffNotAvailableException e) {
throw new StorageException(e);
} catch (IOException e) {
logger.atSevere().withCause(e).log("File content unavailable");
throw new NoSuchChangeException(changeId, e);
} catch (org.eclipse.jgit.errors.LargeObjectException err) {
throw new LargeObjectException("File content is too large", err);
}
} catch (RepositoryNotFoundException e) {
logger.atSevere().withCause(e).log("Repository %s not found", notes.getProjectName());
throw new NoSuchChangeException(changeId, e);
} catch (IOException e) {
logger.atSevere().withCause(e).log("Cannot open repository %s", notes.getProjectName());
throw new NoSuchChangeException(changeId, e);
}
}
use of com.google.gerrit.exceptions.StorageException in project gerrit by GerritCodeReview.
the class PatchSetInfoFactory method get.
public PatchSetInfo get(Project.NameKey project, PatchSet patchSet) throws PatchSetInfoNotAvailableException {
try (Repository repo = repoManager.openRepository(project);
RevWalk rw = new RevWalk(repo)) {
RevCommit src = rw.parseCommit(patchSet.commitId());
PatchSetInfo info = get(rw, src, patchSet.id());
info.setParents(toParentInfos(src.getParents(), rw));
return info;
} catch (IOException | StorageException e) {
throw new PatchSetInfoNotAvailableException(e);
}
}
use of com.google.gerrit.exceptions.StorageException in project gerrit by GerritCodeReview.
the class NoteDbUpdateManager method addRewrites.
private static void addRewrites(ListMultimap<String, NoteDbRewriter> rewriters, OpenRepo openRepo) throws IOException {
for (Map.Entry<String, Collection<NoteDbRewriter>> entry : rewriters.asMap().entrySet()) {
String refName = entry.getKey();
ObjectId oldTip = openRepo.cmds.get(refName).orElse(ObjectId.zeroId());
if (oldTip.equals(ObjectId.zeroId())) {
throw new StorageException(String.format("Ref %s is empty", refName));
}
ObjectId currTip = oldTip;
try {
for (NoteDbRewriter noteDbRewriter : entry.getValue()) {
ObjectId nextTip = noteDbRewriter.rewriteCommitHistory(openRepo.rw, openRepo.tempIns, currTip);
if (nextTip != null) {
currTip = nextTip;
}
}
} catch (ConfigInvalidException e) {
throw new StorageException("Cannot rewrite commit history", e);
}
if (!oldTip.equals(currTip)) {
openRepo.cmds.add(new ReceiveCommand(oldTip, currTip, refName));
}
}
}
Aggregations