简体   繁体   English

修复损坏的 HDFS 文件而不丢失数据(数据节点中的文件仍然存在)

[英]Fix corrupt HDFS Files without losing data (files in the datanode still exist)

I am new to the HDFS system and I come across a HDFS question.我是 HDFS 系统的新手,我遇到了 HDFS 问题。

We have a HDFS file system, with the namenode on a server (with this server named as 0002) and datanode on two other servers (with these two severs named as 0004 and 0005 respectively).我们有一个 HDFS 文件系统,namenode 在服务器上(此服务器名为 0002)和 datanode 在另外两个服务器上(这两个服务器分别命名为 0004 和 0005)。 The original data comes from a Flume application and with the "Sink" in the Flume as HDFS.原始数据来自 Flume 应用程序,Flume 中的“Sink”为 HDFS。 The Flume will write the original data (txt files) into the datanode on the servers 0004 and 0005. Flume 会将原始数据(txt 文件)写入服务器 0004 和 0005 上的数据节点中。

So, the original data is replicated twice and saved under two servers.因此,原始数据被复制两次并保存在两台服务器下。 The system work well for some time until one day there is a power outage.系统运行良好一段时间,直到有一天停电。 When restarting the servers, the datanode servers (0004 and 0005) are restarted before the namenode (0002) server.重新启动服务器时,datanode 服务器(0004 和 0005)在 namenode(0002)服务器之前重新启动。 In this case, the original data is still saved onto the 0004 and 0005 server, however the metadata information on the namenode(0002) is lost.在这种情况下,原始数据仍然保存在 0004 和 0005 服务器上,但是 namenode(0002) 上的元数据信息丢失了。 The block information become corrupt.块信息损坏。 The question is how to fix the corrupt blocks without losing the original data?问题是如何在不丢失原始数据的情况下修复损坏的块?

For example, when we check on the namenode例如,当我们检查名称节点时

hadoop fsck /wimp/contract-snapshot/year=2020/month=6/day=10/snapshottime=1055/contract-snapshot.1591779548475.csv -files -blocks -locations

We find the filename on the datanode, but the block is corrupt.我们在数据节点上找到了文件名,但该块已损坏。 The corresponding file name is:对应的文件名是:

blk_1090579409_16840906

在此处输入图像描述

When we go to the datanode (eg 0004) server, we can search the location of this file by当我们 go 到datanode(例如0004)服务器时,我们可以通过以下方式搜索该文件的位置

find ./ -name "*blk_1090579409*"

We have found the the file corresponding to the csv file under the virtual path of the HDFS system "/wimp/contract-snapshot/year=2020/month=6/day=10/snapshottime=1055/contract-snapshot.1591779548475.csv".我们在HDFS系统虚拟路径下找到了csv文件对应的文件“/wimp/contract-snapshot/year=2020/month=6/day=10/snapshottime=1055/contract-snapshot.159871 ”。 The file is saved under folder: "./subdir0/subdir235/" and we can open it and find it is in the correct format.该文件保存在文件夹:“./subdir0/subdir235/”下,我们可以打开它,发现它的格式正确。 The corresponding.meta data is in binary form(?) and we can not read directly.对应的.meta 数据是二进制形式(?),我们无法直接读取。

./subdir0/subdir235/blk_1090579409

The question is, given that we have found the original file (blk_1090579409), how could we restore the corrupt HDFS system using and without losing these correct original files?问题是,既然我们已经找到了原始文件(blk_1090579409),我们如何才能在不丢失这些正确原始文件的情况下恢复损坏的 HDFS 系统?

在此处输入图像描述

After some research, I find a solution, which may be not efficient but works.经过一番研究,我找到了一个可能效率不高但有效的解决方案。 If someone comes with a better solution, please let me know.如果有人提出更好的解决方案,请告诉我。

