Skip to content

Commit

Permalink
HDFS-14519. NameQuota is not update after concat operation, so namequ…
Browse files Browse the repository at this point in the history
…ota is wrong. Contributed by Ranith Sardar.
  • Loading branch information
ayushtkn committed Nov 22, 2019
1 parent 4c1a128 commit 049940e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
Expand Up @@ -214,6 +214,7 @@ private static QuotaCounts computeQuotaDeltas(FSDirectory fsd,
}
}
}
deltas.addNameSpace(-srcList.length);
return deltas;
}

Expand Down
Expand Up @@ -34,6 +34,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.ContentSummary;
import org.apache.hadoop.fs.DirectoryListingStartAfterNotFoundException;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileStatus;
Expand All @@ -45,6 +46,7 @@
import org.apache.hadoop.fs.Options.Rename;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.PathIsNotDirectoryException;
import org.apache.hadoop.fs.QuotaUsage;
import org.apache.hadoop.fs.RemoteIterator;
import org.apache.hadoop.fs.XAttr;
import org.apache.hadoop.fs.permission.FsAction;
Expand Down Expand Up @@ -1232,4 +1234,35 @@ public void testClearBlocks() {
toBeCleared.clearBlocks();
assertTrue(toBeCleared.getBlocks().length == 0);
}
}

@Test
public void testConcat() throws IOException {
Configuration conf = new Configuration();
try (MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).build()) {
cluster.waitActive();
DistributedFileSystem dfs = cluster.getFileSystem();
String dir = "/testConcat";
dfs.mkdirs(new Path(dir), FsPermission.getDirDefault());
dfs.setQuota(new Path(dir), 100L, HdfsConstants.QUOTA_DONT_SET);

// Create 4 files
Path trg = new Path(dir + "/file");
DFSTestUtil.createFile(dfs, trg, 512, (short) 1, 0);
Path[] srcs = new Path[4];
for (int i = 0; i < 4; i++) {
srcs[i] = new Path(dir + "/file" + i);
DFSTestUtil.createFile(dfs, srcs[i], 512, (short) 1, 0);
}

// Concat file1, file2, file3 to file0
dfs.concat(trg, srcs);

// Check the file and directory count and consumed space
ContentSummary cs = dfs.getContentSummary(new Path(dir));
QuotaUsage qu = dfs.getQuotaUsage(new Path(dir));

Assert.assertEquals(cs.getFileCount() + cs.getDirectoryCount(),
qu.getFileAndDirectoryCount());
}
}
}

0 comments on commit 049940e

Please sign in to comment.