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_r152193185
##########
File path:
bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/Bookie.java
##########
@@ -441,117 +336,220 @@ private void checkIfDirsOnSameDiskPartition(List<File>
dirs) throws DiskPartitio
}
}
- public static void checkEnvironmentWithStorageExpansion(
- ServerConfiguration conf,
- RegistrationManager rm,
- List<File> journalDirectories,
- List<File> allLedgerDirs) throws BookieException {
+ static List<BookieSocketAddress> possibleBookieIds(ServerConfiguration
conf)
+ throws BookieException {
+ // we need to loop through all possible bookie identifiers to ensure
it is treated as a new environment
+ // just because of bad configuration
+ List<BookieSocketAddress> addresses =
Lists.newArrayListWithExpectedSize(3);
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);
- }
+ // ip address
+ addresses.add(getBookieAddress(
+ new
ServerConfiguration(conf).setUseHostNameAsBookieID(false).setAdvertisedAddress(null)));
+ // host name
+ addresses.add(getBookieAddress(
+ new
ServerConfiguration(conf).setUseHostNameAsBookieID(true).setAdvertisedAddress(null)));
+ // advertised address
+ if (null != conf.getAdvertisedAddress()) {
+ addresses.add(getBookieAddress(conf));
}
+ } catch (UnknownHostException e) {
+ throw new UnknownBookieIdException(e);
+ }
+ return addresses;
+ }
- String instanceId = rm.getClusterInstanceId();
- Cookie.Builder builder = Cookie.generateCookie(conf);
- if (null != instanceId) {
- builder.setInstanceId(instanceId);
- }
- Cookie masterCookie = builder.build();
- Versioned<Cookie> rmCookie = null;
+ static Versioned<Cookie> readAndVerifyCookieFromRegistrationManager(
+ Cookie masterCookie, RegistrationManager rm,
+ List<BookieSocketAddress> addresses, boolean allowExpansion)
+ throws BookieException {
+ Versioned<Cookie> rmCookie = null;
+ for (BookieSocketAddress address : addresses) {
try {
- rmCookie = Cookie.readFromRegistrationManager(rm, conf);
+ rmCookie = Cookie.readFromRegistrationManager(rm, address);
// 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.verifyIsSuperSet(journalCookie);
+ if (allowExpansion) {
+ masterCookie.verifyIsSuperSet(rmCookie.getValue());
+ } else {
+ masterCookie.verify(rmCookie.getValue());
}
+ } catch (CookieNotFoundException e) {
+ continue;
}
+ }
+ return rmCookie;
+ }
-
- for (File dir : allLedgerDirs) {
- checkDirectoryStructure(dir);
- try {
- Cookie c = Cookie.readFromDirectory(dir);
+ private static Pair<List<File>, List<Cookie>> verifyAndGetMissingDirs(
+ Cookie masterCookie, boolean allowExpansion, List<File> dirs)
+ throws InvalidCookieException, IOException {
+ List<File> missingDirs = Lists.newArrayList();
+ List<Cookie> existedCookies = Lists.newArrayList();
+ for (File dir : dirs) {
+ checkDirectoryStructure(dir);
Review comment:
You can do this at the top.
----------------------------------------------------------------
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