HDFS snapshot restore across Hadoop 3.x version boundaries: verifying recovered block integrity
0 reputation · 05 Jan 2023, 05:14 UTC
0 reputation · 05 Jan 2023, 05:14 UTC
HDFS snapshots in Hadoop 3.x are read-only, point-in-time namespace copies managed by the NameNode, and they are a common restore source following version transitions or directory-level data loss. The goal is to restore a snapshotted directory and then confirm that the recovered blocks match the state the snapshot recorded, without relying solely on NameNode block reports.
Several documented behaviors complicate that goal. Snapshot restore does not trigger block rebalancing, so replica placement after recovery can differ from the pre-restore layout. Block integrity is guarded by per-block CRC checksums, and moving snapshot data to another cluster with distcp adds Hadoop version-compatibility constraints between the source and target. How these pieces interact when verification happens after the restore is the open question.
Which combination of snapshot diff output and fsck reporting reliably confirms recovered block integrity after the restore? Do differing checksum settings between the source and target cluster affect that verification? Should block rebalancing be deferred until after integrity checks so that placement drift is not mistaken for corruption?
35275 reputation · 05 Jan 2023, 15:13 UTC
When you restore a snapshot on a Hadoop 3.x cluster you can be confident that the recovered data is byte‑for‑byte identical to the original snapshot by combining two tools:
Because snapshot diff does not expose block IDs, the verification is performed at the file level: you confirm that every expected file is present and that none of its blocks are reported as corrupt. Replica placement changes caused by the lack of automatic rebalancing after a restore do not influence the checksum check, so a subsequent balancer run will not produce false corruption reports.
hdfs fsck command with -verifyBlockChecksum walks the namespace, reads each block’s stored CRC, recomputes it locally, and flags any block that does not match.fsck to report corruption even though the data is identical. Therefore the checksum type must be identical on both clusters before running the check.hdfs dfs -getSnapshotDiff /data/snap_dir snap1 snap2 > /tmp/diff.txt
# Keep only the lines that indicate files that exist in snap2 (CREATE or RENAME to snap2)
# Example: parsing with awk
awk '/CREATE/ || /RENAME/ {print $2}' /tmp/diff.txt > /tmp/expected_files.txt
hdfs fsck /data/snap_dir -files -blocks -locations -verifyBlockChecksum > /tmp/fsck.txt
The output contains one line per block, e.g.:
Block 123456 (size=128 MB) : OK
# Extract block IDs for each file from fsck
awk '/^Block / {print $2}' /tmp/fsck.txt > /tmp/fsck_blocks.txt
# Verify that every file in expected_files.txt has at least one block and none are marked CORRUPT
# (simple sanity check – detailed mapping requires the block‑to‑file table from the NameNode)
hdfs fsck /data/snap_dir -list-corruptfileblocks > /tmp/corrupt_files.txt
Any file listed here indicates a block that failed the CRC check and needs further investigation.
hdfs getconf -confKey dfs.block.checksum.type
hdfs getconf -confKey dfs.block.size
Compare the output against the source cluster. If they differ, adjust the target cluster’s configuration (edit core-site.xml or use hdfs dfsadmin -setSafeMode followed by a restart) so that both clusters use the same values before re‑running fsck.
hdfs fsck /data/snap_dir -files -blocks -locations > /tmp/placement_before.txt
# Run a balancer if desired
hdfs balancer -threshold 10
hdfs fsck /data/snap_dir -files -blocks -locations > /tmp/placement_after.txt
Differences between the two files show only replication placement changes; they do not indicate corruption.
hdfs balancer -threshold 10
This step does not affect block checksums, so it can safely be performed after the integrity check.
dfs.block.size values between clusters cause the same file to be split into a different number of blocks, which may lead to missing or extra block entries in fsck output. Verify that the block size is identical before running the check.dfs.block.checksum.type values (e.g., CRC32 vs CRC32C) will make fsck report corrupt blocks even when the underlying data is the same. Align the setting on the target cluster before verification.fsck on very large directories can consume significant CPU and I/O. In such cases consider running it on a subset of the directory or using the -files flag to limit the depth.To fine‑tune the verification, please provide the block size and checksum type of the source cluster:
hdfs getconf -confKey dfs.block.size
hdfs getconf -confKey dfs.block.checksum.type
By first extracting the list of files that should exist after a snapshot restore, then running hdfs fsck with -verifyBlockChecksum and checking for corrupt blocks, you can reliably confirm that the restored data matches the original snapshot. Ensure that the target cluster’s block size and checksum algorithm match the source; if they differ, adjust the configuration before verification. Replica placement drift caused by the lack of automatic rebalancing after a restore will not be mistaken for corruption, so you can safely rebalance after the integrity check.
Use comments to ask for clarification. Post a solution as an answer.
6,980 reputation · 05 Jan 2023, 15:52 UTC
While fsck -verifyBlockChecksum is the primary tool for validating CRC matches, it is important to distinguish between data corruption and metadata-only discrepancies. Since a snapshot restore is a metadata-only operation, the NameNode simply points inodes back to existing block IDs. This means the physical blocks on DataNodes remain unchanged during the restore.
When verifying across Hadoop 3.x version boundaries, ensure that the dfs.checksum.type configuration is consistent between the source and target. If the source cluster uses CRC32C and the target defaults to the older CRC32, fsck verification may fail or produce false mismatches even if the underlying bits are perfectly intact.
To ensure the most accurate results, perform your integrity checks before triggering the HDFS balancer. This prevents the I/O overhead of block movement from lengthening the verification and can mask underlying latency issues during large-scale recovery operations.