Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,12 @@
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;

Expand Down Expand Up @@ -166,7 +163,7 @@ public static DiffReportEntry fromProtobufDiffReportEntry(
return null;
}
DiffType type = fromProtobufDiffType(entry.getDiffType());
return type == null ? null : new DiffReportEntryOzone(type,
return type == null ? null : new DiffReportEntry(type,
entry.getSourcePath().getBytes(StandardCharsets.UTF_8),
entry.hasTargetPath() ?
entry.getTargetPath().getBytes(StandardCharsets.UTF_8) : null);
Expand Down Expand Up @@ -194,7 +191,7 @@ public static DiffReportEntry getDiffReportEntry(final DiffType type,

public static DiffReportEntry getDiffReportEntry(final DiffType type,
final String sourcePath, final String targetPath) {
return new DiffReportEntryOzone(type,
return new DiffReportEntry(type,
sourcePath.getBytes(StandardCharsets.UTF_8),
targetPath != null ? targetPath.getBytes(StandardCharsets.UTF_8) :
null);
Expand All @@ -208,45 +205,4 @@ public static DiffReportEntry getDiffReportEntry(final DiffType type,
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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@
import java.util.stream.Collectors;

import static org.apache.hadoop.hdds.HddsConfigKeys.HDDS_DB_PROFILE;
import static org.apache.hadoop.ozone.OzoneConsts.OZONE_URI_DELIMITER;
import static org.apache.hadoop.ozone.admin.scm.FinalizeUpgradeCommandUtil.isDone;
import static org.apache.hadoop.ozone.admin.scm.FinalizeUpgradeCommandUtil.isStarting;
import static org.apache.hadoop.ozone.OzoneConsts.OM_KEY_PREFIX;
Expand Down Expand Up @@ -231,7 +230,7 @@ private void init() throws Exception {

// stop the deletion services so that keys can still be read
keyManager.stop();
preFinalizationChecks();
// preFinalizationChecks();
finalizeOMUpgrade();
counter = new AtomicInteger();
}
Expand Down Expand Up @@ -616,7 +615,7 @@ public void testSnapDiffWithDirRename() throws Exception {
snap1, snap2);
Assertions.assertEquals(Arrays.asList(
SnapshotDiffReportOzone.getDiffReportEntry(
SnapshotDiffReport.DiffType.RENAME, "/dir1", "/dir1_rename")),
SnapshotDiffReport.DiffType.RENAME, "dir1", "dir1_rename")),
diff.getDiffList());
}

Expand Down Expand Up @@ -659,11 +658,9 @@ public void testSnapDiff() throws Exception {
Assert.assertEquals(2, diff2.getDiffList().size());
Assert.assertEquals(
Arrays.asList(SnapshotDiffReportOzone.getDiffReportEntry(
SnapshotDiffReport.DiffType.DELETE,
OZONE_URI_DELIMITER + key1),
SnapshotDiffReport.DiffType.DELETE, key1),
SnapshotDiffReportOzone.getDiffReportEntry(
SnapshotDiffReport.DiffType.CREATE,
OZONE_URI_DELIMITER + key2)),
SnapshotDiffReport.DiffType.CREATE, key2)),
diff2.getDiffList());

// Rename Key2
Expand All @@ -677,8 +674,8 @@ public void testSnapDiff() throws Exception {
Assert.assertEquals(1, diff3.getDiffList().size());
Assert.assertTrue(diff3.getDiffList().contains(
SnapshotDiffReportOzone.getDiffReportEntry(
SnapshotDiffReportOzone.DiffType.RENAME, OZONE_URI_DELIMITER + key2,
OZONE_URI_DELIMITER + key2Renamed)));
SnapshotDiffReportOzone.DiffType.RENAME, key2,
key2Renamed)));


// Create a directory
Expand All @@ -691,8 +688,7 @@ public void testSnapDiff() throws Exception {
Assert.assertEquals(1, diff4.getDiffList().size());
Assert.assertTrue(diff4.getDiffList().contains(
SnapshotDiffReportOzone.getDiffReportEntry(
SnapshotDiffReportOzone.DiffType.CREATE,
OM_KEY_PREFIX + dir1)));
SnapshotDiffReportOzone.DiffType.CREATE, dir1)));

