本文尝试分析某大型大数据解决方案公司企业级hadoop源代码,班门弄斧。
本系列将分三篇文章,对所做的修改进行分析。
修改点1
Index: org/apache/hadoop/hdfs/server/namenode/AclTransformation.java
===================================================================
--- org/apache/hadoop/hdfs/server/namenode/AclTransformation.java (revision 37)
+++ org/apache/hadoop/hdfs/server/namenode/AclTransformation.java (revision 42)
@@ -62,7 +62,7 @@
*/
@InterfaceAudience.Private
final class AclTransformation {
- private static final int MAX_ENTRIES = 32;
+ private static final int MAX_ENTRIES = 64;
分析
其中AclTransformation是acl操作类,MAX_ENTRIES表示所能存储的最大acl条目数。该条修改能够增加存储条目,无法在性能方面有所作为。
1.MAX_ENTRIES相关的源码。
/**
* Builds the final list of ACL entries to return by trimming, sorting and
* validating the ACL entries that have been added.
*
* @param aclBuilder ArrayList<AclEntry> containing entries to build
* @return List<AclEntry> unmodifiable, sorted list of ACL entries
* @throws AclException if validation fails
*/
private static List<AclEntry> buildAndValidateAcl(
ArrayList<AclEntry> aclBuilder) throws AclException {
if (aclBuilder.size() > MAX_ENTRIES) {
throw new AclException("Invalid ACL: ACL has " + aclBuilder.size() +
" entries, which exceeds maximum of " + MAX_ENTRIES + ".");
}
2.AclTransformation类注释及简单翻译
/**
* AclTransformation defines the operations that can modify an ACL. All ACL
* modifications take as input an existing ACL and apply logic to add new
* entries, modify existing entries or remove old entries. Some operations also
* accept an ACL spec: a list of entries that further describes the requested
* change. Different operations interpret the ACL spec differently. In the
* case of adding an ACL to an inode that previously did not have one, the
* existing ACL can be a "minimal ACL" containing exactly 3 entries for owner,
* group and other, all derived from the {@link FsPermission} bits.
*
* The algorithms implemented here require sorted lists of ACL entries. For any
* existing ACL, it is assumed that the entries are sorted. This is because all
* ACL creation and modification is intended to go through these methods, and
* they all guarantee correct sort order in their outputs. However, an ACL spec
* is considered untrusted user input, so all operations pre-sort the ACL spec as
* the first step.
*/
AclTransformation定义了修改acl的操作。所有的acl修改都是通过新增一条acl实现,实现添加,修改,删除。
一些操作也接受acl列表作为参数,不同的操作对acl列表的处理也不一样。当给一个没有进行过授权操作的inode添加acl时,inode包含最小化的acl,即owner,group,other三条acl,这三条acl从FsPermission继承而来。
这里Acl入口列表是有序的。所有已存在的ACL,其入口都是排序的。
这么做是因为所有的acl创建和都要经过这些方法,他们都保证他们的输出是正确排序的。
然而ACL spec被默认为不被信任的用户输入,所有操作都会首先对Acl spec进行预排序。
3.保证排序的代码
/**
* Comparator that enforces required ordering for entries within an ACL:
* -owner entry (unnamed user)
* -all named user entries (internal ordering undefined)
* -owning group entry (unnamed group)
* -all named group entries (internal ordering undefined)
* -mask entry
* -other entry
* All access ACL entries sort ahead of all default ACL entries.
*/
static final Comparator<AclEntry> ACL_ENTRY_COMPARATOR =
new Comparator<AclEntry>() {
@Override
public int compare(AclEntry entry1, AclEntry entry2) {
return ComparisonChain.start()
.compare(entry1.getScope(), entry2.getScope(),
Ordering.explicit(ACCESS, DEFAULT))
.compare(entry1.getType(), entry2.getType(),
Ordering.explicit(USER, GROUP, MASK, OTHER))
.compare(entry1.getName(), entry2.getName(),
Ordering.natural().nullsFirst())
.result();
}
};