Я использую "namenode" и "datanode" в одном и том же jvm, когда я пытаюсь записать данные, я получаю следующее исключение
org.apache.hadoop.hdfs.server.blockmanagement.BlockPlacementPolicy $ NotEnoughReplicasException:
в org.apache.hadoop.hdfs.server.blockmanagement.BlockPlacementPolicyDefault.chooseRandom (BlockPlacementPolicyDefault.java:836)
в org.apache.hadoop.hdfs.server.blockmanagement.BlockPlacementPolicyDefault.chooseRandom (BlockPlacementPolicyDefault.java:724)
в org.apache.hadoop.hdfs.server.blockmanagement.BlockPlacementPolicyDefault.chooseLocalRack (BlockPlacePolicyDefault.java:631)
в org.apache.hadoop.hdfs.server.blockmanagement.BlockPlacementPolicyDefault.chooseLocalStorage (BlockPlacePolicyDefault.java:591)
в org.apache.hadoop.hdfs.server.blockmanagement.BlockPlacementPolicyDefault.chooseTargetInOrder (BlockPlacementPolicyDefault.java:490)
в org.apache.hadoop.hdfs.server.blockmanagement.BlockPlacementPolicyDefault.chooseTarget (BlockPlacePolicyDefault.java:421)
в org.apache.hadoop.hdfs.server.blockmanagement.BlockPlacementPolicyDefault.chooseTarget (BlockPlacePolicyDefault.java:297)
в org.apache.hadoop.hdfs.server.blockmanagement.BlockPlacementPolicyDefault.chooseTarget (BlockPlacePolicyDefault.java:148)
на org.apache.hadoop.hdfs.server.blockmanagement.BlockPlacementPolicyDefault.chooseTarget (BlockPlacementPolicyDefault.java:164)
в org.apache.hadoop.hdfs.server.blockmanagement.BlockManager.chooseTarget4NewBlock (BlockManager.java:2127)
в org.apache.hadoop.hdfs.server.namenode.FSDirWriteFileOp.chooseTargetForNewBlock (FSDirWriteFileOp.java:294)
в org.apache.hadoop.hdfs.server.namenode.FSNamesystem.getAdditionalBlock (FSNamesystem.java:2771)
в org.apache.hadoop.hdfs.server.namenode.NameNodeRpcServer.addBlock (NameNodeRpcServer.java:876)
в org.apache.hadoop.hdfs.protocolPB.ClientNamenodeProtocolServerSideTranslatorPB.addBlock (ClientNamenodeProtocolServerSideTranslatorPB.java:567)
в org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos $ ClientNamenodeProtocol $ 2.callBlockingMethod (ClientNamenodeProtocolProtos.java)
в org.apache.hadoop.ipc.ProtobufRpcEngine $ Server $ ProtoBufRpcInvoker.call (ProtobufRpcEngine.java:524)
на org.apache.hadoop.ipc.RPC $ Server.call (RPC.java:1025)
в org.apache.hadoop.ipc.Server $ RpcCall.run (Server.java:876)
в org.apache.hadoop.ipc.Server $ RpcCall.run (Server.java:822)
в java.base / java.security.AccessController.doPrivileged (собственный метод)
в java.base / javax.security.auth.Subject.doAs (Subject.java:423)
в org.apache.hadoop.security.UserGroupInformation.doAs (UserGroupInformation.java:1730)
в org.apache.hadoop.ipc.Server $ Handler.run (Server.java:2682)
final File file = new File("C:\\ManageEngine\\test\\data\\namenode");
final File file1 = new File("C:\\ManageEngine\\test\\data\\datanode1");
BasicConfigurator.configure();
final HdfsConfiguration nameNodeConfiguration = new HdfsConfiguration();
FileSystem.setDefaultUri(nameNodeConfiguration, "hdfs://localhost:5555");
nameNodeConfiguration.set(DFSConfigKeys.DFS_NAMENODE_NAME_DIR_KEY, file.toURI().toString());
nameNodeConfiguration.set(DFSConfigKeys.DFS_REPLICATION_KEY, "1" );
final NameNode nameNode = new NameNode(nameNodeConfiguration);
final HdfsConfiguration dataNodeConfiguration1 = new HdfsConfiguration();
dataNodeConfiguration1.set(DFSConfigKeys.DFS_DATANODE_DATA_DIR_KEY, file1.toURI().toString());
dataNodeConfiguration1.set(DFSConfigKeys.DFS_DATANODE_ADDRESS_KEY, "localhost:5556" );
dataNodeConfiguration1.set(DFSConfigKeys.DFS_REPLICATION_KEY, "1" );
FileSystem.setDefaultUri(dataNodeConfiguration1, "hdfs://localhost:5555");
final DataNode dataNode1 = DataNode.instantiateDataNode(new String[]{}, dataNodeConfiguration1);
final FileSystem fs = FileSystem.get(dataNodeConfiguration1);
Path hdfswritepath = new Path(fileName);
if(!fs.exists(hdfswritepath)) {
fs.create(hdfswritepath);
System.out.println("Path "+hdfswritepath+" created.");
}
System.out.println("Begin Write file into hdfs");
FSDataOutputStream outputStream=fs.create(hdfswritepath);
//Cassical output stream usage
outputStream.writeBytes(fileContent);
outputStream.close();
System.out.println("End Write file into hdfs");
Запрос данных - Изображение