HDFS-4091. Add snapshot quota to limit the number of snapshots allowed.
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/HDFS-2802@1401868 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
4fde5c0190
commit
b897bb8992
@ -23,3 +23,6 @@ Branch-2802 Snapshot (Unreleased)
|
|||||||
|
|
||||||
HDFS-4084. Provide CLI support to allow and disallow snapshot
|
HDFS-4084. Provide CLI support to allow and disallow snapshot
|
||||||
on a directory. (Brondon Li via suresh)
|
on a directory. (Brondon Li via suresh)
|
||||||
|
|
||||||
|
HDFS-4091. Add snapshot quota to limit the number of snapshots allowed.
|
||||||
|
(szetszwo)
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.hadoop.HadoopIllegalArgumentException;
|
||||||
import org.apache.hadoop.classification.InterfaceAudience;
|
import org.apache.hadoop.classification.InterfaceAudience;
|
||||||
import org.apache.hadoop.hdfs.server.namenode.INode;
|
import org.apache.hadoop.hdfs.server.namenode.INode;
|
||||||
import org.apache.hadoop.hdfs.server.namenode.INodeDirectory;
|
import org.apache.hadoop.hdfs.server.namenode.INodeDirectory;
|
||||||
@ -30,7 +31,8 @@
|
|||||||
/** Directories where taking snapshots is allowed. */
|
/** Directories where taking snapshots is allowed. */
|
||||||
@InterfaceAudience.Private
|
@InterfaceAudience.Private
|
||||||
public class INodeDirectorySnapshottable extends INodeDirectoryWithQuota {
|
public class INodeDirectorySnapshottable extends INodeDirectoryWithQuota {
|
||||||
static public INodeDirectorySnapshottable newInstance(final INodeDirectory dir) {
|
static public INodeDirectorySnapshottable newInstance(
|
||||||
|
final INodeDirectory dir, final int snapshotQuota) {
|
||||||
long nsq = -1L;
|
long nsq = -1L;
|
||||||
long dsq = -1L;
|
long dsq = -1L;
|
||||||
|
|
||||||
@ -39,7 +41,7 @@ static public INodeDirectorySnapshottable newInstance(final INodeDirectory dir)
|
|||||||
nsq = q.getNsQuota();
|
nsq = q.getNsQuota();
|
||||||
dsq = q.getDsQuota();
|
dsq = q.getDsQuota();
|
||||||
}
|
}
|
||||||
return new INodeDirectorySnapshottable(nsq, dsq, dir);
|
return new INodeDirectorySnapshottable(nsq, dsq, dir, snapshotQuota);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Cast INode to INodeDirectorySnapshottable. */
|
/** Cast INode to INodeDirectorySnapshottable. */
|
||||||
@ -55,10 +57,25 @@ static public INodeDirectorySnapshottable valueOf(
|
|||||||
/** A list of snapshots of this directory. */
|
/** A list of snapshots of this directory. */
|
||||||
private final List<INodeDirectorySnapshotRoot> snapshots
|
private final List<INodeDirectorySnapshotRoot> snapshots
|
||||||
= new ArrayList<INodeDirectorySnapshotRoot>();
|
= new ArrayList<INodeDirectorySnapshotRoot>();
|
||||||
|
/** Number of snapshots is allowed. */
|
||||||
|
private int snapshotQuota;
|
||||||
|
|
||||||
private INodeDirectorySnapshottable(long nsQuota, long dsQuota,
|
private INodeDirectorySnapshottable(long nsQuota, long dsQuota,
|
||||||
INodeDirectory dir) {
|
INodeDirectory dir, final int snapshotQuota) {
|
||||||
super(nsQuota, dsQuota, dir);
|
super(nsQuota, dsQuota, dir);
|
||||||
|
setSnapshotQuota(snapshotQuota);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSnapshotQuota() {
|
||||||
|
return snapshotQuota;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSnapshotQuota(int snapshotQuota) {
|
||||||
|
if (snapshotQuota <= 0) {
|
||||||
|
throw new HadoopIllegalArgumentException(
|
||||||
|
"Cannot set snapshot quota to " + snapshotQuota + " <= 0");
|
||||||
|
}
|
||||||
|
this.snapshotQuota = snapshotQuota;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -67,7 +84,15 @@ public boolean isSnapshottable() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Add a snapshot root under this directory. */
|
/** Add a snapshot root under this directory. */
|
||||||
INodeDirectorySnapshotRoot addSnapshotRoot(final String name) {
|
INodeDirectorySnapshotRoot addSnapshotRoot(final String name
|
||||||
|
) throws SnapshotException {
|
||||||
|
//check snapshot quota
|
||||||
|
if (snapshots.size() + 1 > snapshotQuota) {
|
||||||
|
throw new SnapshotException("Failed to add snapshot: there are already "
|
||||||
|
+ snapshots.size() + " snapshot(s) and the snapshot quota is "
|
||||||
|
+ snapshotQuota);
|
||||||
|
}
|
||||||
|
|
||||||
final INodeDirectorySnapshotRoot r = new INodeDirectorySnapshotRoot(name, this);
|
final INodeDirectorySnapshotRoot r = new INodeDirectorySnapshotRoot(name, this);
|
||||||
snapshots.add(r);
|
snapshots.add(r);
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ public SnapshotManager(final Namesystem namesystem) {
|
|||||||
* Otherwise, the {@link INodeDirectory} of the path is replaced by an
|
* Otherwise, the {@link INodeDirectory} of the path is replaced by an
|
||||||
* {@link INodeDirectorySnapshottable}.
|
* {@link INodeDirectorySnapshottable}.
|
||||||
*/
|
*/
|
||||||
public void setSnapshottable(final String path,
|
public void setSnapshottable(final String path, final int snapshotQuota,
|
||||||
final FSDirectory fsdir) throws IOException {
|
final FSDirectory fsdir) throws IOException {
|
||||||
namesystem.writeLock();
|
namesystem.writeLock();
|
||||||
try {
|
try {
|
||||||
@ -54,7 +54,7 @@ public void setSnapshottable(final String path,
|
|||||||
}
|
}
|
||||||
|
|
||||||
final INodeDirectorySnapshottable s
|
final INodeDirectorySnapshottable s
|
||||||
= INodeDirectorySnapshottable.newInstance(d);
|
= INodeDirectorySnapshottable.newInstance(d, snapshotQuota);
|
||||||
fsdir.replaceINodeDirectory(path, d, s);
|
fsdir.replaceINodeDirectory(path, d, s);
|
||||||
snapshottables.add(s);
|
snapshottables.add(s);
|
||||||
} finally {
|
} finally {
|
||||||
|
Loading…
Reference in New Issue
Block a user