Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
7796d21
HDDS-8739. Snapdiff should return complete absolute path in Diff Entry
swamirishi Jun 2, 2023
b5f2f77
Merge remote-tracking branch 'apache/master' into HEAD
swamirishi Jun 14, 2023
4c53136
HDDS-8739. Fix Diff entry representation
swamirishi Jun 14, 2023
eddb5a1
HDDS-8739. Fix compilation issues
swamirishi Jun 14, 2023
87792cc
HDDS-8739. Fix bug
swamirishi Jun 14, 2023
971321f
HDDS-8739. fix bug to resolve abs path
swamirishi Jun 14, 2023
0feae64
HDDS-8739. Fix testcases
swamirishi Jun 16, 2023
007d6f6
Merge remote-tracking branch 'apache/master' into HEAD
swamirishi Jun 16, 2023
7756571
HDDS-8739. Fix testcases
swamirishi Jun 16, 2023
ccea92b
HDDS-8739. Fix checkstyle
swamirishi Jun 17, 2023
6297ed5
HDDS-8739. Address review comments
swamirishi Jun 19, 2023
c3ec1a7
HDDS-8739: Fix failures
swamirishi Jun 19, 2023
3f6510f
HDDS-8739: Fix failures
swamirishi Jun 19, 2023
ebfb66b
HDDS-8739: Fix failures
swamirishi Jun 20, 2023
227f6c1
HDDS-8739: Fix failures
swamirishi Jun 20, 2023
981cb79
HDDS-8739: Address review comments
swamirishi Jun 20, 2023
3bc5467
HDDS-8739: Fix failures
swamirishi Jun 20, 2023
9d35447
HDDS-8739: Address review comments
swamirishi Jun 21, 2023
258a36c
Merge remote-tracking branch 'apache/master' into HEAD
swamirishi Jun 21, 2023
d318ec2
HDDS-8739: Address review comments
swamirishi Jun 21, 2023
f48d2a1
HDDS-8739: Address review comments
swamirishi Jun 21, 2023
c69987e
HDDS-8739: Fix checkstyle
swamirishi Jun 21, 2023
f5b299a
Merge remote-tracking branch 'apache/master' into HEAD
swamirishi Jun 22, 2023
d224462
HDDS-8739: Resolve merge conflicts
swamirishi Jun 22, 2023
d03890d
HDDS-8739: Resolve test failure
swamirishi Jun 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.hadoop.ozone.om.snapshot;

import org.apache.hadoop.hdds.utils.db.Table;
import org.apache.hadoop.hdds.utils.db.TableIterator;
import org.apache.hadoop.ozone.om.helpers.OmDirectoryInfo;

import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.Queue;
import java.util.Set;

import static org.apache.hadoop.ozone.OzoneConsts.OM_KEY_PREFIX;

public class FSODirectoryPathResolver implements ObjectPathResolver {

private String prefix;
private long bucketId;
private Table<String, OmDirectoryInfo> dirInfoTable;

public FSODirectoryPathResolver(String prefix, long bucketId,
Table<String, OmDirectoryInfo> dirInfoTable) {
this.prefix = prefix;
this.dirInfoTable = dirInfoTable;
this.bucketId = bucketId;
}

private void addToPathMap(ObjectIDPathVal objectIDPathVal,
Set<Long> dirObjIds, Map<Long, Path> pathMap) {
if (dirObjIds.contains(objectIDPathVal.getObjectId())) {
pathMap.put(objectIDPathVal.getObjectId(), objectIDPathVal.getPath());
dirObjIds.remove(objectIDPathVal.getObjectId());
}
}

/**
* Assuming all dirObjIds belong to a bucket this function resolves absolute
* path for a given FSO bucket.
* @param dirObjIds
* @return Map of Path corresponding to provided directory object IDs
*/
@Override
public Map<Long, Path> getAbsolutePathForObjectIDs(Set<Long> dirObjIds)
throws IOException {
// Root of a bucket would always have the key as /volumeId/bucketId/bucketId/
if (dirObjIds.isEmpty()) {
return Collections.emptyMap();
}

Map<Long, Path> pathMap = new HashMap<>();
Queue<ObjectIDPathVal> objectIdPathVals = new LinkedList<>();
ObjectIDPathVal root = new ObjectIDPathVal(bucketId, Paths.get("/"));
objectIdPathVals.add(root);
addToPathMap(root, dirObjIds, pathMap);

while (!objectIdPathVals.isEmpty() && dirObjIds.size() > 0) {
ObjectIDPathVal parent = objectIdPathVals.poll();
try(TableIterator<String, ? extends Table.KeyValue<String, OmDirectoryInfo>>
subDirIter = dirInfoTable.iterator(
prefix + parent.getObjectId())) {
while (dirObjIds.size() > 0 && subDirIter.hasNext()) {
OmDirectoryInfo dir = subDirIter.next().getValue();
ObjectIDPathVal pathVal = new ObjectIDPathVal(dir.getObjectID(),
parent.getPath().resolve(dir.getName()));
addToPathMap(pathVal, dirObjIds, pathMap);
}
}
}

if (dirObjIds.size() > 0) {
throw new IllegalArgumentException(
"Dir object Ids required but not found in bucket: " + dirObjIds);
}
return pathMap;
}

private static class ObjectIDPathVal {
private long objectId;
private Path path;

public ObjectIDPathVal(long objectId, Path path) {
this.objectId = objectId;
this.path = path;
}

public long getObjectId() {
return objectId;
}

public Path getPath() {
return path;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.apache.hadoop.ozone.om.snapshot;

import java.io.IOException;
import java.nio.file.Path;
import java.util.Map;
import java.util.Set;

public interface ObjectPathResolver {

public Map<Long, Path> getAbsolutePathForObjectIDs(Set<Long> objIds)
throws IOException;
}
Loading