HDFS文件误删怎么办,一招教你恢复回来,再也不用担心删库跑路了_hdfs表被删了,怎么看操作记录

先自我介绍一下,小编浙江大学毕业,去过华为、字节跳动等大厂,目前阿里P7

深知大多数程序员,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年最新Python全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友。
img
img



既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上Python知识点,真正体系化!

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新

如果你需要这些资料,可以添加V获取:vip1024c (备注Python)
img

正文

final Map<String, Double> slowPeersMap = slowPeers.getSlowPeers();
if (!slowPeersMap.isEmpty()) {
if (LOG.isDebugEnabled()) {
LOG.debug("DataNode " + nodeReg + " reported slow peers: " +
slowPeersMap);
}
for (String slowNodeId : slowPeersMap.keySet()) {
slowPeerTracker.addReport(slowNodeId, nodeReg.getIpcAddr(false));
}
}
}

if (slowDiskTracker != null) {
if (!slowDisks.getSlowDisks().isEmpty()) {
if (LOG.isDebugEnabled()) {
LOG.debug("DataNode " + nodeReg + " reported slow disks: " +
slowDisks.getSlowDisks());
}
slowDiskTracker.addSlowDiskReport(nodeReg.getIpcAddr(false), slowDisks);
}
}

if (!cmds.isEmpty()) {
return cmds.toArray(new DatanodeCommand[cmds.size()]);
}

return new DatanodeCommand[0];
}

定时轮循+limit 1000个块删除的特性决定了hdfs删除数据并不会立即真正的执行物理删除,并且一次删除的数量也有限,所以出现误删操作需要立即停止HDFS,虽然有的数据在轮循中已被删除,所以事发后停止HDFS集群越早,被删的数据越少,损失越小!

EditLog

EditLog记录了hdfs操作的每一条日志记录,包括当然包括删除,我们所熟知的文件操作类型只有增、删、改,但是在 HDFS 的领域里,远远不止这些操作,我们看看 EditLog 操作类型的枚举类org.apache.hadoop.hdfs.server.namenode.FSEditLogOpCodes

/**

  • Licensed to the Apache Software Foundation (ASF) under one
  • or more contributor license agreements. See the NOTICE file
  • distributed with this work for additional information
  • regarding copyright ownership. The ASF licenses this file
  • to you under the Apache License, Version 2.0 (the
  • “License”); you may not use this file except in compliance
  • with the License. You may obtain a copy of the License at
  • http://www.apache.org/licenses/LICENSE-2.0
    
  • Unless required by applicable law or agreed to in writing, software
  • distributed under the License is distributed on an “AS IS” BASIS,
  • WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  • See the License for the specific language governing permissions and
  • limitations under the License.
    */
    package org.apache.hadoop.hdfs.server.namenode;

import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.classification.InterfaceStability;
import org.apache.hadoop.hdfs.server.namenode.FSEditLogOp.*;

