use of com.google.gerrit.exceptions.StorageException in project gerrit by GerritCodeReview.
the class NoteDbSchemaUpdater method update.
public void update(UpdateUI ui) {
ensureSchemaCreated();
int currentVersion = versionManager.read();
if (currentVersion == 0) {
// The only valid case where there is no refs/meta/version is when running 3.x init for the
// first time on a site that previously ran init on 2.16. A freshly created 3.x site will have
// seeded refs/meta/version during AllProjectsCreator, so it won't hit this block.
checkNoteDbConfigFor216();
}
for (int nextVersion : requiredUpgrades(currentVersion, schemaVersions.keySet())) {
try {
ui.message(String.format("Migrating data to schema %d ...", nextVersion));
NoteDbSchemaVersions.get(schemaVersions, nextVersion).upgrade(args, ui);
versionManager.increment(nextVersion - 1);
} catch (Exception e) {
throw new StorageException(String.format("Failed to upgrade to schema version %d", nextVersion), e);
}
}
}
use of com.google.gerrit.exceptions.StorageException in project gerrit by GerritCodeReview.
the class NoteDbSchemaVersionCheck method start.
@Override
public void start() {
try {
int current = versionManager.read();
if (current == 0) {
throw new ProvisionException(String.format("Schema not yet initialized. Run init to initialize the schema:\n" + "$ java -jar gerrit.war init -d %s", sitePaths.site_path.toAbsolutePath()));
}
int expected = NoteDbSchemaVersions.LATEST;
if (current > expected && gerritConfig.getBoolean("gerrit", "experimentalRollingUpgrade", false)) {
logger.atWarning().log("Gerrit has detected refs/meta/version %d different than the expected %d." + "Bear in mind that this is supported ONLY for rolling upgrades to immediate next " + "Gerrit version (e.g. v3.1 to v3.2). If this is not expected, remove gerrit.experimentalRollingUpgrade " + "from $GERRIT_SITE/etc/gerrit.config and restart Gerrit." + "Please note that gerrit.experimentalRollingUpgrade is intended to be used " + "for the rolling upgrade phase only and should be disabled afterwards.", current, expected);
} else if (current != expected) {
String advice = current > expected ? "Downgrade is not supported" : String.format("Run init to upgrade:\n$ java -jar %s init -d %s", sitePaths.gerrit_war.toAbsolutePath(), sitePaths.site_path.toAbsolutePath());
throw new ProvisionException(String.format("Unsupported schema version %d; expected schema version %d. %s", current, expected, advice));
}
} catch (StorageException e) {
throw new ProvisionException("Failed to read NoteDb schema version", e);
}
}
use of com.google.gerrit.exceptions.StorageException in project gerrit by GerritCodeReview.
the class ProjectConfigSchemaUpdate method save.
public void save(PersonIdent personIdent, String commitMessage) {
if (!updated) {
return;
}
update.getCommitBuilder().setAuthor(personIdent);
update.getCommitBuilder().setCommitter(personIdent);
update.setMessage(commitMessage);
try {
commit(update);
} catch (IOException e) {
throw new StorageException(e);
}
}
use of com.google.gerrit.exceptions.StorageException in project gerrit by GerritCodeReview.
the class JdbcAccountPatchReviewStore method markReviewed.
@Override
public void markReviewed(PatchSet.Id psId, Account.Id accountId, Collection<String> paths) {
if (paths == null || paths.isEmpty()) {
return;
}
try (TraceTimer ignored = TraceContext.newTimer("Mark files as reviewed", Metadata.builder().patchSetId(psId.get()).accountId(accountId.get()).resourceCount(paths.size()).build());
Connection con = ds.getConnection();
PreparedStatement stmt = con.prepareStatement("INSERT INTO account_patch_reviews " + "(account_id, change_id, patch_set_id, file_name) VALUES " + "(?, ?, ?, ?)")) {
for (String path : paths) {
stmt.setInt(1, accountId.get());
stmt.setInt(2, psId.changeId().get());
stmt.setInt(3, psId.get());
stmt.setString(4, path);
stmt.addBatch();
}
stmt.executeBatch();
} catch (SQLException e) {
StorageException ormException = convertError("insert", e);
if (ormException instanceof DuplicateKeyException) {
return;
}
throw ormException;
}
}
use of com.google.gerrit.exceptions.StorageException in project gerrit by GerritCodeReview.
the class NoteDbSchemaVersionManager method increment.
public void increment(int expectedOldVersion) throws IOException {
try (Repository repo = repoManager.openRepository(allProjectsName);
RevWalk rw = new RevWalk(repo)) {
Optional<IntBlob> old = IntBlob.parse(repo, REFS_VERSION, rw);
if (old.isPresent() && old.get().value() != expectedOldVersion) {
throw new StorageException(String.format("Expected old version %d for %s, found %d", expectedOldVersion, REFS_VERSION, old.get().value()));
}
IntBlob.store(repo, rw, allProjectsName, REFS_VERSION, old.map(IntBlob::id).orElse(ObjectId.zeroId()), expectedOldVersion + 1, GitReferenceUpdated.DISABLED);
}
}
Aggregations