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);
}
}
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");
}
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");
}
Aggregations