String key3 = createFileKeyWithPrefix(bucket1, "key-3-");
String snap6 = "snap" + counter.incrementAndGet();
Expand All @@ -707,10 +703,10 @@ public void testSnapDiff() throws Exception {
diff5 = getSnapDiffReport(volume, bucket, snap6, snap7);
List<SnapshotDiffReport.DiffReportEntry> expectedDiffList =
Arrays.asList(SnapshotDiffReportOzone.getDiffReportEntry(
SnapshotDiffReport.DiffType.RENAME, OZONE_URI_DELIMITER + key3,
OZONE_URI_DELIMITER + renamedKey3),
SnapshotDiffReport.DiffType.RENAME, key3,
renamedKey3),
SnapshotDiffReportOzone.getDiffReportEntry(
SnapshotDiffReport.DiffType.MODIFY, OZONE_URI_DELIMITER + key3)
SnapshotDiffReport.DiffType.MODIFY, key3)
);
assertEquals(expectedDiffList, diff5.getDiffList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1266,8 +1266,8 @@ private void validateEstimatedKeyChangesAreInLimits(
}

@SuppressFBWarnings("DMI_HARDCODED_ABSOLUTE_FILENAME")
private String resolveAbsolutePath(boolean isFSOBucket,
final Optional<Map<Long, Path>> parentIdMap, byte[] keyVal)
private String resolveBucketRelativePath(boolean isFSOBucket,
final Optional<Map<Long, Path>> parentIdMap, byte[] keyVal)
throws IOException {
String key = codecRegistry.asObject(keyVal, String.class);
if (isFSOBucket) {
Expand All @@ -1279,9 +1279,10 @@ private String resolveAbsolutePath(boolean isFSOBucket,
parentId));
}
return parentIdMap.map(m -> m.get(parentId).resolve(splitKey[1]))
.get().toString();
.get().toString().substring(1);
}
return Paths.get(OzoneConsts.OZONE_URI_DELIMITER).resolve(key).toString();
return Paths.get(OzoneConsts.OZONE_URI_DELIMITER).resolve(key).toString()
.substring(1);
}

@SuppressWarnings({"checkstyle:ParameterNumber", "checkstyle:MethodLength"})
Expand Down Expand Up @@ -1366,28 +1367,28 @@ long generateDiffReport(
throw new IllegalStateException(
"Old and new key name both are null");
} else if (oldKeyName == null) { // Key Created.
String key = resolveAbsolutePath(isFSOBucket, newParentIdPathMap,
newKeyName);
String key = resolveBucketRelativePath(isFSOBucket,
newParentIdPathMap, newKeyName);
DiffReportEntry entry =
SnapshotDiffReportOzone.getDiffReportEntry(CREATE, key);
createDiffs.add(codecRegistry.asRawData(entry));
} else if (newKeyName == null) { // Key Deleted.
String key = resolveAbsolutePath(isFSOBucket, oldParentIdPathMap,
oldKeyName);
String key = resolveBucketRelativePath(isFSOBucket,
oldParentIdPathMap, oldKeyName);
DiffReportEntry entry =
SnapshotDiffReportOzone.getDiffReportEntry(DELETE, key);
deleteDiffs.add(codecRegistry.asRawData(entry));
} else if (Arrays.equals(oldKeyName, newKeyName)) { // Key modified.
String key = resolveAbsolutePath(isFSOBucket, newParentIdPathMap,
newKeyName);
String key = resolveBucketRelativePath(isFSOBucket,
newParentIdPathMap, newKeyName);
DiffReportEntry entry =
SnapshotDiffReportOzone.getDiffReportEntry(MODIFY, key);
modifyDiffs.add(codecRegistry.asRawData(entry));
} else { // Key Renamed.
String oldKey = resolveAbsolutePath(isFSOBucket, oldParentIdPathMap,
oldKeyName);
String newKey = resolveAbsolutePath(isFSOBucket, newParentIdPathMap,
newKeyName);
String oldKey = resolveBucketRelativePath(isFSOBucket,
oldParentIdPathMap, oldKeyName);
String newKey = resolveBucketRelativePath(isFSOBucket,
newParentIdPathMap, newKeyName);
renameDiffs.add(codecRegistry.asRawData(
SnapshotDiffReportOzone.getDiffReportEntry(RENAME, oldKey,
newKey)));
Expand Down