The whole idea is to copy all the files from the HDFS, arrange these files by year/day/hour/minute into different folders and then update these folders onto HDFS.整个想法是从 HDFS 复制所有文件,将这些文件按年/日/小时/分钟排列到不同的文件夹中,然后将这些文件夹更新到 HDFS。

I have two datanodes (0004 and 0005) where data is stored.我有两个存储数据的数据节点(0004 和 0005)。 The total data size is of the magnitude of 10+ terabytes.总数据大小为 10+ TB。 The folder structure is as following (it is the same as in the question, one displayed on linux and the other on Windows):文件夹结构如下(同题,linux显示一个,Windows显示一个):

在此处输入图像描述

The replication factor is set as 2, which means (if no mistake happens) that each datanode will have one and only one copy of the original file.复制因子设置为 2,这意味着(如果没有错误发生)每个数据节点将只有一个原始文件的副本。 Therefore, we just scan the folders/files on one datanode (on server 0004, about 5+ terabytes).因此,我们只扫描一个数据节点上的文件夹/文件(在服务器 0004 上,大约 5+ TB)。 Based on the modification date and the timestep in each file, copy the files into a new folder on a backup server/driver.根据每个文件中的修改日期和时间步长,将文件复制到备份服务器/驱动程序上的新文件夹中。 Luckily, in the original files, time step information is available, eg 2020-03-02T09:25 .幸运的是,在原始文件中,时间步长信息可用,例如2020-03-02T09:25 I round the time to the nearest five minutes, and parent folder is for each day, with the newly created folder structure as:我将时间四舍五入到最接近的五分钟,父文件夹是每天的,新创建的文件夹结构为: 在此处输入图像描述

The code of scan and copy the files from the datanode into the new folders by each five minutes are written in Pyspark and it takes about 2 days (I leave the code to run in the evening) to run all the operation. Pyspark 中写入了每五分钟从datanode 扫描并复制文件到新文件夹的代码,运行所有操作大约需要2 天(我让代码在晚上运行)。

Then I can update the folders on HDFS for each day.然后我可以每天更新 HDFS 上的文件夹。 On HDFS, the folder structure is as follows:在HDFS上,文件夹结构如下: 在此处输入图像描述

The created folder is with the same structure as on the HDFS, also the naming convention is the same (in the copy step, I rename each copied files to match the convention on HDFS).创建的文件夹与 HDFS 上的结构相同,命名约定也相同(在复制步骤中,我重命名每个复制的文件以匹配 HDFS 上的约定)。

In the final step, I write JAVA code in order to do operations to the HDFS.在最后一步中,我编写了 JAVA 代码,以便对 HDFS 进行操作。 After some testing, I am able to update the data of each day on HDFS.经过一些测试,我能够更新HDFS上每天的数据。 Ie It will delete eg the data under the folder ~/year=2019/month=1/day=2/ on HDFS and then upload all the folders/files under the newly created folder ~/20190102/ up to ~/year=2019/month=1/day=2/ on HDFS.即它将删除例如HDFS上文件夹~/year=2019/month=1/day=2/下的数据,然后上传新创建的文件夹~/20190102/下的所有文件夹/文件到~/year=2019/month=1/day=2/在 HDFS 上。 I do such operation for each day.我每天都做这样的手术。 Then the corrupt blocks disappear, and the right files are uploaded to the correct path on HDFS.然后损坏的块消失,正确的文件上传到 HDFS 上的正确路径。

According to my research, it is also possible to find the corrupt blocks before the power outage by using the fsimage file on Hadoop, but this means that I may corrupt the blocks on HDFS after the power outage.根据我的研究,通过使用Hadoop上的fsimage文件也可以在停电前找到损坏的块,但这意味着我可能会在停电后损坏HDFS上的块。 Therefore, I decide using the described approach to delete the corrupt blocks while still keeping the original files and update them on HDFS.因此,我决定使用所描述的方法来删除损坏的块,同时仍然保留原始文件并在 HDFS 上更新它们。

If anyone has a better or more efficient solution, please share!如果有人有更好或更有效的解决方案,请分享!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM