[ https://issues.apache.org/jira/browse/HDFS-7056?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14254471#comment-14254471 ]
Jing Zhao commented on HDFS-7056: --------------------------------- maybe something like the following? I wrote it in a hurry, so the code may not be in a good shape. but the general idea is to directly process on the diff list instead of keeping calling {{getPrior}} and {{getDiffById}}. {code} public BlockInfo[] findBlocksAfter(INodeFile currentINode, int snapshot) { if (snapshot == Snapshot.CURRENT_STATE_ID) { return currentINode.getBlocks(); } else { List<FileDiff> diffs = this.asList(); int i = Collections.binarySearch(diffs, snapshot); i = i >= 0 ? i : -i - 1; for (; i < diffs.size(); i++) { final FileDiff diff = diffs.get(i); if (diff.getBlocks() != null) { return diff.getBlocks(); } } return currentINode.getBlocks(); } } {code} > Snapshot support for truncate > ----------------------------- > > Key: HDFS-7056 > URL: https://issues.apache.org/jira/browse/HDFS-7056 > Project: Hadoop HDFS > Issue Type: Sub-task > Components: namenode > Affects Versions: 3.0.0 > Reporter: Konstantin Shvachko > Assignee: Plamen Jeliazkov > Attachments: HDFS-3107-HDFS-7056-combined.patch, > HDFS-3107-HDFS-7056-combined.patch, HDFS-3107-HDFS-7056-combined.patch, > HDFS-3107-HDFS-7056-combined.patch, HDFS-3107-HDFS-7056-combined.patch, > HDFS-3107-HDFS-7056-combined.patch, HDFS-3107-HDFS-7056-combined.patch, > HDFS-3107-HDFS-7056-combined.patch, HDFS-3107-HDFS-7056-combined.patch, > HDFS-7056.patch, HDFS-7056.patch, HDFS-7056.patch, HDFS-7056.patch, > HDFS-7056.patch, HDFS-7056.patch, HDFS-7056.patch, HDFS-7056.patch, > HDFSSnapshotWithTruncateDesign.docx > > > Implementation of truncate in HDFS-3107 does not allow truncating files which > are in a snapshot. It is desirable to be able to truncate and still keep the > old file state of the file in the snapshot. -- This message was sent by Atlassian JIRA (v6.3.4#6332)