hdfs dfsadmin -rollingUpgrade解读

本文深入探讨HDFS中namenode的滚动升级过程,包括关键步骤rollingUpgradePrepare与rollingUpgradeFinalize的具体实现。详细解释了checkpoint签名生成、transaction ID记录及版本文件更新等重要环节的作用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >



hdfs dfsadmin -rollingUpgrade prepare 源码中是

CheckpointSignature rollEditLog() throws IOException {
  getEditLog().rollEditLog();
  // Record this log segment ID in all of the storage directories, so
  // we won't miss this log segment on a restart if the edits directories
  // go missing.
  storage.writeTransactionIdFileToStorage(getEditLog().getCurSegmentTxId());
  return new CheckpointSignature(this);



void writeTransactionIdFile(StorageDirectory sd, long txid) throws IOException {
  Preconditions.checkArgument(txid >= 0"bad txid: " + txid);
 
  File txIdFile = getStorageFile(sdNameNodeFile.SEEN_TXID);
  PersistentLongFile.writeFile(txIdFiletxid);
}
SEEN_TXID ("seen_txid"),
$dfs.namenode.name.dir/current/seen_txid非常重要,是存放transactionId的文件,format之后是0,它代表的是namenode里面的edits_*文件的尾数,namenode重启的时候,会按照seen_txid的数字,循序从头跑edits_0000001~到seen_txid的数字。所以当你的hdfs发生异常重启的时候,一定要比对seen_txid内的数字是不是你edits最后的尾数,不然会发生建置namenode时metaData的资料有缺少,导致误删Datanode上多余Block的资讯




hdfs dfsadmin -rollingUpgrade finalize, 源码是

getFSImage().updateStorageVersion();
getFSImage().renameCheckpoint(NameNodeFile.IMAGE_ROLLBACK,
    NameNodeFile.IMAGE);
protected static final String STORAGE_FILE_VERSION    = "VERSION";

namenode下的VERISON文件
public File getVersionFile() {
  return new File(new File(rootSTORAGE_DIR_CURRENT)STORAGE_FILE_VERSION);
}

public void writeProperties(StorageDirectory sd) throws IOException {
  writeProperties(sd.getVersionFile()sd);
}

public void writeProperties(File toStorageDirectory sd) throws IOException {
  Properties props = new Properties();
  setPropertiesFromFields(propssd);
  writeProperties(tosdprops);
}

public static void writeProperties(File toStorageDirectory sd,
    Properties props) throws IOException {
  RandomAccessFile file = new RandomAccessFile(to"rws");

内容写到VERSION文件中
file.setLength(out.getChannel().position());
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值