use of org.apache.hadoop.ozone.om.helpers.OmDirectoryInfo in project ozone by apache.
the class TestS3InitiateMultipartUploadRequestWithFSO method verifyDirectoriesInDB.
private long verifyDirectoriesInDB(List<String> dirs, long bucketID) throws IOException {
// bucketID is the parent
long parentID = bucketID;
for (int indx = 0; indx < dirs.size(); indx++) {
String dirName = dirs.get(indx);
String dbKey = "";
// for index=0, parentID is bucketID
dbKey = omMetadataManager.getOzonePathKey(parentID, dirName);
OmDirectoryInfo omDirInfo = omMetadataManager.getDirectoryTable().get(dbKey);
Assert.assertNotNull("Invalid directory!", omDirInfo);
Assert.assertEquals("Invalid directory!", dirName, omDirInfo.getName());
Assert.assertEquals("Invalid dir path!", parentID + "/" + dirName, omDirInfo.getPath());
parentID = omDirInfo.getObjectID();
}
return parentID;
}
use of org.apache.hadoop.ozone.om.helpers.OmDirectoryInfo in project ozone by apache.
the class TestOMFileCreateRequestWithFSO method verifyPathInOpenKeyTable.
@Override
protected OmKeyInfo verifyPathInOpenKeyTable(String key, long id, boolean doAssert) throws Exception {
long bucketId = OMRequestTestUtils.getBucketId(volumeName, bucketName, omMetadataManager);
String[] pathComponents = StringUtils.split(key, '/');
long parentId = bucketId;
for (int indx = 0; indx < pathComponents.length; indx++) {
String pathElement = pathComponents[indx];
// Reached last component, which is file name
if (indx == pathComponents.length - 1) {
String dbOpenFileName = omMetadataManager.getOpenFileName(parentId, pathElement, id);
OmKeyInfo omKeyInfo = omMetadataManager.getOpenKeyTable(getBucketLayout()).get(dbOpenFileName);
if (doAssert) {
Assert.assertNotNull("Invalid key!", omKeyInfo);
}
return omKeyInfo;
} else {
// directory
String dbKey = omMetadataManager.getOzonePathKey(parentId, pathElement);
OmDirectoryInfo dirInfo = omMetadataManager.getDirectoryTable().get(dbKey);
parentId = dirInfo.getObjectID();
}
}
if (doAssert) {
Assert.fail("Invalid key!");
}
return null;
}
use of org.apache.hadoop.ozone.om.helpers.OmDirectoryInfo in project ozone by apache.
the class TestOMFileCreateRequestWithFSO method getDirInfo.
private OmDirectoryInfo getDirInfo(String key) throws Exception {
long bucketId = OMRequestTestUtils.getBucketId(volumeName, bucketName, omMetadataManager);
String[] pathComponents = StringUtils.split(key, '/');
long parentId = bucketId;
OmDirectoryInfo dirInfo = null;
for (int indx = 0; indx < pathComponents.length; indx++) {
String pathElement = pathComponents[indx];
// Reached last component, which is file name
// directory
String dbKey = omMetadataManager.getOzonePathKey(parentId, pathElement);
dirInfo = omMetadataManager.getDirectoryTable().get(dbKey);
parentId = dirInfo.getObjectID();
}
return dirInfo;
}
use of org.apache.hadoop.ozone.om.helpers.OmDirectoryInfo in project ozone by apache.
the class TestOMAllocateBlockRequestWithFSO method verifyPathInOpenKeyTable.
@Override
protected OmKeyInfo verifyPathInOpenKeyTable(String key, long id, boolean doAssert) throws Exception {
long bucketId = OMRequestTestUtils.getBucketId(volumeName, bucketName, omMetadataManager);
String[] pathComponents = StringUtils.split(key, '/');
long parentId = bucketId;
for (int indx = 0; indx < pathComponents.length; indx++) {
String pathElement = pathComponents[indx];
// Reached last component, which is file name
if (indx == pathComponents.length - 1) {
String dbOpenFileName = omMetadataManager.getOpenFileName(parentId, pathElement, id);
OmKeyInfo omKeyInfo = omMetadataManager.getOpenKeyTable(getBucketLayout()).get(dbOpenFileName);
if (doAssert) {
Assert.assertNotNull("Invalid key!", omKeyInfo);
}
return omKeyInfo;
} else {
// directory
String dbKey = omMetadataManager.getOzonePathKey(parentId, pathElement);
OmDirectoryInfo dirInfo = omMetadataManager.getDirectoryTable().get(dbKey);
parentId = dirInfo.getObjectID();
}
}
if (doAssert) {
Assert.fail("Invalid key!");
}
return null;
}
use of org.apache.hadoop.ozone.om.helpers.OmDirectoryInfo in project ozone by apache.
the class OMFileRequest method verifyDirectoryKeysInPath.
/**
* Verify any dir/key exist in the given path in the specified
* volume/bucket by iterating through directory table.
*
* @param omMetadataManager OM Metadata manager
* @param volumeName volume name
* @param bucketName bucket name
* @param keyName key name
* @param keyPath path
* @return OMPathInfoWithFSO path info object
* @throws IOException on DB failure
*/
public static OMPathInfoWithFSO verifyDirectoryKeysInPath(@Nonnull OMMetadataManager omMetadataManager, @Nonnull String volumeName, @Nonnull String bucketName, @Nonnull String keyName, @Nonnull Path keyPath) throws IOException {
String leafNodeName = OzoneFSUtils.getFileName(keyName);
List<String> missing = new ArrayList<>();
// Found no files/ directories in the given path.
OMDirectoryResult result = OMDirectoryResult.NONE;
Iterator<Path> elements = keyPath.iterator();
String bucketKey = omMetadataManager.getBucketKey(volumeName, bucketName);
OmBucketInfo omBucketInfo = omMetadataManager.getBucketTable().get(bucketKey);
// by default, inherit bucket ACLs
List<OzoneAcl> inheritAcls = omBucketInfo.getAcls();
long lastKnownParentId = omBucketInfo.getObjectID();
// absolute path for trace logs
String dbDirName = "";
// for better logging
StringBuilder fullKeyPath = new StringBuilder(bucketKey);
while (elements.hasNext()) {
String fileName = elements.next().toString();
fullKeyPath.append(OzoneConsts.OM_KEY_PREFIX);
fullKeyPath.append(fileName);
if (missing.size() > 0) {
// Assume /vol1/buck1/a/b/c exists, then add d, e, f into missing list.
if (elements.hasNext()) {
// skips leaf node.
missing.add(fileName);
}
continue;
}
// For example, /vol1/buck1/a/b/c/d/e/f/file1.txt
// 1. Do lookup on directoryTable. If not exists goto next step.
// 2. Do look on keyTable. If not exists goto next step.
// 3. Add 'sub-dir' to missing parents list
String dbNodeName = omMetadataManager.getOzonePathKey(lastKnownParentId, fileName);
OmDirectoryInfo omDirInfo = omMetadataManager.getDirectoryTable().get(dbNodeName);
if (omDirInfo != null) {
dbDirName += omDirInfo.getName() + OzoneConsts.OZONE_URI_DELIMITER;
if (elements.hasNext()) {
result = OMDirectoryResult.DIRECTORY_EXISTS_IN_GIVENPATH;
lastKnownParentId = omDirInfo.getObjectID();
inheritAcls = omDirInfo.getAcls();
continue;
} else {
// Checked all the sub-dirs till the leaf node.
// Found a directory in the given path.
result = OMDirectoryResult.DIRECTORY_EXISTS;
}
} else {
// TODO: Need to add UT for this case along with OMFileCreateRequest.
if (omMetadataManager.getKeyTable(BucketLayout.FILE_SYSTEM_OPTIMIZED).isExist(dbNodeName)) {
if (elements.hasNext()) {
// Found a file in the given key name.
result = OMDirectoryResult.FILE_EXISTS_IN_GIVENPATH;
} else {
// Checked all the sub-dirs till the leaf file.
// Found a file with the given key name.
result = OMDirectoryResult.FILE_EXISTS;
}
// Skip directory traversal as it hits key.
break;
}
// Add to missing list, there is no such file/directory with given name.
if (elements.hasNext()) {
missing.add(fileName);
}
}
}
LOG.trace("verifyFiles/Directories in Path : " + "/" + volumeName + "/" + bucketName + "/" + keyName + ":" + result);
if (result == OMDirectoryResult.FILE_EXISTS_IN_GIVENPATH || result == OMDirectoryResult.FILE_EXISTS) {
return new OMPathInfoWithFSO(leafNodeName, lastKnownParentId, missing, result, inheritAcls, fullKeyPath.toString());
}
String dbDirKeyName = omMetadataManager.getOzoneDirKey(volumeName, bucketName, dbDirName);
LOG.trace("Acls inherited from parent " + dbDirKeyName + " are : " + inheritAcls);
return new OMPathInfoWithFSO(leafNodeName, lastKnownParentId, missing, result, inheritAcls);
}
Aggregations