HDFS-10499. TestNameNodeMetadataConsistency#testGenerationStampInFuture Fails Intermittently. Contributed by Yiqun Lin.
This commit is contained in:
parent
5b577f43a2
commit
808f5d8985
@ -27,6 +27,9 @@
|
|||||||
import org.apache.hadoop.hdfs.protocol.ExtendedBlock;
|
import org.apache.hadoop.hdfs.protocol.ExtendedBlock;
|
||||||
import org.apache.hadoop.hdfs.server.blockmanagement.BlockInfo;
|
import org.apache.hadoop.hdfs.server.blockmanagement.BlockInfo;
|
||||||
import org.apache.hadoop.hdfs.server.blockmanagement.BlockManagerTestUtil;
|
import org.apache.hadoop.hdfs.server.blockmanagement.BlockManagerTestUtil;
|
||||||
|
import org.apache.hadoop.test.GenericTestUtils;
|
||||||
|
|
||||||
|
import com.google.common.base.Supplier;
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@ -34,7 +37,6 @@
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
@ -73,8 +75,7 @@ public void cleanup() {
|
|||||||
* safe mode while it is in startup mode.
|
* safe mode while it is in startup mode.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGenerationStampInFuture() throws
|
public void testGenerationStampInFuture() throws Exception {
|
||||||
IOException, InterruptedException {
|
|
||||||
cluster.waitActive();
|
cluster.waitActive();
|
||||||
|
|
||||||
FileSystem fs = cluster.getFileSystem();
|
FileSystem fs = cluster.getFileSystem();
|
||||||
@ -105,9 +106,7 @@ public void testGenerationStampInFuture() throws
|
|||||||
cluster.getNameNode().getNamesystem().getBlockManager());
|
cluster.getNameNode().getNamesystem().getBlockManager());
|
||||||
|
|
||||||
cluster.restartDataNode(dnProps);
|
cluster.restartDataNode(dnProps);
|
||||||
waitTil(TimeUnit.SECONDS.toMillis(SCAN_WAIT));
|
waitForNumBytes(TEST_DATA_IN_FUTURE.length());
|
||||||
cluster.triggerBlockReports();
|
|
||||||
waitTil(TimeUnit.SECONDS.toMillis(SCAN_WAIT));
|
|
||||||
|
|
||||||
// Make sure that we find all written bytes in future block
|
// Make sure that we find all written bytes in future block
|
||||||
assertEquals(TEST_DATA_IN_FUTURE.length(),
|
assertEquals(TEST_DATA_IN_FUTURE.length(),
|
||||||
@ -122,9 +121,7 @@ public void testGenerationStampInFuture() throws
|
|||||||
* hence we should not have positive count of Blocks in future.
|
* hence we should not have positive count of Blocks in future.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testEnsureGenStampsIsStartupOnly() throws
|
public void testEnsureGenStampsIsStartupOnly() throws Exception {
|
||||||
IOException, InterruptedException {
|
|
||||||
|
|
||||||
String testData = " This is test data";
|
String testData = " This is test data";
|
||||||
cluster.restartDataNodes();
|
cluster.restartDataNodes();
|
||||||
cluster.restartNameNodes();
|
cluster.restartNameNodes();
|
||||||
@ -153,21 +150,31 @@ public void testEnsureGenStampsIsStartupOnly() throws
|
|||||||
cluster.getNameNode().getNamesystem().writeUnlock();
|
cluster.getNameNode().getNamesystem().writeUnlock();
|
||||||
|
|
||||||
cluster.restartDataNode(dnProps);
|
cluster.restartDataNode(dnProps);
|
||||||
waitTil(TimeUnit.SECONDS.toMillis(SCAN_WAIT));
|
waitForNumBytes(0);
|
||||||
cluster.triggerBlockReports();
|
|
||||||
waitTil(TimeUnit.SECONDS.toMillis(SCAN_WAIT));
|
|
||||||
|
|
||||||
|
|
||||||
// Make sure that there are no bytes in future since isInStartupSafe
|
// Make sure that there are no bytes in future since isInStartupSafe
|
||||||
// mode is not true.
|
// mode is not true.
|
||||||
assertEquals(0, cluster.getNameNode().getBytesWithFutureGenerationStamps());
|
assertEquals(0, cluster.getNameNode().getBytesWithFutureGenerationStamps());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void waitTil(long waitPeriod) {
|
private void waitForNumBytes(final int numBytes) throws Exception {
|
||||||
|
GenericTestUtils.waitFor(new Supplier<Boolean>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean get() {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(waitPeriod);
|
cluster.triggerBlockReports();
|
||||||
} catch (InterruptedException e) {
|
// Compare the number of bytes
|
||||||
e.printStackTrace();
|
if (cluster.getNameNode().getBytesWithFutureGenerationStamps()
|
||||||
|
== numBytes) {
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
// Ignore the exception
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}, SCAN_WAIT * 1000, 60000);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user