1

我在伪分布式模式下运行 Hadoop 1.2.1,在同一虚拟机上同时拥有 namenode 和 datanode。数据节点有 4 个卷。我正在做一些关于在 Hadoop 中使用非常小的块大小(4k、8k、...)的测试。复制因子设置为 1。

将块大小设置为 8k 时,我可以使用以下命令将 64MB 文件复制到 hdfs:

bin/hadoop fs -put my64mbfile .

虽然在运行命令时我多次收到以下异常:

13/08/29 10:50:47 WARN hdfs.DFSClient: NotReplicatedYetException sleeping 
/user/myuser/my64mbfile retries left 4
13/08/29 10:50:48 INFO hdfs.DFSClient: org.apache.hadoop.ipc.RemoteException: 
org.apache.hadoop.hdfs.server.namenode.NotReplicatedYetException: 
Not replicated yet:/user/myuser/my64mbfile
 at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.getAdditionalBlock
 (FSNamesystem.java:1905)
 at org.apache.hadoop.hdfs.server.namenode.NameNode.addBlock
 (NameNode.java:783)
 at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke
 (DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:606)
 at org.apache.hadoop.ipc.RPC$Server.call(RPC.java:587)
 at org.apache.hadoop.ipc.Server$Handler$1.run(Server.java:1432)
 at org.apache.hadoop.ipc.Server$Handler$1.run(Server.java:1428)
 at java.security.AccessController.doPrivileged(Native Method)
 at javax.security.auth.Subject.doAs(Subject.java:415)
 at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.
 java:1190)
 at org.apache.hadoop.ipc.Server$Handler.run(Server.java:1426)

 at org.apache.hadoop.ipc.Client.call(Client.java:1113)
 at org.apache.hadoop.ipc.RPC$Invoker.invoke(RPC.java:229)
 at com.sun.proxy.$Proxy1.addBlock(Unknown Source)
 at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke
 (DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:606)
 at org.apache.hadoop.io.retry.RetryInvocationHandler.invokeMethod
 (RetryInvocationHandler.
 java:85)
 at org.apache.hadoop.io.retry.RetryInvocationHandler.invoke
 (RetryInvocationHandler.java:62)
 at com.sun.proxy.$Proxy1.addBlock(Unknown Source)
 at org.apache.hadoop.hdfs.DFSClient$DFSOutputStream.locateFollowingBlock
 (DFSClient.java:3720)
 at org.apache.hadoop.hdfs.DFSClient$DFSOutputStream.nextBlockOutputStream
 (DFSClient.java:3580)
 at org.apache.hadoop.hdfs.DFSClient$DFSOutputStream.access$2600
 (DFSClient.java:2783)
 at org.apache.hadoop.hdfs.DFSClient$DFSOutputStream$DataStreamer.run
 (DFSClient.java:3023)

在此之后,我重新格式化并重新启动 hadoop。

当我调用相同的命令,但块大小为 4k 时,我仍然收到上面的警告,最终我收到此错误(仅将大约一半的文件复制到 hdfs 之后):

13/08/29 11:32:38 WARN hdfs.DFSClient: Error Recovery for 
blk_1692157315263473676_1009 bad datanode[0] nodes == null
13/08/29 11:32:38 WARN hdfs.DFSClient: Could not get block locations. Source 
file "/user/myuser/my64mbfile" - Aborting...
put: java.io.IOException: java.lang.OutOfMemoryError: Requested array size 
exceeds VM limit
13/08/29 11:32:38 ERROR hdfs.DFSClient: Failed to close file 
/user/myuser/my64mbfile
org.apache.hadoop.ipc.RemoteException: java.io.IOException: 
java.lang.OutOfMemoryError: Requested array size exceeds VM limit
 at java.util.Arrays.copyOf(Arrays.java:2271)
 at java.io.ByteArrayOutputStream.grow(ByteArrayOutputStream.java:113)
 at java.io.ByteArrayOutputStream.ensureCapacity(ByteArrayOutputStream.java:93)
 at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:140)
 at java.io.DataOutputStream.writeLong(DataOutputStream.java:224)
 at org.apache.hadoop.hdfs.protocol.Block.write(Block.java:134)
 at org.apache.hadoop.io.ArrayWritable.write(ArrayWritable.java:98)
 at org.apache.hadoop.hdfs.server.namenode.FSEditLog$EditLogFileOutputStream.
 write(FSEditLog.java:184)
 at org.apache.hadoop.hdfs.server.namenode.FSEditLog.logEdit(FSEditLog.java:
 1138)
 at org.apache.hadoop.hdfs.server.namenode.FSEditLog.logOpenFile(FSEditLog.
 java:1299)
 at org.apache.hadoop.hdfs.server.namenode.FSDirectory.persistBlocks
 (FSDirectory.java:305)
 at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.getAdditionalBlock
 (FSNamesystem.java:1947)
 at org.apache.hadoop.hdfs.server.namenode.NameNode.addBlock(NameNode.java:783)
 at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke
 (DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:606)
 at org.apache.hadoop.ipc.RPC$Server.call(RPC.java:587)
 at org.apache.hadoop.ipc.Server$Handler$1.run(Server.java:1432)
 at org.apache.hadoop.ipc.Server$Handler$1.run(Server.java:1428)
 at java.security.AccessController.doPrivileged(Native Method)
 at javax.security.auth.Subject.doAs(Subject.java:415)
 at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.
 java:1190)
 at org.apache.hadoop.ipc.Server$Handler.run(Server.java:1426)

 at org.apache.hadoop.ipc.Client.call(Client.java:1113)
 at org.apache.hadoop.ipc.RPC$Invoker.invoke(RPC.java:229)
 at com.sun.proxy.$Proxy1.addBlock(Unknown Source)
 at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessor
 Impl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:606)
 at org.apache.hadoop.io.retry.RetryInvocationHandler.invokeMethod
 (RetryInvocationHandler.java:85)
 at org.apache.hadoop.io.retry.RetryInvocationHandler.invoke
 (RetryInvocationHandler.java:62)
 at com.sun.proxy.$Proxy1.addBlock(Unknown Source)
 at org.apache.hadoop.hdfs.DFSClient$DFSOutputStream.locateFollowingBlock
 (DFSClient.java:3720)
 at org.apache.hadoop.hdfs.DFSClient$DFSOutputStream.nextBlockOutputStream
 (DFSClient.java:3580)
 at org.apache.hadoop.hdfs.DFSClient$DFSOutputStream.access$2600
 (DFSClient.java:2783)
 at org.apache.hadoop.hdfs.DFSClient$DFSOutputStream$DataStreamer.run
 (DFSClient.java:3023)

数据节点可以处理的块数量是否有限制?或者关于对象数量的名称节点是否有另一个限制(除了 dfs.namenode.fs-limits.max-blocks-per-file)?

对于 4k 的情况,块的总数应该是 16384 个块,这意味着每个卷约 4100 个块,这意味着每个卷约 8200 个文件(包括元数据文件)。

4

1 回答 1

1

NameNode 将整个文件到块的映射(BlockMap)保存在内存中,所以如果你配置的块太小,BlockMap 会变得非常大,从而导致 OOME。请参阅hadoop 的 namenode 的内存消耗?

于 2014-02-28T06:10:48.523 回答