Skip to content

Commit 1a88ef0

Browse files
committed
indexDir compatible fix for issue #3430
1 parent 442e3bb commit 1a88ef0

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/Cookie.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import org.apache.bookkeeper.versioning.LongVersion;
5151
import org.apache.bookkeeper.versioning.Version;
5252
import org.apache.bookkeeper.versioning.Versioned;
53+
import org.apache.commons.lang3.StringUtils;
5354
import org.slf4j.Logger;
5455
import org.slf4j.LoggerFactory;
5556

@@ -136,11 +137,27 @@ private boolean verifyLedgerDirs(Cookie c, boolean checkIfSuperSet) {
136137
}
137138
}
138139

140+
private boolean verifyDefaultIndexDirsWithLedgerDirs(String indexDirsTpm, Cookie c, boolean checkIfSuperSet) {
141+
if (!checkIfSuperSet) {
142+
return indexDirsTpm.equals(c.ledgerDirs);
143+
} else {
144+
return isSuperSet(decodeDirPathFromCookie(indexDirsTpm), decodeDirPathFromCookie(c.ledgerDirs));
145+
}
146+
}
147+
139148
private boolean verifyIndexDirs(Cookie c, boolean checkIfSuperSet) {
140149
// Compatible with old cookie
141150
if (null == indexDirs && null == c.indexDirs) {
142151
return true;
143152
}
153+
154+
// compatible logic: existed node's cookie has no indexDirs, but indexDirs's default value equals ledgerDirs
155+
if (StringUtils.isNotBlank(indexDirs)
156+
&& null == c.indexDirs
157+
&& verifyDefaultIndexDirsWithLedgerDirs(indexDirs, c, checkIfSuperSet)) {
158+
return true;
159+
}
160+
144161
if (null == indexDirs || null == c.indexDirs) {
145162
return false;
146163
}

bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/CookieIndexDirTest.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -970,4 +970,35 @@ public void testBookieIdSetting() throws Exception {
970970
cookie.writeToRegistrationManager(rm, conf, version1);
971971
Assert.assertTrue(cookie.toString().contains(customBookieId));
972972
}
973+
974+
/**
975+
* Compatibility test
976+
* 1. First create bookie without indexDirName
977+
* 2. Configure indexDirName to start bookie
978+
*/
979+
@Test
980+
public void testNewBookieStartingWithOldCookie() throws Exception {
981+
String journalDir = newDirectory();
982+
String[] ledgerDirs = {newDirectory(), newDirectory()};
983+
ServerConfiguration conf = TestBKConfiguration.newServerConfiguration();
984+
conf.setJournalDirName(journalDir)
985+
.setLedgerDirNames(ledgerDirs)
986+
.setBookiePort(bookiePort)
987+
.setMetadataServiceUri(zkUtil.getMetadataServiceUri());
988+
validateConfig(conf);
989+
990+
conf = TestBKConfiguration.newServerConfiguration();
991+
conf.setJournalDirName(journalDir)
992+
.setLedgerDirNames(ledgerDirs)
993+
.setIndexDirName(ledgerDirs)
994+
.setBookiePort(bookiePort)
995+
.setMetadataServiceUri(zkUtil.getMetadataServiceUri());
996+
try {
997+
validateConfig(conf);
998+
} catch (InvalidCookieException ice) {
999+
// error behaviour
1000+
fail("fail to start,error info:");
1001+
ice.printStackTrace();
1002+
}
1003+
}
9731004
}

0 commit comments

Comments
 (0)