Search in sources :

Example 56 with StorageException

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);
        }
    }
}
Also used : StorageException(com.google.gerrit.exceptions.StorageException) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) StorageException(com.google.gerrit.exceptions.StorageException) IOException(java.io.IOException)

Example 57 with StorageException

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);
    }
}
Also used : ProvisionException(com.google.inject.ProvisionException) StorageException(com.google.gerrit.exceptions.StorageException)

Example 58 with StorageException

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);
    }
}
Also used : IOException(java.io.IOException) StorageException(com.google.gerrit.exceptions.StorageException)

Example 59 with StorageException

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;
    }
}
Also used : SQLException(java.sql.SQLException) TraceTimer(com.google.gerrit.server.logging.TraceContext.TraceTimer) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) StorageException(com.google.gerrit.exceptions.StorageException) DuplicateKeyException(com.google.gerrit.exceptions.DuplicateKeyException)

Example 60 with StorageException

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);
    }
}
Also used : Repository(org.eclipse.jgit.lib.Repository) IntBlob(com.google.gerrit.server.notedb.IntBlob) RevWalk(org.eclipse.jgit.revwalk.RevWalk) StorageException(com.google.gerrit.exceptions.StorageException)

Aggregations

StorageException (com.google.gerrit.exceptions.StorageException)153 IOException (java.io.IOException)68 Change (com.google.gerrit.entities.Change)47 ObjectId (org.eclipse.jgit.lib.ObjectId)37 Repository (org.eclipse.jgit.lib.Repository)33 ChangeNotes (com.google.gerrit.server.notedb.ChangeNotes)30 PatchSet (com.google.gerrit.entities.PatchSet)29 RevCommit (org.eclipse.jgit.revwalk.RevCommit)28 ArrayList (java.util.ArrayList)25 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)24 Project (com.google.gerrit.entities.Project)22 Ref (org.eclipse.jgit.lib.Ref)22 ChangeData (com.google.gerrit.server.query.change.ChangeData)21 RevWalk (org.eclipse.jgit.revwalk.RevWalk)21 Account (com.google.gerrit.entities.Account)20 Inject (com.google.inject.Inject)19 Map (java.util.Map)19 Test (org.junit.Test)19 List (java.util.List)18 BranchNameKey (com.google.gerrit.entities.BranchNameKey)17