Skip to content

Commit a47c140

Browse files
kuenishiGitHub Enterprise
authored andcommitted
Optimize ACL Check (#15)
1 parent 7f53342 commit a47c140

File tree

1 file changed

+80
-1
lines changed

1 file changed

+80
-1
lines changed

hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/KeyManagerImpl.java

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1801,7 +1801,10 @@ public boolean checkAccess(OzoneObj ozObject, RequestContext context)
18011801
return checkChildrenAcls(ozObject, context);
18021802
}
18031803
try {
1804-
OzoneFileStatus fileStatus = getFileStatus(args);
1804+
// As this is only used from OzoneNativeAuthorizer to check the ACL,
1805+
// it won't need refreshPipeline(). Thus it's using a forked version
1806+
// of getFileStatus(), which is used elsewhere.
1807+
OzoneFileStatus fileStatus = getFileStatus2(args);
18051808
keyInfo = fileStatus.getKeyInfo();
18061809
} catch (IOException e) {
18071810
// OzoneFS will check whether the key exists when write a new key.
@@ -1963,6 +1966,22 @@ public OzoneFileStatus getFileStatus(OmKeyArgs args, String clientAddress)
19631966
args.getLatestVersionLocation(), clientAddress);
19641967
}
19651968

1969+
public OzoneFileStatus getFileStatus2(OmKeyArgs args)
1970+
throws IOException {
1971+
Preconditions.checkNotNull(args, "Key args can not be null");
1972+
String volumeName = args.getVolumeName();
1973+
String bucketName = args.getBucketName();
1974+
String keyName = args.getKeyName();
1975+
1976+
if (isBucketFSOptimized(volumeName, bucketName)) {
1977+
return getOzoneFileStatusFSO(volumeName, bucketName, keyName,
1978+
args.getSortDatanodes(), null,
1979+
args.getLatestVersionLocation(), false);
1980+
}
1981+
return getOzoneFileStatus2(volumeName, bucketName, keyName,
1982+
args.getLatestVersionLocation());
1983+
}
1984+
19661985
private OzoneFileStatus getOzoneFileStatus(String volumeName,
19671986
String bucketName,
19681987
String keyName,
@@ -2027,6 +2046,66 @@ private OzoneFileStatus getOzoneFileStatus(String volumeName,
20272046
FILE_NOT_FOUND);
20282047
}
20292048

2049+
private OzoneFileStatus getOzoneFileStatus2(String volumeName,
2050+
String bucketName,
2051+
String keyName,
2052+
boolean latestLocationVersion)
2053+
throws IOException {
2054+
OmKeyInfo fileKeyInfo = null;
2055+
metadataManager.getLock().acquireReadLock(BUCKET_LOCK, volumeName,
2056+
bucketName);
2057+
try {
2058+
// Check if this is the root of the filesystem.
2059+
if (keyName.length() == 0) {
2060+
OMFileRequest.validateBucket(metadataManager, volumeName, bucketName);
2061+
return new OzoneFileStatus();
2062+
}
2063+
2064+
// Check if the key is a file.
2065+
String fileKeyBytes = metadataManager.getOzoneKey(
2066+
volumeName, bucketName, keyName);
2067+
fileKeyInfo = metadataManager.getKeyTable().get(fileKeyBytes);
2068+
2069+
// Check if the key is a directory.
2070+
if (fileKeyInfo == null) {
2071+
String dirKey = OzoneFSUtils.addTrailingSlashIfNeeded(keyName);
2072+
String dirKeyBytes = metadataManager.getOzoneKey(
2073+
volumeName, bucketName, dirKey);
2074+
OmKeyInfo dirKeyInfo = metadataManager.getKeyTable().get(dirKeyBytes);
2075+
if (dirKeyInfo != null) {
2076+
return new OzoneFileStatus(dirKeyInfo, scmBlockSize, true);
2077+
}
2078+
}
2079+
} finally {
2080+
metadataManager.getLock().releaseReadLock(BUCKET_LOCK, volumeName,
2081+
bucketName);
2082+
2083+
// if the key is a file then do refresh pipeline info in OM by asking SCM
2084+
if (fileKeyInfo != null) {
2085+
if (latestLocationVersion) {
2086+
slimLocationVersion(fileKeyInfo);
2087+
}
2088+
// refreshPipeline flag check has been removed as part of
2089+
// https://issues.apache.org/jira/browse/HDDS-3658.
2090+
// Please refer this jira for more details.
2091+
// refresh(fileKeyInfo);
2092+
// if (sortDatanodes) {
2093+
// sortDatanodes(clientAddress, fileKeyInfo);
2094+
//}
2095+
return new OzoneFileStatus(fileKeyInfo, scmBlockSize, false);
2096+
}
2097+
}
2098+
2099+
// Key is not found, throws exception
2100+
if (LOG.isDebugEnabled()) {
2101+
LOG.debug("Unable to get file status for the key: volume: {}, bucket:" +
2102+
" {}, key: {}, with error: No such file exists.",
2103+
volumeName, bucketName, keyName);
2104+
}
2105+
throw new OMException("Unable to get file status: volume: " +
2106+
volumeName + " bucket: " + bucketName + " key: " + keyName,
2107+
FILE_NOT_FOUND);
2108+
}
20302109

20312110
private OzoneFileStatus getOzoneFileStatusFSO(String volumeName,
20322111
String bucketName, String keyName, boolean sortDatanodes,

0 commit comments

Comments
 (0)