【HDFS运维】HDFS回收箱机制:原理、配置、配置可能导致的问题分析

news/2024/5/20 4:03:01 标签: hdfs, 运维, hadoop

文章目录

  • 一. HDFS回收箱机制逻辑
    • 1. 基本逻辑
    • 2. 举例说明
  • 二. 配置测试
    • 1. 配置
    • 2. 回收箱相关命令
  • 三. 其他问题讨论
    • 1. api不会走trash机制
    • 2. 因为设置了Trash configuration导致nn无法响应

一. HDFS回收箱机制逻辑

1. 基本逻辑

If trash configuration is enabled, files removed by FS Shell is not immediately removed from HDFS. Instead, HDFS moves it to a trash directory (each user has its own trash directory under /user//.Trash). The file can be restored quickly as long as it remains in trash.
 
Most recent deleted files are moved to the current trash directory (/user//.Trash/Current), and in a configurable interval, HDFS creates checkpoints (under /user//.Trash/) for files in current trash directory and deletes old checkpoints when they are expired. See expunge command of FS shell about checkpointing of trash.
 
After the expiry of its life in trash, the NameNode deletes the file from the HDFS namespace. The deletion of a file causes the blocks associated with the file to be freed. Note that there could be an appreciable time delay between the time a file is deleted by a user and the time of the corresponding increase in free space in HDFS.

hdfs配置了回收箱后,文件删除后会移动到回收箱目录,每个用户都有自己的回收箱目录:/user/<username>/.Trash。只要文件删除后还在回收箱,就可以随时恢复。

删除的文件被移动到/user/<username>/.Trash/Current目录下。配置时间间隔后,HDFS为当前垃圾目录下的文件创建检查点(在/user//. trash /下),并在过期时删除旧的检查点

当过期时,namenode会从namespace删除此文件。文件删除后会释放与之相关的块。文件删除后,磁盘空间的增加会有延迟。

参考:File Deletes and Undeletes

 

2. 举例说明

This will result in deleted files being move to trash and retained in trash for 4 days (i.e. fs.trash.interval); every 12 hours (i.e. fs.trash.checkpoint.interval) the Trash is scanned and files older than 4 days will be deleted (“expunged”) from Trash.

比如删除文件后,文件将会在回收箱保留4天(通过fs.trash.interval设置),每12小时(通过 fs.trash.checkpoint.interval设置)扫描回收箱,并将过期(超过4天)的文件删除。

 

二. 配置测试

1. 配置

hdfs上面开启trash功能,默认是没有开启的。只需要在hadoop的配置文件core-site.xml中添加下面的内容:

<property>
     <name>fs.trash.interval</name>
     <value>360</value>
     <description>检查点被删除后的分钟数。如果为零,垃圾桶功能将被禁用。
     该选项可以在服务器和客户端上配置。如果垃圾箱被禁用服务器端,则检查客户端配置。
     如果在服务器端启用垃圾箱,则会使用服务器上配置的值,并忽略客户端配置值。
     </description>
</property>
 
<property>
     <name>fs.trash.checkpoint.interval</name>
     <value>0</value>
     <description>垃圾检查点之间的分钟数。应该小于或等于fs.trash.interval。
     如果为零,则将该值设置为fs.trash.interval的值。每次检查指针运行时,
     它都会从当前创建一个新的检查点,并删除比fs.trash.interval更早创建的检查点。
     </description>
</property>

不需要重启,直接执行

2. 回收箱相关命令

# 删除
 bin/hdfs dfs -rm /conf.tar.gz
2023-12-05 14:54:43,989 INFO fs.TrashPolicyDefault: Moved: 'hdfs://xxx/conf.tar.gz' to trash at: hdfs://xmanhdfs3/user/taiyi/.Trash/Current/conf.tar.gz

# 查看回收箱文件
bin/hdfs dfs -ls hdfs://xxx/user/taiyi/.Trash/Current/conf.tar.gz
-rw-r--r--   3 taiyi supergroup       7605 2023-12-05 14:54 hdfs://xxx/user/taiyi/.Trash/Current/conf.tar.gz


# 文件恢复:就是将文件从回收箱中移出
bin/hdfs dfs -mv  hdfs://xxx/user/taiyi/.Trash/Current/conf.tar.gz /

# 清空回收站
bin/hdfs dfs -expunge

# 跳过回收站直接删除
hdfs dfs -rm -r -skipTrash /user/root/123123

 

三. 其他问题讨论

1. api不会走trash机制

但如果直接调用hadoop delete api进行删除操作,是默认不会走trash机制的,同时也未配置快照功能的情况下,文件所对应的block数据已经开始真正从底层文件系统层面进行删除,此时需要快速的做出决断进行恢复操作。

因为需要停止数据服务(nn、dn),所以需要综合考虑,去权衡恢复数据和停服对线上服务的影响两者之间的利害关系。

参考:

恢复数据
如何有效恢复误删的HDFS文件

ing

 

2. 因为设置了Trash configuration导致nn无法响应

Hadoop NameNode becomes un-responsive due to Trash configuration

Resolving The Problem
In order to prevent the NameNode having to perform an extreme amount of file to block map maintenance (which will also impact the DataNode(s)), the settings for fs.trash.interval and fs.trash.checkpoint.interval should be set so that the amount of data to be expunged at a single point of time is within the capability of the environment; a suggestion being under 10GB.

namenode单次删除回收箱的数据不大于10G


http://www.niftyadmin.cn/n/5242711.html

相关文章

python进行文件批量命名

目录 1、传递需要修改文件的上一级目录root_path&#xff0c;step的作用是生成不同的文件&#xff0c;convert_format是转化为特定的格式 2、代码使用 1、传递需要修改文件的上一级目录root_path&#xff0c;step的作用是生成不同的文件&#xff0c;convert_format是转化为特…

蓝桥杯真题:四平方和-Java版

import java.io.*;/*先找后两个数for(int i 0; 2 * i * i < n;i)for(int j i; i * i j * j < n;j ) 再找前两个数 for(int i 0;4 * i * i < n; i )for(int j i;2 * (j * j i * i) < n;j )//这样就可以让后两个数尽量大,前两个数尽量小 这样就可以确定后…

Django回顾 - 6 Ajax

【1】Ajax 定义&#xff1a; 异步Javscript和XML 作用&#xff1a; Javascript语言与服务器(django)进行异步交互&#xff0c;传输的数据为XML&#xff08;当然&#xff0c;传输的数据不只是XML,现在更多使用json数据&#xff09; 同步交互和异步交互&#xff1a; 1、同步交互&…

国内AI翘楚,看看有没有你心动的offer?

科技创新争占高地&#xff0c;AI领域各显神通。从一战成名的阿尔法狗到引起轩然大波的ChatGPT&#xff0c;我们早已卷入了一场没有硝烟的革命。前方世人看到的科技日新日异、岁月静好&#xff0c;后方是各大企业的绞尽脑汁、争先恐后。人工智能时代&#xff0c;AI是挡不住的时代…

Qt创建和使用动态库链接

首先建立库文件 顺序确认完成后&#xff0c;构建完成 注意&#xff1a;上图中mydll_global.h中的内容可以复制到mydll.h中去&#xff0c;在以后调用时只调用mydll.h即可&#xff0c;否则调用时需要两个头文件同事使用。 在mydll.h和mydll.cpp中可以正常编写代码&#xff…

HTML程序大全(2):通用注册模版

一、正常情况效果 二、某项没有填写的效果 三、没有勾选同意项的效果 四、代码 <!DOCTYPE html> <html> <head><meta charset"UTF-8"><title>注册</title><style>body {font-family: Arial, sans-serif;background-color…

k8s官方镜像代理加速

背景 大家可能在云原生领域需要部署周边的一些生态组件时&#xff0c;在国内遇到无法正常拉取镜像&#xff0c;显得就有点苦恼&#xff0c;不过没关系&#xff0c;常见的${{ registry_name }} 例如 “gcr.io”&#xff0c;“registry.k8s.io” Failed to pull image “registry…

python通过ssh密钥等形式链接到redis服务器

当使用 RSA 私钥进行 SSH 认证时&#xff0c;你可以通过 paramiko 的 RSAKey 来加载私钥&#xff0c;并用其创建 SSH 隧道。以下是修改后的代码示例&#xff0c;使用 RSA 私钥进行 SSH 连接&#xff1a; 示例代码 import paramiko from paramiko import RSAKey from sshtunne…