jvrao commented on a change in pull request #712: Issue 544: Bootup cookie
validation considers an empty journal to signify a new bookie
URL: https://github.com/apache/bookkeeper/pull/712#discussion_r152193201
##########
File path:
bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/Bookie.java
##########
@@ -277,122 +281,13 @@ private void checkEnvironment(RegistrationManager rm)
throws BookieException, IO
return;
}
- if (conf.getAllowStorageExpansion()) {
- checkEnvironmentWithStorageExpansion(conf, rm, journalDirectories,
allLedgerDirs);
- return;
- }
-
- try {
- boolean newEnv = false;
- List<File> missedCookieDirs = new ArrayList<File>();
- List<Cookie> journalCookies = Lists.newArrayList();
- // try to read cookie from journal directory.
- for (File journalDirectory : journalDirectories) {
- try {
- Cookie journalCookie =
Cookie.readFromDirectory(journalDirectory);
- journalCookies.add(journalCookie);
- if (journalCookie.isBookieHostCreatedFromIp()) {
- conf.setUseHostNameAsBookieID(false);
- } else {
- conf.setUseHostNameAsBookieID(true);
- }
- } catch (FileNotFoundException fnf) {
- newEnv = true;
- missedCookieDirs.add(journalDirectory);
- }
- }
-
- String instanceId = rm.getClusterInstanceId();
- Cookie.Builder builder = Cookie.generateCookie(conf);
- if (null != instanceId) {
- builder.setInstanceId(instanceId);
- }
- Cookie masterCookie = builder.build();
- Versioned<Cookie> rmCookie = null;
- try {
- rmCookie = Cookie.readFromRegistrationManager(rm, conf);
- // If allowStorageExpansion option is set, we should
- // make sure that the new set of ledger/index dirs
- // is a super set of the old; else, we fail the cookie check
- masterCookie.verifyIsSuperSet(rmCookie.getValue());
- } catch (CookieNotFoundException e) {
- // can occur in cases:
- // 1) new environment or
- // 2) done only metadata format and started bookie server.
- }
- for (File journalDirectory : journalDirectories) {
- checkDirectoryStructure(journalDirectory);
- }
- if (!newEnv) {
- for (Cookie journalCookie: journalCookies) {
- masterCookie.verify(journalCookie);
- }
- }
-
-
- for (File dir : allLedgerDirs) {
- checkDirectoryStructure(dir);
- try {
- Cookie c = Cookie.readFromDirectory(dir);
- masterCookie.verify(c);
- } catch (FileNotFoundException fnf) {
- missedCookieDirs.add(dir);
- }
- }
-
- if (!newEnv && missedCookieDirs.size() > 0) {
- // If we find that any of the dirs in missedCookieDirs, existed
- // previously, we stop because we could be missing data
- // Also, if a new ledger dir is being added, we make sure that
- // that dir is empty. Else, we reject the request
- Set<String> existingLedgerDirs = Sets.newHashSet();
- for (Cookie journalCookie : journalCookies) {
- Collections.addAll(existingLedgerDirs,
journalCookie.getLedgerDirPathsFromCookie());
- }
- List<File> dirsMissingData = new ArrayList<File>();
- List<File> nonEmptyDirs = new ArrayList<File>();
- for (File dir : missedCookieDirs) {
- if (existingLedgerDirs.contains(dir.getParent())) {
- // if one of the existing ledger dirs doesn't have
cookie,
- // let us not proceed further
- dirsMissingData.add(dir);
- continue;
- }
- String[] content = dir.list();
- if (content != null && content.length != 0) {
- nonEmptyDirs.add(dir);
- }
- }
- if (dirsMissingData.size() > 0 || nonEmptyDirs.size() > 0) {
- LOG.error("Either not all local directories have cookies
or directories being added "
- + " newly are not empty. "
- + "Directories missing cookie file are: " +
dirsMissingData
- + " New directories that are not empty are: " +
nonEmptyDirs);
- throw new BookieException.InvalidCookieException();
- }
- }
-
- if (missedCookieDirs.size() > 0) {
- LOG.info("Stamping new cookies on all dirs {}",
missedCookieDirs);
- for (File journalDirectory : journalDirectories) {
- masterCookie.writeToDirectory(journalDirectory);
- }
- for (File dir : allLedgerDirs) {
- masterCookie.writeToDirectory(dir);
- }
- masterCookie.writeToRegistrationManager(rm, conf, rmCookie !=
null ? rmCookie.getVersion() : Version.NEW);
- }
-
- List<File> ledgerDirs = ledgerDirsManager.getAllLedgerDirs();
- checkIfDirsOnSameDiskPartition(ledgerDirs);
- List<File> indexDirs = indexDirsManager.getAllLedgerDirs();
- checkIfDirsOnSameDiskPartition(indexDirs);
- checkIfDirsOnSameDiskPartition(journalDirectories);
+ checkEnvironmentWithStorageExpansion(conf, rm, journalDirectories,
allLedgerDirs);
- } catch (IOException ioe) {
- LOG.error("Error accessing cookie on disks", ioe);
- throw new BookieException.InvalidCookieException(ioe);
- }
+ List<File> ledgerDirs = ledgerDirsManager.getAllLedgerDirs();
+ checkIfDirsOnSameDiskPartition(ledgerDirs);
+ List<File> indexDirs = indexDirsManager.getAllLedgerDirs();
+ checkIfDirsOnSameDiskPartition(indexDirs);
Review comment:
Why not simply call checkIfDirsOnSameDiskPartition(allLedgerDirs)?
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services