You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@bookkeeper.apache.org by GitBox <gi...@apache.org> on 2017/12/20 01:30:40 UTC
[GitHub] reddycharan commented on a change in pull request #894: ISSUE #893: more options for UpdateCookieCmd
reddycharan commented on a change in pull request #894: ISSUE #893: more options for UpdateCookieCmd
URL: https://github.com/apache/bookkeeper/pull/894#discussion_r157919264
##########
File path: bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookieShell.java
##########
@@ -1724,63 +1797,85 @@ private boolean verifyCookie(Cookie oldCookie, File dir) throws IOException {
}
return true;
}
- }
- /**
- * Expand the storage directories owned by a bookie.
- */
- class ExpandStorageCmd extends MyCommand {
- Options opts = new Options();
-
- ExpandStorageCmd() {
- super(CMD_EXPANDSTORAGE);
- }
-
- @Override
- Options getOptions() {
- return opts;
- }
+ private int listOrDeleteCookies(boolean delete, boolean force)
+ throws IOException, BookieException {
+ BookieSocketAddress bookieAddress = Bookie.getBookieAddress(bkConf);
+ File[] journalDirs = bkConf.getJournalDirs();
+ File[] ledgerDirs = bkConf.getLedgerDirs();
+ File[] indexDirs = bkConf.getIndexDirs();
+ File[] allDirs = ArrayUtils.addAll(journalDirs, ledgerDirs);
+ if (indexDirs != null) {
+ allDirs = ArrayUtils.addAll(allDirs, indexDirs);
+ }
- @Override
- String getDescription() {
- return "Add new empty ledger/index directories. Update the directories"
- + "info in the conf file before running the command.";
- }
+ File[] allCurDirs = Bookie.getCurrentDirectories(allDirs);
+ List<File> allVersionFiles = new LinkedList<File>();
+ File versionFile;
+ for (File curDir : allCurDirs) {
+ versionFile = new File(curDir, BookKeeperConstants.VERSION_FILENAME);
+ if (versionFile.exists()) {
+ allVersionFiles.add(versionFile);
+ }
+ }
- @Override
- String getUsage() {
- return "expandstorage";
- }
+ if (!allVersionFiles.isEmpty()) {
+ if (delete) {
+ boolean confirm = force;
+ if (!confirm) {
+ confirm = IOUtils.confirmPrompt("Are you sure you want to delete Cookies locally?");
+ }
+ if (confirm) {
+ for (File verFile : allVersionFiles) {
+ if (!verFile.delete()) {
+ LOG.error(
+ "Failed to delete Local cookie file {}. So aborting deletecookie of Bookie: {}",
+ verFile, bookieAddress);
+ return -1;
+ }
+ }
+ LOG.info("Deleted Local Cookies of Bookie: {}", bookieAddress);
+ } else {
+ LOG.info("Skipping deleting local Cookies of Bookie: {}", bookieAddress);
+ }
+ } else {
+ LOG.info("Listing local Cookie Files of Bookie: {}", bookieAddress);
+ for (File verFile : allVersionFiles) {
+ LOG.info(verFile.getCanonicalPath());
+ }
+ }
+ } else {
+ LOG.info("No local cookies for Bookie: {}", bookieAddress);
+ }
- @Override
- int runCmd(CommandLine cmdLine) {
- ServerConfiguration conf = new ServerConfiguration(bkConf);
try (RegistrationManager rm = new ZKRegistrationManager()) {
+ Versioned<Cookie> cookie = null;
try {
- rm.initialize(bkConf, () -> {
- }, NullStatsLogger.INSTANCE);
- } catch (BookieException e) {
- LOG.error("Exception while establishing zookeeper connection.", e);
- return -1;
+ rm.initialize(bkConf, () -> { }, NullStatsLogger.INSTANCE);
+ cookie = Cookie.readFromRegistrationManager(rm, bookieAddress);
+ } catch (CookieNotFoundException nne) {
+ LOG.info("No cookie for {} in ZooKeeper", bookieAddress);
+ return 0;
}
- List<File> allLedgerDirs = Lists.newArrayList();
- allLedgerDirs.addAll(Arrays.asList(ledgerDirectories));
- if (indexDirectories != ledgerDirectories) {
- allLedgerDirs.addAll(Arrays.asList(indexDirectories));
- }
+ if (delete) {
+ boolean confirm = force;
+ if (!confirm) {
+ confirm = IOUtils.confirmPrompt("Are you sure you want to delete Cookies from Zookeeper?");
+ }
- try {
- conf.setAllowStorageExpansion(true);
Review comment:
I removed this line, not sure why this is added in this commit -https://github.com/sijie/bookkeeper/commit/0db0cf6181f4949fe4684770bb81442694a24b27
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services