-
Notifications
You must be signed in to change notification settings - Fork 587
HDDS-8739. Snapdiff should return complete absolute path in Diff Entry #4823
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 14 commits
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 b5f2f77
Merge remote-tracking branch 'apache/master' into HEAD
swamirishi 4c53136
HDDS-8739. Fix Diff entry representation
swamirishi eddb5a1
HDDS-8739. Fix compilation issues
swamirishi 87792cc
HDDS-8739. Fix bug
swamirishi 971321f
HDDS-8739. fix bug to resolve abs path
swamirishi 0feae64
HDDS-8739. Fix testcases
swamirishi 007d6f6
Merge remote-tracking branch 'apache/master' into HEAD
swamirishi 7756571
HDDS-8739. Fix testcases
swamirishi ccea92b
HDDS-8739. Fix checkstyle
swamirishi 6297ed5
HDDS-8739. Address review comments
swamirishi c3ec1a7
HDDS-8739: Fix failures
swamirishi 3f6510f
HDDS-8739: Fix failures
swamirishi ebfb66b
HDDS-8739: Fix failures
swamirishi 227f6c1
HDDS-8739: Fix failures
swamirishi 981cb79
HDDS-8739: Address review comments
swamirishi 3bc5467
HDDS-8739: Fix failures
swamirishi 9d35447
HDDS-8739: Address review comments
swamirishi 258a36c
Merge remote-tracking branch 'apache/master' into HEAD
swamirishi d318ec2
HDDS-8739: Address review comments
swamirishi f48d2a1
HDDS-8739: Address review comments
swamirishi c69987e
HDDS-8739: Fix checkstyle
swamirishi f5b299a
Merge remote-tracking branch 'apache/master' into HEAD
swamirishi d224462
HDDS-8739: Resolve merge conflicts
swamirishi d03890d
HDDS-8739: Resolve test failure
swamirishi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,12 +24,15 @@ | |
| import org.apache.hadoop.hdds.utils.db.Codec; | ||
| import org.apache.hadoop.hdds.utils.db.DelegatedCodec; | ||
| import org.apache.hadoop.hdds.utils.db.Proto2Codec; | ||
| import org.apache.hadoop.hdfs.DFSUtilClient; | ||
| import org.apache.hadoop.hdfs.protocol.SnapshotDiffReport; | ||
| import org.apache.hadoop.ozone.OFSPath; | ||
| import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos; | ||
| import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.DiffReportEntryProto; | ||
| import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.SnapshotDiffReportProto; | ||
|
|
||
| import java.nio.charset.StandardCharsets; | ||
| import java.nio.file.Paths; | ||
| import java.util.List; | ||
| import java.util.stream.Collectors; | ||
|
|
||
|
|
@@ -163,7 +166,7 @@ public static DiffReportEntry fromProtobufDiffReportEntry( | |
| return null; | ||
| } | ||
| DiffType type = fromProtobufDiffType(entry.getDiffType()); | ||
| return type == null ? null : new DiffReportEntry(type, | ||
| return type == null ? null : new DiffReportEntryOzone(type, | ||
| entry.getSourcePath().getBytes(StandardCharsets.UTF_8), | ||
| entry.hasTargetPath() ? | ||
| entry.getTargetPath().getBytes(StandardCharsets.UTF_8) : null); | ||
|
|
@@ -191,7 +194,7 @@ public static DiffReportEntry getDiffReportEntry(final DiffType type, | |
|
|
||
| public static DiffReportEntry getDiffReportEntry(final DiffType type, | ||
| final String sourcePath, final String targetPath) { | ||
| return new DiffReportEntry(type, | ||
| return new DiffReportEntryOzone(type, | ||
| sourcePath.getBytes(StandardCharsets.UTF_8), | ||
| targetPath != null ? targetPath.getBytes(StandardCharsets.UTF_8) : | ||
| null); | ||
|
|
@@ -206,5 +209,46 @@ public void aggregate(SnapshotDiffReportOzone diffReport) { | |
| this.getDiffList().addAll(diffReport.getDiffList()); | ||
| } | ||
|
|
||
| /** | ||
| * DiffReportEntry for ozone. | ||
| */ | ||
| public static class DiffReportEntryOzone extends DiffReportEntry { | ||
|
|
||
| public DiffReportEntryOzone(DiffType type, byte[] sourcePath) { | ||
| super(type, sourcePath); | ||
| } | ||
|
|
||
| public DiffReportEntryOzone(DiffType type, byte[][] sourcePathComponents) { | ||
| super(type, sourcePathComponents); | ||
| } | ||
|
|
||
| public DiffReportEntryOzone(DiffType type, byte[] sourcePath, | ||
| byte[] targetPath) { | ||
| super(type, sourcePath, targetPath); | ||
| } | ||
|
|
||
| public DiffReportEntryOzone(DiffType type, byte[][] sourcePathComponents, | ||
| byte[][] targetPathComponents) { | ||
| super(type, sourcePathComponents, targetPathComponents); | ||
| } | ||
|
|
||
| static String getPathString(byte[] path) { | ||
| String pathStr = DFSUtilClient.bytes2String(path); | ||
| return pathStr.isEmpty() ? "." : Paths.get(pathStr) | ||
| .toAbsolutePath().toString(); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| String str = this.getType().getLabel() + "\t" + | ||
| getPathString(this.getSourcePath()); | ||
| if (this.getType() == SnapshotDiffReport.DiffType.RENAME) { | ||
| str = str + " -> " + getPathString(this.getTargetPath()); | ||
| } | ||
|
|
||
| return str; | ||
| } | ||
| } | ||
|
|
||
|
||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -29,6 +29,7 @@ | |||||||||||||||
| import org.apache.hadoop.hdds.utils.db.DBProfile; | ||||||||||||||||
| import org.apache.hadoop.hdds.utils.db.RDBStore; | ||||||||||||||||
| import org.apache.hadoop.hdds.utils.db.managed.ManagedRocksObjectUtils; | ||||||||||||||||
| import org.apache.hadoop.hdfs.protocol.SnapshotDiffReport; | ||||||||||||||||
| import org.apache.hadoop.hdfs.protocol.SnapshotDiffReport.DiffReportEntry; | ||||||||||||||||
| import org.apache.hadoop.ozone.MiniOzoneCluster; | ||||||||||||||||
| import org.apache.hadoop.ozone.TestDataUtil; | ||||||||||||||||
|
|
@@ -131,7 +132,7 @@ public class TestOmSnapshot { | |||||||||||||||
| private static AtomicInteger counter; | ||||||||||||||||
|
|
||||||||||||||||
| @Rule | ||||||||||||||||
| public Timeout timeout = new Timeout(180, TimeUnit.SECONDS); | ||||||||||||||||
| public Timeout timeout = new Timeout(180, TimeUnit.HOURS); | ||||||||||||||||
swamirishi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||
|
|
||||||||||||||||
| @Parameterized.Parameters | ||||||||||||||||
| public static Collection<Object[]> data() { | ||||||||||||||||
|
|
@@ -208,7 +209,7 @@ private void init() throws Exception { | |||||||||||||||
|
|
||||||||||||||||
| // stop the deletion services so that keys can still be read | ||||||||||||||||
| keyManager.stop(); | ||||||||||||||||
| preFinalizationChecks(); | ||||||||||||||||
| // preFinalizationChecks(); | ||||||||||||||||
swamirishi marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||
| finalizeOMUpgrade(); | ||||||||||||||||
| counter = new AtomicInteger(); | ||||||||||||||||
| } | ||||||||||||||||
|
|
@@ -591,12 +592,11 @@ public void testSnapDiff() throws Exception { | |||||||||||||||
| SnapshotDiffReportOzone | ||||||||||||||||
| diff2 = getSnapDiffReport(volume, bucket, snap2, snap3); | ||||||||||||||||
| Assert.assertEquals(2, diff2.getDiffList().size()); | ||||||||||||||||
| Assert.assertTrue(diff2.getDiffList().contains( | ||||||||||||||||
| SnapshotDiffReportOzone.getDiffReportEntry( | ||||||||||||||||
| SnapshotDiffReportOzone.DiffType.CREATE, key2))); | ||||||||||||||||
| Assert.assertTrue(diff2.getDiffList().contains( | ||||||||||||||||
| SnapshotDiffReportOzone.getDiffReportEntry( | ||||||||||||||||
| SnapshotDiffReportOzone.DiffType.DELETE, key1))); | ||||||||||||||||
| Assert.assertEquals(diff2.getDiffList(), | ||||||||||||||||
|
||||||||||||||||
| Assert.assertEquals(diff2.getDiffList(), | |
| Assert.assertEquals( | |
| Arrays.asList(SnapshotDiffReportOzone.getDiffReportEntry( | |
| SnapshotDiffReport.DiffType.DELETE, "/" + key1), | |
| SnapshotDiffReportOzone.getDiffReportEntry( | |
| SnapshotDiffReport.DiffType.CREATE, "/" + key2)), | |
| diff2.getDiffList()); |
- Use
OM_KEY_PREFIXinstead of/. - Curious if it should be
./key.
108 changes: 108 additions & 0 deletions
108
...e-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/FSODirectoryPathResolver.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| /* | ||
| * 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 com.google.common.collect.Sets; | ||
| import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; | ||
| import org.apache.commons.lang3.tuple.Pair; | ||
| 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.Optional; | ||
| import java.util.Queue; | ||
| import java.util.Set; | ||
|
|
||
| import static org.apache.hadoop.ozone.OzoneConsts.OM_KEY_PREFIX; | ||
swamirishi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * Class to resolve absolute paths for FSO DirectoryInfo Objects. | ||
| */ | ||
| public class FSODirectoryPathResolver implements ObjectPathResolver { | ||
swamirishi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| private final String prefix; | ||
| private final long bucketId; | ||
| private final 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(Pair<Long, Path> objectIDPath, | ||
| Set<Long> dirObjIds, Map<Long, Path> pathMap) { | ||
| if (dirObjIds.contains(objectIDPath.getKey())) { | ||
| pathMap.put(objectIDPath.getKey(), objectIDPath.getValue()); | ||
| dirObjIds.remove(objectIDPath.getKey()); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Assuming all dirObjIds belong to a bucket this function resolves absolute | ||
| * path for a given FSO bucket. | ||
| * @param dirObjIds | ||
swamirishi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * @return Map of Path corresponding to provided directory object IDs | ||
| */ | ||
| @SuppressFBWarnings("DMI_HARDCODED_ABSOLUTE_FILENAME") | ||
swamirishi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| @Override | ||
| public Map<Long, Path> getAbsolutePathForObjectIDs( | ||
| Optional<Set<Long>> dirObjIds) throws IOException { | ||
| // Root of a bucket would always have the | ||
| // key as /volumeId/bucketId/bucketId/ | ||
| if (!dirObjIds.isPresent() || dirObjIds.get().isEmpty()) { | ||
| return Collections.emptyMap(); | ||
| } | ||
| Set<Long> objIds = Sets.newHashSet(dirObjIds.get()); | ||
| Map<Long, Path> pathMap = new HashMap<>(); | ||
swamirishi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Queue<Pair<Long, Path>> objectIdPathVals = new LinkedList<>(); | ||
| Pair<Long, Path> root = Pair.of(bucketId, Paths.get("/")); | ||
| objectIdPathVals.add(root); | ||
| addToPathMap(root, objIds, pathMap); | ||
|
|
||
| while (!objectIdPathVals.isEmpty() && objIds.size() > 0) { | ||
| Pair<Long, Path> parent = objectIdPathVals.poll(); | ||
| try (TableIterator<String, | ||
| ? extends Table.KeyValue<String, OmDirectoryInfo>> | ||
| subDirIter = dirInfoTable.iterator( | ||
| prefix + parent.getKey() + OM_KEY_PREFIX)) { | ||
| while (objIds.size() > 0 && subDirIter.hasNext()) { | ||
| OmDirectoryInfo childDir = subDirIter.next().getValue(); | ||
| Pair<Long, Path> pathVal = Pair.of(childDir.getObjectID(), | ||
| parent.getValue().resolve(childDir.getName())); | ||
| addToPathMap(pathVal, objIds, pathMap); | ||
| objectIdPathVals.add(pathVal); | ||
| } | ||
| } | ||
| } | ||
| // Invalid directory objectId which does not exist in the given bucket. | ||
| if (objIds.size() > 0) { | ||
| throw new IllegalArgumentException( | ||
| "Dir object Ids required but not found in bucket: " + objIds); | ||
| } | ||
| return pathMap; | ||
| } | ||
| } | ||
34 changes: 34 additions & 0 deletions
34
...e/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/ObjectPathResolver.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| /* | ||
| * 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 java.io.IOException; | ||
| import java.nio.file.Path; | ||
| import java.util.Map; | ||
| import java.util.Optional; | ||
| import java.util.Set; | ||
|
|
||
| /** | ||
| * Class to resolve paths of Objects. | ||
| */ | ||
| public interface ObjectPathResolver { | ||
|
|
||
| Map<Long, Path> getAbsolutePathForObjectIDs(Optional<Set<Long>> objIds) | ||
| throws IOException; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.