/**

  • Op codes for edits file
    */
    @InterfaceAudience.Private
    @InterfaceStability.Unstable
    public enum FSEditLogOpCodes {
    // last op code in file
    OP_ADD ((byte) 0, AddOp.class),
    // deprecated operation
    OP_RENAME_OLD ((byte) 1, RenameOldOp.class),
    OP_DELETE ((byte) 2, DeleteOp.class),
    OP_MKDIR ((byte) 3, MkdirOp.class),
    OP_SET_REPLICATION ((byte) 4, SetReplicationOp.class),
    @Deprecated OP_DATANODE_ADD ((byte) 5), // obsolete
    @Deprecated OP_DATANODE_REMOVE((byte) 6), // obsolete
    OP_SET_PERMISSIONS ((byte) 7, SetPermissionsOp.class),
    OP_SET_OWNER ((byte) 8, SetOwnerOp.class),
    OP_CLOSE ((byte) 9, CloseOp.class),
    OP_SET_GENSTAMP_V1 ((byte) 10, SetGenstampV1Op.class),
    OP_SET_NS_QUOTA ((byte) 11, SetNSQuotaOp.class), // obsolete
    OP_CLEAR_NS_QUOTA ((byte) 12, ClearNSQuotaOp.class), // obsolete
    OP_TIMES ((byte) 13, TimesOp.class), // set atime, mtime
    OP_SET_QUOTA ((byte) 14, SetQuotaOp.class),
    // filecontext rename
    OP_RENAME ((byte) 15, RenameOp.class),
    // concat files
    OP_CONCAT_DELETE ((byte) 16, ConcatDeleteOp.class),
    OP_SYMLINK ((byte) 17, SymlinkOp.class),
    OP_GET_DELEGATION_TOKEN ((byte) 18, GetDelegationTokenOp.class),
    OP_RENEW_DELEGATION_TOKEN ((byte) 19, RenewDelegationTokenOp.class),
    OP_CANCEL_DELEGATION_TOKEN ((byte) 20, CancelDelegationTokenOp.class),
    OP_UPDATE_MASTER_KEY ((byte) 21, UpdateMasterKeyOp.class),
    OP_REASSIGN_LEASE ((byte) 22, ReassignLeaseOp.class),
    OP_END_LOG_SEGMENT ((byte) 23, EndLogSegmentOp.class),
    OP_START_LOG_SEGMENT ((byte) 24, StartLogSegmentOp.class),
    OP_UPDATE_BLOCKS ((byte) 25, UpdateBlocksOp.class),
    OP_CREATE_SNAPSHOT ((byte) 26, CreateSnapshotOp.class),
    OP_DELETE_SNAPSHOT ((byte) 27, DeleteSnapshotOp.class),
    OP_RENAME_SNAPSHOT ((byte) 28, RenameSnapshotOp.class),
    OP_ALLOW_SNAPSHOT ((byte) 29, AllowSnapshotOp.class),
    OP_DISALLOW_SNAPSHOT ((byte) 30, DisallowSnapshotOp.class),
    OP_SET_GENSTAMP_V2 ((byte) 31, SetGenstampV2Op.class),
    OP_ALLOCATE_BLOCK_ID ((byte) 32, AllocateBlockIdOp.class),
    OP_ADD_BLOCK ((byte) 33, AddBlockOp.class),
    OP_ADD_CACHE_DIRECTIVE ((byte) 34, AddCacheDirectiveInfoOp.class),
    OP_REMOVE_CACHE_DIRECTIVE ((byte) 35, RemoveCacheDirectiveInfoOp.class),
    OP_ADD_CACHE_POOL ((byte) 36, AddCachePoolOp.class),
    OP_MODIFY_CACHE_POOL ((byte) 37, ModifyCachePoolOp.class),
    OP_REMOVE_CACHE_POOL ((byte) 38, RemoveCachePoolOp.class),
    OP_MODIFY_CACHE_DIRECTIVE ((byte) 39, ModifyCacheDirectiveInfoOp.class),
    OP_SET_ACL ((byte) 40, SetAclOp.class),
    OP_ROLLING_UPGRADE_START ((byte) 41, RollingUpgradeStartOp.class),
    OP_ROLLING_UPGRADE_FINALIZE ((byte) 42, RollingUpgradeFinalizeOp.class),
    OP_SET_XATTR ((byte) 43, SetXAttrOp.class),
    OP_REMOVE_XATTR ((byte) 44, RemoveXAttrOp.class),
    OP_SET_STORAGE_POLICY ((byte) 45, SetStoragePolicyOp.class),
    OP_TRUNCATE ((byte) 46, TruncateOp.class),
    OP_APPEND ((byte) 47, AppendOp.class),
    OP_SET_QUOTA_BY_STORAGETYPE ((byte) 48, SetQuotaByStorageTypeOp.class),
    OP_ADD_ERASURE_CODING_POLICY ((byte) 49, AddErasureCodingPolicyOp.class),
    OP_ENABLE_ERASURE_CODING_POLICY((byte) 50, EnableErasureCodingPolicyOp.class),
    OP_DISABLE_ERASURE_CODING_POLICY((byte) 51,
    DisableErasureCodingPolicyOp.class),
    OP_REMOVE_ERASURE_CODING_POLICY((byte) 52, RemoveErasureCodingPolicyOp.class),

// Note that the current range of the valid OP code is 0~127
OP_INVALID ((byte) -1);

private final byte opCode;
private final Class<? extends FSEditLogOp> opClass;

/**

  • Constructor
  • @param opCode byte value of constructed enum
    */
    FSEditLogOpCodes(byte opCode) {
    this(opCode, null);
    }

FSEditLogOpCodes(byte opCode, Class<? extends FSEditLogOp> opClass) {
this.opCode = opCode;
this.opClass = opClass;
}

/**

  • return the byte value of the enum
  • @return the byte value of the enum
    */
    public byte getOpCode() {
    return opCode;
    }

public Class<? extends FSEditLogOp> getOpClass() {
return opClass;
}

private static final FSEditLogOpCodes[] VALUES;

static {
byte max = 0;
for (FSEditLogOpCodes code : FSEditLogOpCodes.values()) {
if (code.getOpCode() > max) {
max = code.getOpCode();
}
}
VALUES = new FSEditLogOpCodes[max + 1];
for (FSEditLogOpCodes code : FSEditLogOpCodes.values()) {
if (code.getOpCode() >= 0) {
VALUES[code.getOpCode()] = code;
}
}
}

/**

  • Converts byte to FSEditLogOpCodes enum value
  • @param opCode get enum for this opCode
  • @return enum with byte value of opCode
    */
    public static FSEditLogOpCodes fromByte(byte opCode) {
    if (opCode >= 0 && opCode < VALUES.length) {
    return VALUES[opCode];
    }
    return opCode == -1 ? OP_INVALID : null;
    }
    }

