Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -40,6 +40,11 @@ public class SnapshotStatus {
*/
private final int snapshotID;

/**
* Whether the snapshot is deleted or not.
*/
private final boolean isDeleted;

/**
* Full path of the parent.
*/
Expand All @@ -50,7 +55,7 @@ public SnapshotStatus(long modificationTime, long accessTime,
EnumSet<HdfsFileStatus.Flags> flags,
String owner, String group, byte[] localName,
long inodeId, int childrenNum, int snapshotID,
byte[] parentFullPath) {
boolean isDeleted, byte[] parentFullPath) {
this.dirStatus = new HdfsFileStatus.Builder()
.isdir(true)
.mtime(modificationTime)
Expand All @@ -64,13 +69,7 @@ public SnapshotStatus(long modificationTime, long accessTime,
.children(childrenNum)
.build();
this.snapshotID = snapshotID;
this.parentFullPath = parentFullPath;
}

public SnapshotStatus(HdfsFileStatus dirStatus,
int snapshotNumber, byte[] parentFullPath) {
this.dirStatus = dirStatus;
this.snapshotID = snapshotNumber;
this.isDeleted = isDeleted;
this.parentFullPath = parentFullPath;
}

Expand All @@ -89,6 +88,13 @@ public int getSnapshotID() {
return snapshotID;
}

/**
* @return whether snapshot is deleted
*/
public boolean isDeleted() {
return isDeleted;
}

/**
* @return The basic information of the directory
*/
Expand Down Expand Up @@ -143,6 +149,7 @@ public static void print(SnapshotStatus[] stats,
+ "%" + maxLen + "s "
+ "%s " // mod time
+ "%" + maxSnapshotID + "s "
+ "%s " // deletion status
+ "%s"; // path
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");

Expand All @@ -155,6 +162,7 @@ public static void print(SnapshotStatus[] stats,
String.valueOf(status.dirStatus.getLen()),
dateFormat.format(new Date(status.dirStatus.getModificationTime())),
status.snapshotID,
status.isDeleted ? "DELETED" : "ACTIVE",
getSnapshotPath(DFSUtilClient.bytes2String(status.parentFullPath),
status.dirStatus.getLocalName())
);
Expand Down Expand Up @@ -207,6 +215,10 @@ public String getOwner() {
public String getGroup() {
return group;
}

public boolean isDELETED () {
return isDELETED();
}
}

static String getSnapshotPath(String snapshottableDir,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1711,6 +1711,7 @@ public static SnapshotStatus convert(
status.getFileId(),
status.getChildrenNum(),
sdirStatusProto.getSnapshotID(),
sdirStatusProto.getIsDeleted(),
sdirStatusProto.getParentFullpath().toByteArray());
}

Expand Down Expand Up @@ -2425,6 +2426,7 @@ public static HdfsProtos.SnapshotStatusProto convert(SnapshotStatus status) {
.newBuilder()
.setSnapshotID(status.getSnapshotID())
.setParentFullpath(parentFullPathBytes)
.setIsDeleted(status.isDeleted())
.setDirStatus(fs);
return builder.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,7 @@ message SnapshotStatusProto {
// Fields specific for snapshot directory
required uint32 snapshotID = 2;
required bytes parent_fullpath = 3;
required bool isDeleted = 4;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,8 @@ public SnapshotStatus[] getSnapshotListing(INodesInPath iip)
// It is expensive to build the snapshot tree for the directory
// and determine the child count.
dir.getChildrenNum(Snapshot.CURRENT_STATE_ID),
s.getId(), DFSUtil.string2Bytes(dir.getParent().getFullPathName()));
s.getId(), s.getRoot().isMarkedAsDeleted(),
DFSUtil.string2Bytes(dir.getParent().getFullPathName()));

}
return statuses;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@
import org.junit.Before;
import org.junit.Test;

import static org.apache.hadoop.hdfs.server.namenode.snapshot.SnapshotManager.
DFS_NAMENODE_SNAPSHOT_DELETION_ORDERED;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;

Expand All @@ -51,6 +54,7 @@ public class TestListSnapshot {
@Before
public void setUp() throws Exception {
conf = new Configuration();
conf.setBoolean(DFS_NAMENODE_SNAPSHOT_DELETION_ORDERED, true);
cluster = new MiniDFSCluster.Builder(conf).numDataNodes(REPLICATION)
.build();
cluster.waitActive();
Expand Down Expand Up @@ -128,7 +132,15 @@ public void testListSnapshot() throws Exception {
snapshotStatuses[2].getFullPath());
hdfs.deleteSnapshot(dir1, "s2");
snapshotStatuses = hdfs.getSnapshotListing(dir1);
// There are now 2 snapshots for dir1
// There are now 2 active snapshots for dir1 and one is marked deleted
assertEquals(3, snapshotStatuses.length);
assertTrue(snapshotStatuses[2].isDeleted());
assertFalse(snapshotStatuses[1].isDeleted());
assertFalse(snapshotStatuses[0].isDeleted());
// delete the 1st snapshot
hdfs.deleteSnapshot(dir1, "s0");
snapshotStatuses = hdfs.getSnapshotListing(dir1);
// There are now 2 snapshots now as the 1st one is deleted in order
assertEquals(2, snapshotStatuses.length);
}
}