Search in sources :

Example 1 with WithParentObjectId

use of org.apache.hadoop.ozone.om.helpers.WithParentObjectId in project ozone by apache.

the class PrefixParser method parse.

public void parse(String vol, String buck, String db, String file) throws Exception {
    if (!Files.exists(Paths.get(db))) {
        System.out.println("DB path not exist:" + db);
        return;
    }
    System.out.println("FilePath is:" + file);
    System.out.println("Db Path is:" + db);
    OzoneConfiguration conf = new OzoneConfiguration();
    conf.set(OMConfigKeys.OZONE_OM_DB_DIRS, db);
    OmMetadataManagerImpl metadataManager = new OmMetadataManagerImpl(conf);
    metadataManager.start(conf);
    org.apache.hadoop.fs.Path effectivePath = new org.apache.hadoop.fs.Path("/");
    Path p = Paths.get(file);
    String volumeKey = metadataManager.getVolumeKey(vol);
    if (!metadataManager.getVolumeTable().isExist(volumeKey)) {
        System.out.println("Invalid Volume:" + vol);
        metadataManager.stop();
        return;
    }
    parserStats[Types.VOLUME.ordinal()]++;
    // First get the info about the bucket
    String bucketKey = metadataManager.getBucketKey(vol, buck);
    OmBucketInfo info = metadataManager.getBucketTable().get(bucketKey);
    if (info == null) {
        System.out.println("Invalid Bucket:" + buck);
        metadataManager.stop();
        return;
    }
    BucketLayout bucketLayout = OzoneManagerUtils.resolveLinkBucketLayout(info, metadataManager, new HashSet<>()).getBucketLayout();
    if (!bucketLayout.isFileSystemOptimized()) {
        System.out.println("Prefix tool only works for FileSystem Optimized" + "bucket. Bucket Layout is:" + bucketLayout);
        metadataManager.stop();
        return;
    }
    long lastObjectId = info.getObjectID();
    WithParentObjectId objectBucketId = new WithParentObjectId();
    objectBucketId.setObjectID(lastObjectId);
    dumpInfo(Types.BUCKET, effectivePath, objectBucketId, bucketKey);
    Iterator<Path> pathIterator = p.iterator();
    while (pathIterator.hasNext()) {
        Path elem = pathIterator.next();
        String path = metadataManager.getOzonePathKey(lastObjectId, elem.toString());
        OmDirectoryInfo directoryInfo = metadataManager.getDirectoryTable().get(path);
        org.apache.hadoop.fs.Path tmpPath = getEffectivePath(effectivePath, elem.toString());
        if (directoryInfo == null) {
            System.out.println("Given path contains a non-existent directory at:" + tmpPath);
            System.out.println("Dumping files and dirs at level:" + tmpPath.getParent());
            System.out.println();
            parserStats[Types.NON_EXISTENT_DIRECTORY.ordinal()]++;
            break;
        }
        effectivePath = tmpPath;
        dumpInfo(Types.INTERMEDIATE_DIRECTORY, effectivePath, directoryInfo, path);
        lastObjectId = directoryInfo.getObjectID();
    }
    // at the last level, now parse both file and dir table
    dumpTableInfo(Types.DIRECTORY, effectivePath, metadataManager.getDirectoryTable(), lastObjectId);
    dumpTableInfo(Types.FILE, effectivePath, metadataManager.getKeyTable(getBucketLayout()), lastObjectId);
    metadataManager.stop();
}
Also used : Path(java.nio.file.Path) OmBucketInfo(org.apache.hadoop.ozone.om.helpers.OmBucketInfo) BucketLayout(org.apache.hadoop.ozone.om.helpers.BucketLayout) OzoneConfiguration(org.apache.hadoop.hdds.conf.OzoneConfiguration) OmMetadataManagerImpl(org.apache.hadoop.ozone.om.OmMetadataManagerImpl) OmDirectoryInfo(org.apache.hadoop.ozone.om.helpers.OmDirectoryInfo) WithParentObjectId(org.apache.hadoop.ozone.om.helpers.WithParentObjectId) HashSet(java.util.HashSet)

Aggregations

Path (java.nio.file.Path)1 HashSet (java.util.HashSet)1 OzoneConfiguration (org.apache.hadoop.hdds.conf.OzoneConfiguration)1 OmMetadataManagerImpl (org.apache.hadoop.ozone.om.OmMetadataManagerImpl)1 BucketLayout (org.apache.hadoop.ozone.om.helpers.BucketLayout)1 OmBucketInfo (org.apache.hadoop.ozone.om.helpers.OmBucketInfo)1 OmDirectoryInfo (org.apache.hadoop.ozone.om.helpers.OmDirectoryInfo)1 WithParentObjectId (org.apache.hadoop.ozone.om.helpers.WithParentObjectId)1