HDFS-14372. NPE while DN is shutting down. Contributed by lujie.
This commit is contained in:
parent
e424392a62
commit
69b903bbd8
@ -803,8 +803,12 @@ void register(NamespaceInfo nsInfo) throws IOException {
|
||||
sleepAndLogInterrupts(1000, "connecting to server");
|
||||
}
|
||||
}
|
||||
|
||||
LOG.info("Block pool " + this + " successfully registered with NN");
|
||||
|
||||
if (bpRegistration == null) {
|
||||
throw new IOException("DN shut down before block pool registered");
|
||||
}
|
||||
|
||||
LOG.info(this + " successfully registered with NN");
|
||||
bpos.registrationSucceeded(this, bpRegistration);
|
||||
|
||||
// reset lease id whenever registered to NN.
|
||||
|
@ -26,9 +26,20 @@
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import org.apache.hadoop.conf.Configuration;
|
||||
import org.apache.hadoop.fs.FileSystem;
|
||||
import org.apache.hadoop.hdfs.DFSConfigKeys;
|
||||
import org.apache.hadoop.hdfs.HdfsConfiguration;
|
||||
import org.apache.hadoop.hdfs.protocolPB.DatanodeProtocolClientSideTranslatorPB;
|
||||
import org.apache.hadoop.hdfs.server.common.HdfsServerConstants;
|
||||
import org.apache.hadoop.hdfs.server.common.IncorrectVersionException;
|
||||
@ -118,4 +129,37 @@ public void testDifferentLayoutVersions() throws Exception {
|
||||
fail("Should not fail to retrieve NS info from DN with different layout version");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDNShutdwonBeforeRegister() throws Exception {
|
||||
final InetSocketAddress nnADDR = new InetSocketAddress(
|
||||
"localhost", 5020);
|
||||
Configuration conf = new HdfsConfiguration();
|
||||
conf.set(DFSConfigKeys.DFS_DATANODE_ADDRESS_KEY, "0.0.0.0:0");
|
||||
conf.set(DFSConfigKeys.DFS_DATANODE_HTTP_ADDRESS_KEY, "0.0.0.0:0");
|
||||
conf.set(DFSConfigKeys.DFS_DATANODE_IPC_ADDRESS_KEY, "0.0.0.0:0");
|
||||
FileSystem.setDefaultUri(conf,
|
||||
"hdfs://" + nnADDR.getHostName() + ":" + nnADDR.getPort());
|
||||
ArrayList<StorageLocation> locations = new ArrayList<>();
|
||||
DataNode dn = new DataNode(conf, locations, null, null);
|
||||
BPOfferService bpos = new BPOfferService("test_ns",
|
||||
Lists.newArrayList("nn0"), Lists.newArrayList(nnADDR),
|
||||
Collections.<InetSocketAddress>nCopies(1, null), dn);
|
||||
DatanodeProtocolClientSideTranslatorPB fakeDnProt =
|
||||
mock(DatanodeProtocolClientSideTranslatorPB.class);
|
||||
when(fakeDnProt.versionRequest()).thenReturn(fakeNsInfo);
|
||||
|
||||
BPServiceActor localActor = new BPServiceActor("test", "test",
|
||||
INVALID_ADDR, null, bpos);
|
||||
localActor.setNameNode(fakeDnProt);
|
||||
try {
|
||||
NamespaceInfo nsInfo = localActor.retrieveNamespaceInfo();
|
||||
bpos.setNamespaceInfo(nsInfo);
|
||||
localActor.stop();
|
||||
localActor.register(nsInfo);
|
||||
} catch (IOException e) {
|
||||
Assert.assertEquals("DN shut down before block pool registered",
|
||||
e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user