HDFS-14977. Quota Usage and Content summary are not same in Truncate with Snapshot. Contributed by hemanthboyina.
This commit is contained in:
parent
1d4d0fcbe1
commit
3afd4cbe89
@ -17,6 +17,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.hadoop.hdfs.server.namenode.snapshot;
|
package org.apache.hadoop.hdfs.server.namenode.snapshot;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.hadoop.classification.InterfaceAudience;
|
import org.apache.hadoop.classification.InterfaceAudience;
|
||||||
@ -154,9 +156,14 @@ public void updateQuotaAndCollectBlocks(INode.ReclaimContext reclaimContext,
|
|||||||
QuotaCounts oldCounts;
|
QuotaCounts oldCounts;
|
||||||
if (removed.snapshotINode != null) {
|
if (removed.snapshotINode != null) {
|
||||||
oldCounts = new QuotaCounts.Builder().build();
|
oldCounts = new QuotaCounts.Builder().build();
|
||||||
BlockInfo[] blocks = file.getBlocks() == null ? new
|
List<BlockInfo> allBlocks = new ArrayList<BlockInfo>();
|
||||||
BlockInfo[0] : file.getBlocks();
|
if (file.getBlocks() != null) {
|
||||||
for (BlockInfo b: blocks) {
|
allBlocks.addAll(Arrays.asList(file.getBlocks()));
|
||||||
|
}
|
||||||
|
if (removed.getBlocks() != null) {
|
||||||
|
allBlocks.addAll(Arrays.asList(removed.getBlocks()));
|
||||||
|
}
|
||||||
|
for (BlockInfo b: allBlocks) {
|
||||||
short replication = b.getReplication();
|
short replication = b.getReplication();
|
||||||
long blockSize = b.isComplete() ? b.getNumBytes() : file
|
long blockSize = b.isComplete() ? b.getNumBytes() : file
|
||||||
.getPreferredBlockSize();
|
.getPreferredBlockSize();
|
||||||
|
@ -1283,4 +1283,40 @@ private void truncateAndRestartDN(Path p, int dn, int newLength)
|
|||||||
cluster.waitActive();
|
cluster.waitActive();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* QuotaUsage in Truncate with Snapshot.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testQuotaOnTruncateWithSnapshot() throws Exception {
|
||||||
|
Path root = new Path("/");
|
||||||
|
Path dirPath = new Path(root, "dir");
|
||||||
|
assertTrue(fs.mkdirs(dirPath));
|
||||||
|
Path filePath = new Path(dirPath, "file");
|
||||||
|
DFSTestUtil.createFile(fs, filePath, 10, (short) 3, 0);
|
||||||
|
|
||||||
|
// verify quotausage and content summary after creating snapshot
|
||||||
|
fs.allowSnapshot(dirPath);
|
||||||
|
fs.createSnapshot(dirPath, "s1");
|
||||||
|
assertEquals(fs.getContentSummary(root).getSpaceConsumed(),
|
||||||
|
fs.getQuotaUsage(root).getSpaceConsumed());
|
||||||
|
|
||||||
|
// truncating the file size to 5bytes
|
||||||
|
boolean blockrecovery = fs.truncate(filePath, 5);
|
||||||
|
if (!blockrecovery) {
|
||||||
|
checkBlockRecovery(filePath, fs, 300, 100L);
|
||||||
|
}
|
||||||
|
|
||||||
|
// verify quotausage and content summary after truncating file which exists
|
||||||
|
// in snapshot
|
||||||
|
assertEquals(fs.getContentSummary(root).getSpaceConsumed(),
|
||||||
|
fs.getQuotaUsage(root).getSpaceConsumed());
|
||||||
|
|
||||||
|
// verify quotausage and content summary after deleting snapshot
|
||||||
|
// now the quota of the file shouldn't present in quotausage and content
|
||||||
|
// summary
|
||||||
|
fs.deleteSnapshot(dirPath, "s1");
|
||||||
|
assertEquals(fs.getContentSummary(root).getSpaceConsumed(),
|
||||||
|
fs.getQuotaUsage(root).getSpaceConsumed());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user