总计54种操作类型!打破了人们印象中文件只有增删改读的几种操作。在hadoop的配置参数**dfs.namenode.name.dir**可以找到路径

这里EditLog文件是序列化后的二进制文件不能直接查看,hdfs自带了解析的命令,可以解析成xml明文格式

hdfs oev -i edits_0000000000035854978-0000000000035906741 -o edits.xml

对 hdfs 的每一个操作都会记录一串 RECORD,RECORD 里面不同的操作包含的字段属性也不同,但是所有操作都具备的属性是 OPCODE,对应上面的枚举类**org.apache.hadoop.hdfs.server.namenode.FSEditLogOpCodes**中的操作

hdfs元数据的加载

hdfs 启动时,NameNode 会加载 Fsimage,Fsimage 记录了 hdfs 现有的全量的路径信息,启动过程中仅仅加载 Fsimage?这句话不完全正确!启动的同时,还会加载未被合并成 fsimage 的EditLog。关于 fsimage 具体细节这里不展开。举个栗子:

假设Hadoop 3分钟checkpoint一次生成Fsimage文件,EditLog 1分钟生成一个文件,下面是依次生成的文件:

fsimage_1
editlog_1
editlog_2
editlog_3
fsimage_2
editlog_4
editlog_5

当NameNode启动时,会加载后缀时间戳最大的那个fsimage文件和它后面产生的editlog文件,也就是会加载fsimage_2、editlog_4、editlog_5进NameNode内存。

恢复方法

假设我们执行 hdfs dfs -rmr xxx 命令的操作记录在了 editlog_5 上面,那么,重启 NameNode 后,我们查看hdfs无法再查看到xxx路径,如果我们把fsimage_2删掉,NameNode则会加载fsimage_1、editlog_1、editlog_2,此时的元数据里面xxx还未被删除,如果此时DataNode未物理删除block,则数据可以恢复,但是editlog_4、editlog_5对应的hdfs操作会丢失。有没有更好的方法呢?

方案一:

删掉 fsimage_2,从上一次 checkpoint 的地方也就是 fsimage_1 恢复,我们集群的实际配置,是一个小时生成一次 fsimage 文件,也就是说,这种恢复方案会导致近一小时 hdfs 新增的文件全部丢失,这一个小时不知道发生了多少事情,可想而知的后果是恢复之后一堆报错,显然不是最好的方案

方案二:

修改editlog_5,把删除xxx那条操作改成其它安全的操作类型,这样重启NameNode后,又可以看到这个路径。

步骤:

  • 关闭HDFS集群
  • 解析editlog

找到删除操作时间点范围内所属的editlog文件,解析

hdfs oev -i edits_0000000000000000336-0000000000000000414 -o edits.xml

查看editlog.xml,执行删除操作的日志已经记录在里面了

  • 替换删除操作

把OP_DELETE操作替换成比较安全的操作,例如

OP_DELETE 374 0 /hbase/oldWALs/test%2C16020%2C1630456996531.1630464212306 1630724840046 d1e2ae59-ba0c-4385-87d4-4da3d9ec019b 1049

注意:只能改变OPCODE,其他不能修改!!!

  • 反解析成editlog

反解析更改后的xml文件成editlog

hdfs oev -i editlog.xml -o edits_0000000000000000336-0000000000000000414.tmp -p binary

重命名掉之前的editlog

mv edits_0000000000000000336-0000000000000000414 edits_0000000000000000336-0000000000000000414.bak

替换反解析后的editlog

mv edits_0000000000000000336-0000000000000000414.tmp edits_0000000000000000336-0000000000000000414

一、Python所有方向的学习路线

Python所有方向的技术点做的整理,形成各个领域的知识点汇总,它的用处就在于,你可以按照下面的知识点去找对应的学习资源,保证自己学得较为全面。

img
img

二、Python必备开发工具

工具都帮大家整理好了,安装就可直接上手!img

三、最新Python学习笔记

当我学到一定基础,有自己的理解能力的时候,会去阅读一些前辈整理的书籍或者手写的笔记资料,这些笔记详细记载了他们对一些技术点的理解,这些理解是比较独到,可以学到不一样的思路。

img

四、Python视频合集

观看全面零基础学习视频,看视频学习是最快捷也是最有效果的方式,跟着视频中老师的思路,从基础到深入,还是很容易入门的。

img

五、实战案例

纸上得来终觉浅,要学会跟着视频一起敲,要动手实操,才能将自己的所学运用到实际当中去,这时候可以搞点实战案例来学习。img

六、面试宝典

在这里插入图片描述

在这里插入图片描述

简历模板在这里插入图片描述

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化的资料的朋友,可以添加V获取:vip1024c (备注python)
img

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

d39.png)

简历模板在这里插入图片描述

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化的资料的朋友,可以添加V获取:vip1024c (备注python)
[外链图片转存中…(img-gYg2AgRc-1713669448211)]

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

  • 24
    点赞
  • 27
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值