Skip to content

Commit

Permalink
[#181] Provide a filter for check if an inode is under a quota
Browse files Browse the repository at this point in the history
  • Loading branch information
pjeli committed Feb 17, 2019
1 parent 16f48e3 commit ac1aeb2
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 5 deletions.
4 changes: 3 additions & 1 deletion docs/Query_Parameters/Filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@ You can always find the full list of available filters by going to `/filters` RE
23. `isUnderConstruction` - Usable by files. Filters the working INode set by some condition of whether the file is under construction.
24. `isWithSnapshot` - Usable by files and dirs. Filters the working INode set by some condition of whether the file or directory is part of a [Snapshot](https://hadoop.apache.org/docs/stable/hadoop-project-dist/hadoop-hdfs/HdfsSnapshots.html).
25. `hasAcl` - Usable by files and dirs. Filters the working INode set by some condition of whether the file or directory is has a native HDFS ACL.
26. `hasQuota` - Usable by dirs. Filters the working INode set by some condition of whether the directory has either a namespace or disk space quota assigned.
26. `hasQuota` - Usable by dirs. Filters the working INode set by some condition of whether the directory has either a namespace or disk space quota assigned.
27. `isUnderNsQuota` - Usable by files and dirs. Filters the working INode set by checking whether each INode has any parent up to the root that has a namespace quota assigned.
28. `isUnderDsQuota` - Usable by files and dirs. Filters the working INode set by checking whether each INode has any parent up to the root that has a disk space quota assigned.
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,26 @@ public Function<INode, Boolean> getFilterFunctionToBooleanForINode(String filter
return node -> node.asFile().isWithSnapshot();
case "hasAcl":
return node -> (node.getAclFeature() != null);
case "isUnderNsQuota":
return node -> {
for (INodeDirectory p = node.getParent(); p != null; p = node.getParent()) {
node = p;
if (versionLoader.getNsQuota(node) >= 0) {
return true;
}
}
return false;
};
case "isUnderDsQuota":
return node -> {
for (INodeDirectory p = node.getParent(); p != null; p = node.getParent()) {
node = p;
if (versionLoader.getDsQuota(node) >= 0) {
return true;
}
}
return false;
};
default:
return versionLoader.getFilterFunctionToBooleanForINode(filter);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ enum Filter {
isUnderConstruction,
isWithSnapshot,
hasAcl,
hasQuota
hasQuota,
isUnderNsQuota,
isUnderDsQuota
}

EnumSet<Filter> FILTER_LONG =
Expand All @@ -109,7 +111,13 @@ enum Filter {
Filter.name, Filter.path, Filter.user, Filter.group, Filter.modDate, Filter.accessDate);

EnumSet<Filter> FILTER_BOOLEAN =
EnumSet.of(Filter.isUnderConstruction, Filter.isWithSnapshot, Filter.hasAcl, Filter.hasQuota);
EnumSet.of(
Filter.isUnderConstruction,
Filter.isWithSnapshot,
Filter.hasAcl,
Filter.hasQuota,
Filter.isUnderNsQuota,
Filter.isUnderDsQuota);

enum FilterOp {
lt,
Expand Down Expand Up @@ -351,7 +359,9 @@ enum Endpoint {
Filter.accessDate,
Filter.isWithSnapshot,
Filter.hasAcl,
Filter.hasQuota);
Filter.hasQuota,
Filter.isUnderNsQuota,
Filter.isUnderDsQuota);

EnumSet<Filter> FILTER_DIR =
EnumSet.of(
Expand All @@ -373,7 +383,9 @@ enum Endpoint {
Filter.isWithSnapshot,
Filter.hasAcl,
Filter.hasQuota,
Filter.storageType);
Filter.storageType,
Filter.isUnderNsQuota,
Filter.isUnderDsQuota);

EnumSet<Filter> FILTER_ALL = getIntersection(FILTER_FILE, FILTER_DIR);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ public class JavaCollectionQEngine extends AbstractQueryEngine {
attribute("hasAcl", node -> getFilterFunctionToBooleanForINode("hasAcl").apply(node));
private final SimpleAttribute<INode, Boolean> hasQuota =
attribute("hasQuota", node -> getFilterFunctionToBooleanForINode("hasQuota").apply(node));
private final SimpleAttribute<INode, Boolean> isUnderNsQuota =
attribute(
"hasQuota", node -> getFilterFunctionToBooleanForINode("isUnderNsQuota").apply(node));
private final SimpleAttribute<INode, Boolean> isUnderDsQuota =
attribute(
"hasQuota", node -> getFilterFunctionToBooleanForINode("isUnderDsQuota").apply(node));
private SimpleAttribute<INode, Long> dirNumChildren;
private SimpleAttribute<INode, Long> dirSubTreeSize;
private SimpleAttribute<INode, Long> dirSubTreeNumFiles;
Expand Down Expand Up @@ -485,6 +491,10 @@ private Attribute<INode, Boolean> getBooleanAttributeForINode(String filter) {
return hasAcl;
case "hasQuota":
return hasQuota;
case "isUnderNsQuota":
return isUnderNsQuota;
case "isUnderDsQuota":
return isUnderDsQuota;
default:
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,27 @@ public void testAverageFileSizePerDirectory() throws IOException {
assertThat(res.getStatusLine().getStatusCode(), is(200));
}

@Test
public void testHasNsQuotaFilter() throws IOException {
HttpGet get =
new HttpGet(
"http://localhost:4567/filter?set=files&filters=isUnderNsQuota:eq:true&sum=count");
HttpResponse res = client.execute(hostPort, get);
List<String> strings = IOUtils.readLines(res.getEntity().getContent());
strings.clear();
assertThat(res.getStatusLine().getStatusCode(), is(200));
}

@Test
public void testHasDsQuotaFilter() throws IOException {
HttpGet get =
new HttpGet("http://localhost:4567/filter?set=files&filters=isUnderDsQuota:eq:false");
HttpResponse res = client.execute(hostPort, get);
List<String> strings = IOUtils.readLines(res.getEntity().getContent());
strings.clear();
assertThat(res.getStatusLine().getStatusCode(), is(200));
}

@Test
public void testNsQuotaHistogram() throws IOException {
HttpGet get =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,9 @@ protected void addFiles(int numOfFiles, long sleepBetweenMs) throws Exception {
DFSTestUtil.writeFile(fileSystem, filePath, "");
break;
}
if (dirNumber1 == 1) {
fileSystem.setQuota(filePath.getParent(), -1L, 100000000000000L);
}
int user = RANDOM.nextInt(3);
switch (user) {
case 0:
Expand Down

0 comments on commit ac1aeb2

Please sign in to comment.