在类org.apache.hadoop.hdfs.server.namenode.NNStorageRetentionManager的purgeOldStorage()方法中描述了fsimage和edit logs的处理逻辑:
一、找到存在于fsimage中的最小txid,删除比最小txid小的fsimage
二、最小txid - dfs.namenode.num.extra.edits.retained = 可以删除txid集合
三、可删除txid集合 > dfs.namenode.max.extra.edits.segments.retained 时,删除集合中的最小值
完整代码:
public void purgeOldStorage() throws IOException {
FSImageTransactionalStorageInspector inspector =
new FSImageTransactionalStorageInspector();
storage.inspectStorageDirs(inspector);
long minImageTxId = getImageTxIdToRetain(inspector);
purgeCheckpointsOlderThan(inspector, minImageTxId);
// If fsimage_N is the image we want to keep, then we need to keep
// all txns > N. We can remove anything < N+1, since fsimage_N
// reflects the state up to and including N. However, we also
// provide a "cushi