• HDFS回收站


    hdfs会为每一个用户创建一个回收站目录:/usr用户名/.Trash/,每一个用户在Shell命令行删除的文件/目录,会进入到对应的回收站目录中,在回收站中的数据都有一个生命周期,也就是说当回收站中的文件/目录在一段时间之内没有被用户恢复的话,HDFS就会自动将这个文件/目录彻底删除。
    默认情况下hdfs的回收站是不开启的,需要通过配置来开启,位置core-site.xml,配置如下,value的单位是分钟,1440分钟代表的是一天的生命周期

     <property>
             <name>fs.trash.interval</name>
            <value>1440</value>
       </property>
    

    1440代表的是一天。24*60=1440
    修改配置需同步集群中其他节点信息,并重启集群
    重启集群后尝试删除REDADME.txt文件

    [root@bigdata02 hadoop]# hdfs dfs -rm /README.txt
    2021-04-03 10:56:08,152 INFO fs.TrashPolicyDefault: Moved: 'hdfs://bigdata02:9000/README.txt' to trash at: hdfs://bigdata02:9000/user/root/.Trash/Current/README.txt
    [root@bigdata02 hadoop]# hdfs dfs -ls /user/root/.Trash/Current
    Found 2 items
    -rw-r--r--   2 root supergroup       1361 2021-04-03 10:14 /user/root/.Trash/Current/README.txt
    -rw-r--r--   2 root supergroup  345625475 2021-04-03 09:53 /user/root/.Trash/Current/hadoop-3.2.0.tar.gz
    [root@bigdata02 hadoop]# hdfs dfs -rm -r /user/root/.Trash/Current/Current/hadoop-3.2.0.tar.gz
    rm: `/user/root/.Trash/Current/Current/hadoop-3.2.0.tar.gz': No such file or directory
    

    如果文件大,可带-skipTrash参数直接进行删除

    [root@bigdata02 hadoop]# hdfs dfs -rm -r -skipTrash /hadoop-3.2.0.tar.gz
    Deleted /hadoop-3.2.0.tar.gz
    

    HDFS安全模式

    集群刚启动时HDFS会进入安全模式,此时无法执行操作。

    [root@bigdata02 hadoop]# hdfs dfs -rm /README.txt
    2021-04-03 10:55:41,520 WARN fs.TrashPolicyDefault: Can't create trash directory: hdfs://bigdata02:9000/user/root/.Trash/Current
    org.apache.hadoop.hdfs.server.namenode.SafeModeException: Cannot create directory /user/root/.Trash/Current. Name node is in safe mode.
    The reported blocks 4 has reached the threshold 0.9990 of total blocks 4. The number of live datanodes 2 has reached the minimum number 0. In safe mode extension. Safe mode will be turned off automatically in 1 seconds. NamenodeHostName:bigdata02
            at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.newSafemodeException(FSNamesystem.java:1469)
            at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.checkNameNodeSafeMode(FSNamesystem.java:1456)
            at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.mkdirs(FSNamesystem.java:3214)
            at org.apache.hadoop.hdfs.server.namenode.NameNodeRpcServer.mkdirs(NameNodeRpcServer.java:1127)
            at org.apache.hadoop.hdfs.protocolPB.ClientNamenodeProtocolServerSideTranslatorPB.mkdirs(ClientNamenodeProtocolServerSideTranslatorPB.java:713)
            at org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos$ClientNamenodeProtocol$2.callBlockingMethod(ClientNamenodeProtocolProtos.java)
            at org.apache.hadoop.ipc.ProtobufRpcEngine$Server$ProtoBufRpcInvoker.call(ProtobufRpcEngine.java:524)
            at org.apache.hadoop.ipc.RPC$Server.call(RPC.java:1025)
            at org.apache.hadoop.ipc.Server$RpcCall.run(Server.java:876)
            at org.apache.hadoop.ipc.Server$RpcCall.run(Server.java:822)
            at java.security.AccessController.doPrivileged(Native Method)
            at javax.security.auth.Subject.doAs(Subject.java:422)
            at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1730)
            at org.apache.hadoop.ipc.Server$Handler.run(Server.java:2682)
    
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
        at org.apache.hadoop.ipc.RemoteException.instantiateException(RemoteException.java:121)
        at org.apache.hadoop.ipc.RemoteException.unwrapRemoteException(RemoteException.java:88)
        at org.apache.hadoop.hdfs.DFSClient.primitiveMkdir(DFSClient.java:2426)
        at org.apache.hadoop.hdfs.DFSClient.mkdirs(DFSClient.java:2400)
        at org.apache.hadoop.hdfs.DistributedFileSystem$27.doCall(DistributedFileSystem.java:1324)
        at org.apache.hadoop.hdfs.DistributedFileSystem$27.doCall(DistributedFileSystem.java:1321)
        at org.apache.hadoop.fs.FileSystemLinkResolver.resolve(FileSystemLinkResolver.java:81)
        at org.apache.hadoop.hdfs.DistributedFileSystem.mkdirsInternal(DistributedFileSystem.java:1338)
        at org.apache.hadoop.hdfs.DistributedFileSystem.mkdirs(DistributedFileSystem.java:1313)
        at org.apache.hadoop.fs.TrashPolicyDefault.moveToTrash(TrashPolicyDefault.java:153)
        at org.apache.hadoop.fs.Trash.moveToTrash(Trash.java:110)
        at org.apache.hadoop.fs.Trash.moveToAppropriateTrash(Trash.java:96)
        at org.apache.hadoop.fs.shell.Delete$Rm.moveToTrash(Delete.java:153)
        at org.apache.hadoop.fs.shell.Delete$Rm.processPath(Delete.java:118)
        at org.apache.hadoop.fs.shell.Command.processPathInternal(Command.java:367)
        at org.apache.hadoop.fs.shell.Command.processPaths(Command.java:331)
        at org.apache.hadoop.fs.shell.Command.processPathArgument(Command.java:304)
        at org.apache.hadoop.fs.shell.Command.processArgument(Command.java:286)
        at org.apache.hadoop.fs.shell.Command.processArguments(Command.java:270)
        at org.apache.hadoop.fs.shell.FsCommand.processRawArguments(FsCommand.java:120)
        at org.apache.hadoop.fs.shell.Command.run(Command.java:177)
        at org.apache.hadoop.fs.FsShell.run(FsShell.java:327)
        at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:76)
        at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:90)
        at org.apache.hadoop.fs.FsShell.main(FsShell.java:390)
    

    Caused by: org.apache.hadoop.ipc.RemoteException(org.apache.hadoop.hdfs.server.namenode.SafeModeException): Cannot create directory /user/root/.Trash/Current. Name node is in safe mode.
    The reported blocks 4 has reached the threshold 0.9990 of total blocks 4. The number of live datanodes 2 has reached the minimum number 0. In safe mode extension. Safe mode will be turned off automatically in 1 seconds. NamenodeHostName:bigdata02
    at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.newSafemodeException(FSNamesystem.java:1469)
    at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.checkNameNodeSafeMode(FSNamesystem.java:1456)
    at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.mkdirs(FSNamesystem.java:3214)
    at org.apache.hadoop.hdfs.server.namenode.NameNodeRpcServer.mkdirs(NameNodeRpcServer.java:1127)
    at org.apache.hadoop.hdfs.protocolPB.ClientNamenodeProtocolServerSideTranslatorPB.mkdirs(ClientNamenodeProtocolServerSideTranslatorPB.java:713)
    at org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos(ClientNamenodeProtocol)2.callBlockingMethod(ClientNamenodeProtocolProtos.java)
    at org.apache.hadoop.ipc.ProtobufRpcEngine(Server)ProtoBufRpcInvoker.call(ProtobufRpcEngine.java:524)
    at org.apache.hadoop.ipc.RPC(Server.call(RPC.java:1025)
    at org.apache.hadoop.ipc.Server)RpcCall.run(Server.java:876)
    at org.apache.hadoop.ipc.Server(RpcCall.run(Server.java:822)
    at java.security.AccessController.doPrivileged(Native Method)
    at javax.security.auth.Subject.doAs(Subject.java:422)
    at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1730)
    at org.apache.hadoop.ipc.Server)Handler.run(Server.java:2682)

        at org.apache.hadoop.ipc.Client.getRpcResponse(Client.java:1511)
        at org.apache.hadoop.ipc.Client.call(Client.java:1457)
        at org.apache.hadoop.ipc.Client.call(Client.java:1367)
        at org.apache.hadoop.ipc.ProtobufRpcEngine$Invoker.invoke(ProtobufRpcEngine.java:228)
        at org.apache.hadoop.ipc.ProtobufRpcEngine$Invoker.invoke(ProtobufRpcEngine.java:116)
        at com.sun.proxy.$Proxy9.mkdirs(Unknown Source)
        at org.apache.hadoop.hdfs.protocolPB.ClientNamenodeProtocolTranslatorPB.mkdirs(ClientNamenodeProtocolTranslatorPB.java:656)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.apache.hadoop.io.retry.RetryInvocationHandler.invokeMethod(RetryInvocationHandler.java:422)
        at org.apache.hadoop.io.retry.RetryInvocationHandler$Call.invokeMethod(RetryInvocationHandler.java:165)
        at org.apache.hadoop.io.retry.RetryInvocationHandler$Call.invoke(RetryInvocationHandler.java:157)
        at org.apache.hadoop.io.retry.RetryInvocationHandler$Call.invokeOnce(RetryInvocationHandler.java:95)
        at org.apache.hadoop.io.retry.RetryInvocationHandler.invoke(RetryInvocationHandler.java:359)
        at com.sun.proxy.$Proxy10.mkdirs(Unknown Source)
        at org.apache.hadoop.hdfs.DFSClient.primitiveMkdir(DFSClient.java:2424)
        ... 22 more
    

    rm: Failed to move to trash: hdfs://bigdata02:9000/README.txt: Cannot create directory /user/root/.Trash/Current. Name node is in safe mode.
    [root@bigdata02 hadoop]# hdfs dfs -rm /README.txt
    2021-04-03 10:56:08,152 INFO fs.TrashPolicyDefault: Moved: 'hdfs://bigdata02:9000/README.txt' to trash at: hdfs://bigdata02:9000/user/root/.Trash/Current/README.txt

    查看安全模式

    [root@bigdata02 hadoop]# hdfs dfsadmin -safemode get
    Safe mode is OFF
    

    离开安全模式

    [root@bigdata02 hadoop]# hdfs dfsadmin -safemode leave
    Safe mode is OFF
    

  • 相关阅读:
    快慢指针
    成绩排序
    简单排序
    个人作业——软件工程实践总结作业
    团队作业——项目验收与总结博客(麻瓜制造者)
    Beta阶段总结博客(麻瓜制造者)
    “福大易宝”宣传文案
    Beta冲刺(5/5)(麻瓜制造者)
    Beta冲刺(4/5)(麻瓜制造者)
    个人作业——软件工程实践总结作业(待续)
  • 原文地址:https://www.cnblogs.com/shine-rainbow/p/hdfs-hui-shou-zhan.html
Copyright © 2020-2023  润新知