Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Expand Up @@ -222,7 +222,9 @@ public SnapshotDiffReport generateReport() {
generateReportList();
for (DiffReportListingEntry modified : mlist) {
diffReportList.add(
new DiffReportEntry(DiffType.MODIFY, modified.getSourcePath(), null));
new DiffReportEntry(modified.getINodeType()
.toSnapshotDiffReportINodeType(),
DiffType.MODIFY, modified.getSourcePath(), null));
if (modified.isReference()
&& dirDiffMap.get(modified.getDirId()) != null) {
List<DiffReportEntry> subList = generateReport(modified);
Expand All @@ -241,18 +243,22 @@ private List<DiffReportEntry> generateReport(
RenameEntry entry = renameMap.get(created.getFileId());
if (entry == null || !entry.isRename()) {
diffReportList.add(new DiffReportEntry(
created.getINodeType().toSnapshotDiffReportINodeType(),
isFromEarlier ? DiffType.CREATE : DiffType.DELETE,
created.getSourcePath()));
}
}
for (DiffReportListingEntry deleted : list.getDeletedList()) {
RenameEntry entry = renameMap.get(deleted.getFileId());
if (entry != null && entry.isRename()) {
diffReportList.add(new DiffReportEntry(DiffType.RENAME,
diffReportList.add(new DiffReportEntry(
deleted.getINodeType().toSnapshotDiffReportINodeType(),
DiffType.RENAME,
isFromEarlier ? entry.getSourcePath() : entry.getTargetPath(),
isFromEarlier ? entry.getTargetPath() : entry.getSourcePath()));
} else {
diffReportList.add(new DiffReportEntry(
deleted.getINodeType().toSnapshotDiffReportINodeType(),
isFromEarlier ? DiffType.DELETE : DiffType.CREATE,
deleted.getSourcePath()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,36 +75,55 @@ public static DiffType parseDiffType(String s){
}
}

/**
* INodeType specifies the type of INode: FILE, DIRECTORY, or SYMLINK.
*/
public enum INodeType {
FILE,
DIRECTORY,
SYMLINK;

public static INodeType parseINodeType(String s) {
return INodeType.valueOf(s.toUpperCase());
}
}

/**
* Representing the full path and diff type of a file/directory where changes
* have happened.
*/
public static class DiffReportEntry {
/** The type of the difference. */
private final DiffType type;
private final INodeType inodeType;
/**
* The relative path (related to the snapshot root) of 1) the file/directory
* where changes have happened, or 2) the source file/dir of a rename op.
*/
private final byte[] sourcePath;
private final byte[] targetPath;

public DiffReportEntry(DiffType type, byte[] sourcePath) {
this(type, sourcePath, null);
public DiffReportEntry(INodeType inodeType, DiffType type,
byte[] sourcePath) {
this(inodeType, type, sourcePath, null);
}

public DiffReportEntry(DiffType type, byte[][] sourcePathComponents) {
this(type, sourcePathComponents, null);
public DiffReportEntry(INodeType inodeType, DiffType type,
byte[][] sourcePathComponents) {
this(inodeType, type, sourcePathComponents, null);
}

public DiffReportEntry(DiffType type, byte[] sourcePath, byte[] targetPath) {
public DiffReportEntry(INodeType inodeType, DiffType type,
byte[] sourcePath, byte[] targetPath) {
this.inodeType = inodeType;
this.type = type;
this.sourcePath = sourcePath;
this.targetPath = targetPath;
}

public DiffReportEntry(DiffType type, byte[][] sourcePathComponents,
byte[][] targetPathComponents) {
public DiffReportEntry(INodeType inodeType, DiffType type,
byte[][] sourcePathComponents, byte[][] targetPathComponents) {
this.inodeType = inodeType;
this.type = type;
this.sourcePath = DFSUtilClient.byteArray2bytes(sourcePathComponents);
this.targetPath = targetPathComponents == null ? null : DFSUtilClient
Expand All @@ -124,6 +143,10 @@ public DiffType getType() {
return type;
}

public INodeType getInodeType() {
return inodeType;
}

static String getPathString(byte[] path) {
String pathStr = DFSUtilClient.bytes2String(path);
if (pathStr.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,29 @@ public class SnapshotDiffReportListing {
* have happened.
*/
public static class DiffReportListingEntry {

/**
* INodeType specifies the type of the INode.
*/
public enum INodeType {

FILE(SnapshotDiffReport.INodeType.FILE),
DIRECTORY(SnapshotDiffReport.INodeType.DIRECTORY),
SYMLINK(SnapshotDiffReport.INodeType.SYMLINK);

private SnapshotDiffReport.INodeType snapshotDiffReportINodeType;

INodeType(SnapshotDiffReport.INodeType snapshotDiffReportINodeType) {
this.snapshotDiffReportINodeType = snapshotDiffReportINodeType;
}

public SnapshotDiffReport.INodeType toSnapshotDiffReportINodeType() {
return snapshotDiffReportINodeType;
}
}

private final INodeType inodeType;

/**
* The type of the difference.
*/
Expand All @@ -51,19 +74,21 @@ public static class DiffReportListingEntry {
private final byte[][] sourcePath;
private final byte[][] targetPath;

public DiffReportListingEntry(long dirId, long fileId, byte[][] sourcePath,
boolean isReference, byte[][] targetPath) {
public DiffReportListingEntry(INodeType inodeType, long dirId, long fileId,
byte[][] sourcePath, boolean isReference, byte[][] targetPath) {
Preconditions.checkNotNull(sourcePath);
this.inodeType = inodeType;
this.dirId = dirId;
this.fileId = fileId;
this.sourcePath = sourcePath;
this.isReference = isReference;
this.targetPath = targetPath;
}

public DiffReportListingEntry(long dirId, long fileId, byte[] sourcePath,
boolean isReference, byte[] targetpath) {
public DiffReportListingEntry(INodeType inodeType, long dirId, long fileId,
byte[] sourcePath, boolean isReference, byte[] targetpath) {
Preconditions.checkNotNull(sourcePath);
this.inodeType = inodeType;
this.dirId = dirId;
this.fileId = fileId;
this.sourcePath = DFSUtilClient.bytes2byteArray(sourcePath);
Expand All @@ -72,6 +97,10 @@ public DiffReportListingEntry(long dirId, long fileId, byte[] sourcePath,
targetpath == null ? null : DFSUtilClient.bytes2byteArray(targetpath);
}

public INodeType getINodeType() {
return inodeType;
}

public long getDirId() {
return dirId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1599,9 +1599,26 @@ public static DiffReportEntry convert(SnapshotDiffReportEntryProto entry) {
}
DiffType type = DiffType.getTypeFromLabel(entry
.getModificationLabel());
return type == null ? null : new DiffReportEntry(type, entry.getFullpath()
.toByteArray(), entry.hasTargetPath() ? entry.getTargetPath()
.toByteArray() : null);
SnapshotDiffReport.INodeType inodeType = null;
if (entry.hasFileType()) {
switch (entry.getFileType()) {
case IS_FILE:
inodeType = SnapshotDiffReport.INodeType.FILE;
break;
case IS_DIR:
inodeType = SnapshotDiffReport.INodeType.DIRECTORY;
break;
case IS_SYMLINK:
inodeType = SnapshotDiffReport.INodeType.SYMLINK;
break;
default:
throw new IllegalArgumentException("Unknown INodeType: " +
entry.getFileType());
}
}
return type == null ? null : new DiffReportEntry(inodeType, type,
entry.getFullpath().toByteArray(), entry.hasTargetPath() ?
entry.getTargetPath().toByteArray() : null);
}

public static SnapshotDiffReportListing convert(
Expand Down Expand Up @@ -1649,14 +1666,29 @@ public static DiffReportListingEntry convert(
if (entry == null) {
return null;
}
DiffReportListingEntry.INodeType inodeType = null;
switch(entry.getFileType()) {
case IS_FILE:
inodeType = DiffReportListingEntry.INodeType.FILE;
break;
case IS_DIR:
inodeType = DiffReportListingEntry.INodeType.DIRECTORY;
break;
case IS_SYMLINK:
inodeType = DiffReportListingEntry.INodeType.SYMLINK;
break;
default:
throw new IllegalArgumentException("Unknown entry file type: "
+ entry.getFileType());
}
long dirId = entry.getDirId();
long fileId = entry.getFileId();
boolean isReference = entry.getIsReference();
byte[] sourceName = entry.getFullpath().toByteArray();
byte[] targetName =
entry.hasTargetPath() ? entry.getTargetPath().toByteArray() : null;
return new DiffReportListingEntry(dirId, fileId, sourceName, isReference,
targetName);
return new DiffReportListingEntry(inodeType, dirId, fileId, sourceName,
isReference, targetName);
}

public static SnapshottableDirectoryStatus[] convert(
Expand Down Expand Up @@ -2679,6 +2711,20 @@ public static SnapshotDiffReportEntryProto convert(DiffReportEntry entry) {
SnapshotDiffReportEntryProto.Builder builder = SnapshotDiffReportEntryProto
.newBuilder().setFullpath(sourcePath)
.setModificationLabel(modification);
switch(entry.getInodeType()){
case FILE:
builder.setFileType(FileType.IS_FILE);
break;
case DIRECTORY:
builder.setFileType(FileType.IS_DIR);
break;
case SYMLINK:
builder.setFileType(FileType.IS_SYMLINK);
break;
default:
throw new IllegalArgumentException("Unknown INodeType: " +
entry.getInodeType());
}
if (entry.getType() == DiffType.RENAME) {
ByteString targetPath =
getByteString(entry.getTargetPath() == null ?
Expand All @@ -2696,14 +2742,31 @@ public static SnapshotDiffReportListingEntryProto convert(
ByteString sourcePath = getByteString(
entry.getSourcePath() == null ? DFSUtilClient.EMPTY_BYTES :
DFSUtilClient.byteArray2bytes(entry.getSourcePath()));
HdfsFileStatusProto.FileType fileType = null;
switch(entry.getINodeType()){
case FILE:
fileType = FileType.IS_FILE;
break;
case DIRECTORY:
fileType = FileType.IS_DIR;
break;
case SYMLINK:
fileType = FileType.IS_SYMLINK;
break;
default:
throw new IllegalArgumentException("Unknown INodeType: " +
entry.getINodeType());
}
long dirId = entry.getDirId();
long fileId = entry.getFileId();
boolean isReference = entry.isReference();
ByteString targetPath = getByteString(
entry.getTargetPath() == null ? DFSUtilClient.EMPTY_BYTES :
DFSUtilClient.byteArray2bytes(entry.getTargetPath()));
SnapshotDiffReportListingEntryProto.Builder builder =
SnapshotDiffReportListingEntryProto.newBuilder().setFullpath(sourcePath)
SnapshotDiffReportListingEntryProto.newBuilder()
.setFileType(fileType)
.setFullpath(sourcePath)
.setDirId(dirId).setFileId(fileId).setIsReference(isReference)
.setTargetPath(targetPath);
return builder.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -803,11 +803,15 @@ private static SnapshotDiffReport.DiffReportEntry toDiffReportEntry(
if (json == null) {
return null;
}
SnapshotDiffReport.INodeType iNodeType =
SnapshotDiffReport.INodeType.parseINodeType(
(String) json.get("inodeType"));
SnapshotDiffReport.DiffType type =
SnapshotDiffReport.DiffType.parseDiffType((String) json.get("type"));
byte[] sourcePath = toByteArray((String) json.get("sourcePath"));
byte[] targetPath = toByteArray((String) json.get("targetPath"));
return new SnapshotDiffReport.DiffReportEntry(type, sourcePath, targetPath);
return new SnapshotDiffReport.DiffReportEntry(iNodeType, type, sourcePath,
targetPath);
}

private static byte[] toByteArray(String str) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -547,13 +547,15 @@ message SnapshottableDirectoryListingProto {
repeated SnapshottableDirectoryStatusProto snapshottableDirListing = 1;
}


/**
* Snapshot diff report entry
*/
message SnapshotDiffReportEntryProto {
required bytes fullpath = 1;
required string modificationLabel = 2;
optional bytes targetPath = 3;
optional HdfsFileStatusProto.FileType fileType = 4;
}

/**
Expand All @@ -576,6 +578,7 @@ message SnapshotDiffReportListingEntryProto {
required bool isReference = 3;
optional bytes targetPath = 4;
optional uint64 fileId = 5;
optional HdfsFileStatusProto.FileType fileType = 6;
}

message SnapshotDiffReportCursorProto {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.apache.hadoop.hdfs.protocol.SnapshotDiffReport;
import org.apache.hadoop.hdfs.protocol.SnapshotDiffReport.DiffReportEntry;
import org.apache.hadoop.hdfs.protocol.SnapshotDiffReport.DiffType;
import org.apache.hadoop.hdfs.protocol.SnapshotDiffReport.INodeType;
import org.apache.hadoop.hdfs.server.namenode.INode;
import org.apache.hadoop.hdfs.server.namenode.INodeDirectory;
import org.apache.hadoop.hdfs.server.namenode.INodeFile;
Expand Down Expand Up @@ -238,7 +239,8 @@ public SnapshotDiffReport generateReport() {
for (Map.Entry<INode,byte[][]> drEntry : diffMap.entrySet()) {
INode node = drEntry.getKey();
byte[][] path = drEntry.getValue();
diffReportList.add(new DiffReportEntry(DiffType.MODIFY, path, null));
diffReportList.add(new DiffReportEntry(determineINodeType(node),
DiffType.MODIFY, path, null));
if (node.isDirectory()) {
List<DiffReportEntry> subList = generateReport(dirDiffMap.get(node),
path, isFromEarlier(), renameMap);
Expand Down Expand Up @@ -274,22 +276,34 @@ private List<DiffReportEntry> generateReport(ChildrenDiff dirDiff,
RenameEntry entry = renameMap.get(cnode.getId());
if (entry == null || !entry.isRename()) {
fullPath[fullPath.length - 1] = cnode.getLocalNameBytes();
list.add(new DiffReportEntry(fromEarlier ? DiffType.CREATE
: DiffType.DELETE, fullPath));
list.add(new DiffReportEntry(determineINodeType(cnode),
fromEarlier ? DiffType.CREATE : DiffType.DELETE, fullPath));
}
}
for (INode dnode : dirDiff.getDeletedUnmodifiable()) {
RenameEntry entry = renameMap.get(dnode.getId());
if (entry != null && entry.isRename()) {
list.add(new DiffReportEntry(DiffType.RENAME,
list.add(new DiffReportEntry(determineINodeType(dnode), DiffType.RENAME,
fromEarlier ? entry.getSourcePath() : entry.getTargetPath(),
fromEarlier ? entry.getTargetPath() : entry.getSourcePath()));
} else {
fullPath[fullPath.length - 1] = dnode.getLocalNameBytes();
list.add(new DiffReportEntry(fromEarlier ? DiffType.DELETE
: DiffType.CREATE, fullPath));
list.add(new DiffReportEntry(determineINodeType(dnode),
fromEarlier ? DiffType.DELETE : DiffType.CREATE, fullPath));
}
}
return list;
}

private static INodeType determineINodeType(INode node) {
if (node.isDirectory()) {
return INodeType.DIRECTORY;
} else if (node.isFile()) {
return INodeType.FILE;
} else if (node.isSymlink()) {
return INodeType.SYMLINK;
} else {
throw new IllegalArgumentException("This type of INode is not supported");
}
}
}
Loading