Search in sources :

Example 1 with UpgradeException

use of org.apache.bookkeeper.bookie.BookieException.UpgradeException in project bookkeeper by apache.

the class FileSystemUpgrade method upgrade.

private static void upgrade(ServerConfiguration conf, RegistrationManager rm) throws UpgradeException {
    try {
        Map<File, File> deferredMoves = new HashMap<File, File>();
        Cookie.Builder cookieBuilder = Cookie.generateCookie(conf);
        Cookie c = cookieBuilder.build();
        for (File d : getAllDirectories(conf)) {
            LOG.info("Upgrading {}", d);
            int version = detectPreviousVersion(d);
            if (version == Cookie.CURRENT_COOKIE_LAYOUT_VERSION) {
                LOG.info("Directory is current, no need to upgrade");
                continue;
            }
            try {
                File curDir = new File(d, BookKeeperConstants.CURRENT_DIR);
                File tmpDir = new File(d, "upgradeTmp." + System.nanoTime());
                deferredMoves.put(curDir, tmpDir);
                if (!tmpDir.mkdirs()) {
                    throw new BookieException.UpgradeException("Could not create temporary directory " + tmpDir);
                }
                c.writeToDirectory(tmpDir);
                String[] files = d.list(new FilenameFilter() {

                    public boolean accept(File dir, String name) {
                        return bookieFilesFilter.accept(dir, name) && !(new File(dir, name).isDirectory());
                    }
                });
                HardLink.createHardLinkMult(d, files, tmpDir);
                linkIndexDirectories(d, tmpDir);
            } catch (IOException ioe) {
                LOG.error("Error upgrading {}", d);
                throw new BookieException.UpgradeException(ioe);
            }
        }
        for (Map.Entry<File, File> e : deferredMoves.entrySet()) {
            try {
                FileUtils.moveDirectory(e.getValue(), e.getKey());
            } catch (IOException ioe) {
                String err = String.format("Error moving upgraded directories into place %s -> %s ", e.getValue(), e.getKey());
                LOG.error(err, ioe);
                throw new BookieException.UpgradeException(ioe);
            }
        }
        if (deferredMoves.isEmpty()) {
            return;
        }
        try {
            c.writeToRegistrationManager(rm, conf, Version.NEW);
        } catch (BookieException ke) {
            LOG.error("Error writing cookie to registration manager");
            throw new BookieException.UpgradeException(ke);
        }
    } catch (IOException ioe) {
        throw new BookieException.UpgradeException(ioe);
    }
}
Also used : HashMap(java.util.HashMap) IOException(java.io.IOException) UpgradeException(org.apache.bookkeeper.bookie.BookieException.UpgradeException) UpgradeException(org.apache.bookkeeper.bookie.BookieException.UpgradeException) FilenameFilter(java.io.FilenameFilter) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with UpgradeException

use of org.apache.bookkeeper.bookie.BookieException.UpgradeException in project bookkeeper by apache.

the class FileSystemUpgrade method upgrade.

public static void upgrade(ServerConfiguration conf) throws BookieException.UpgradeException, InterruptedException {
    LOG.info("Upgrading...");
    try {
        runFunctionWithRegistrationManager(conf, rm -> {
            try {
                upgrade(conf, rm);
            } catch (UpgradeException e) {
                throw new UncheckedExecutionException(e.getMessage(), e);
            }
            return null;
        });
    } catch (MetadataException e) {
        throw new UpgradeException(e);
    } catch (ExecutionException e) {
        throw new UpgradeException(e.getCause());
    }
    LOG.info("Done");
}
Also used : UpgradeException(org.apache.bookkeeper.bookie.BookieException.UpgradeException) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) ExecutionException(java.util.concurrent.ExecutionException) MetadataException(org.apache.bookkeeper.meta.exceptions.MetadataException)

Example 3 with UpgradeException

use of org.apache.bookkeeper.bookie.BookieException.UpgradeException in project bookkeeper by apache.

the class FileSystemUpgrade method rollback.

public static void rollback(ServerConfiguration conf) throws BookieException.UpgradeException, InterruptedException {
    LOG.info("Rolling back upgrade...");
    try {
        runFunctionWithRegistrationManager(conf, rm -> {
            try {
                rollback(conf, rm);
            } catch (UpgradeException e) {
                throw new UncheckedExecutionException(e.getMessage(), e);
            }
            return null;
        });
    } catch (MetadataException e) {
        throw new UpgradeException(e);
    } catch (ExecutionException e) {
        throw new UpgradeException(e.getCause());
    }
    LOG.info("Done");
}
Also used : UpgradeException(org.apache.bookkeeper.bookie.BookieException.UpgradeException) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) ExecutionException(java.util.concurrent.ExecutionException) MetadataException(org.apache.bookkeeper.meta.exceptions.MetadataException)

Aggregations

UpgradeException (org.apache.bookkeeper.bookie.BookieException.UpgradeException)3 UncheckedExecutionException (com.google.common.util.concurrent.UncheckedExecutionException)2 ExecutionException (java.util.concurrent.ExecutionException)2 MetadataException (org.apache.bookkeeper.meta.exceptions.MetadataException)2 File (java.io.File)1 FilenameFilter (java.io.FilenameFilter)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1