HDFS-8593. Calculation of effective layout version mishandles comparison to current layout version in storage. Contributed by Chris Nauroth.

This commit is contained in:
cnauroth 2015-06-13 10:37:52 -07:00
parent eef7b50e23
commit b8341f1cd8
3 changed files with 35 additions and 5 deletions

View File

@ -886,6 +886,9 @@ Release 2.8.0 - UNRELEASED
HDFS-8554. TestDatanodeLayoutUpgrade fails on Windows. (cnauroth) HDFS-8554. TestDatanodeLayoutUpgrade fails on Windows. (cnauroth)
HDFS-8593. Calculation of effective layout version mishandles comparison to
current layout version in storage. (cnauroth)
Release 2.7.1 - UNRELEASED Release 2.7.1 - UNRELEASED
INCOMPATIBLE CHANGES INCOMPATIBLE CHANGES

View File

@ -7004,10 +7004,17 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
* @return layout version in effect * @return layout version in effect
*/ */
public int getEffectiveLayoutVersion() { public int getEffectiveLayoutVersion() {
if (isRollingUpgrade()) { return getEffectiveLayoutVersion(isRollingUpgrade(),
int storageLV = fsImage.getStorage().getLayoutVersion(); fsImage.getStorage().getLayoutVersion(),
if (storageLV >= NameNodeLayoutVersion.MINIMUM_COMPATIBLE_LAYOUT_VERSION,
NameNodeLayoutVersion.MINIMUM_COMPATIBLE_LAYOUT_VERSION) { NameNodeLayoutVersion.CURRENT_LAYOUT_VERSION);
}
@VisibleForTesting
static int getEffectiveLayoutVersion(boolean isRollingUpgrade, int storageLV,
int minCompatLV, int currentLV) {
if (isRollingUpgrade) {
if (storageLV <= minCompatLV) {
// The prior layout version satisfies the minimum compatible layout // The prior layout version satisfies the minimum compatible layout
// version of the current software. Keep reporting the prior layout // version of the current software. Keep reporting the prior layout
// as the effective one. Downgrade is possible. // as the effective one. Downgrade is possible.
@ -7016,7 +7023,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
} }
// The current software cannot satisfy the layout version of the prior // The current software cannot satisfy the layout version of the prior
// software. Proceed with using the current layout version. // software. Proceed with using the current layout version.
return NameNodeLayoutVersion.CURRENT_LAYOUT_VERSION; return currentLV;
} }
/** /**

View File

@ -213,4 +213,24 @@ public class TestFSNamesystem {
fsn.imageLoadComplete(); fsn.imageLoadComplete();
assertTrue(fsn.isImageLoaded()); assertTrue(fsn.isImageLoaded());
} }
@Test
public void testGetEffectiveLayoutVersion() {
assertEquals(-63,
FSNamesystem.getEffectiveLayoutVersion(true, -60, -61, -63));
assertEquals(-61,
FSNamesystem.getEffectiveLayoutVersion(true, -61, -61, -63));
assertEquals(-62,
FSNamesystem.getEffectiveLayoutVersion(true, -62, -61, -63));
assertEquals(-63,
FSNamesystem.getEffectiveLayoutVersion(true, -63, -61, -63));
assertEquals(-63,
FSNamesystem.getEffectiveLayoutVersion(false, -60, -61, -63));
assertEquals(-63,
FSNamesystem.getEffectiveLayoutVersion(false, -61, -61, -63));
assertEquals(-63,
FSNamesystem.getEffectiveLayoutVersion(false, -62, -61, -63));
assertEquals(-63,
FSNamesystem.getEffectiveLayoutVersion(false, -63, -61, -63));
}
} }