Example usage for org.apache.hadoop.hdfs DistributedFileSystem setQuota

List of usage examples for org.apache.hadoop.hdfs DistributedFileSystem setQuota

Introduction

In this page you can find the example usage for org.apache.hadoop.hdfs DistributedFileSystem setQuota.

Prototype

public void setQuota(Path src, final long namespaceQuota, final long storagespaceQuota) throws IOException 

Source Link

Document

Set a directory's quotas

Usage

From source file:com.trace.hadoop.TestDFSRename.java

License:Apache License

public void testRenameWithQuota() throws Exception {
    DistributedFileSystem fs = (DistributedFileSystem) cluster.getFileSystem();
    Path src1 = new Path(dir, "testRenameWithQuota/srcdir/src1");
    Path src2 = new Path(dir, "testRenameWithQuota/srcdir/src2");
    Path dst1 = new Path(dir, "testRenameWithQuota/dstdir/dst1");
    Path dst2 = new Path(dir, "testRenameWithQuota/dstdir/dst2");
    createFile(fs, src1);//from  w  w  w . j av a2s.  co  m
    createFile(fs, src2);
    fs.setQuota(src1.getParent(), FSConstants.QUOTA_DONT_SET, FSConstants.QUOTA_DONT_SET);
    fs.mkdirs(dst1.getParent());
    fs.setQuota(dst1.getParent(), FSConstants.QUOTA_DONT_SET, FSConstants.QUOTA_DONT_SET);

    // Test1: src does not exceed quota and dst has quota to accommodate rename
    rename(src1, dst1, true, false);

    // Test2: src does not exceed quota and dst has *no* quota to accommodate
    // rename
    fs.setQuota(dst1.getParent(), 1, FSConstants.QUOTA_DONT_SET);
    rename(src2, dst2, false, true);

    // Test3: src exceeds quota and dst has *no* quota to accommodate rename
    fs.setQuota(src1.getParent(), 1, FSConstants.QUOTA_DONT_SET);
    rename(dst1, src1, false, true);
}

From source file:com.trace.hadoop.TestDFSRename.java

License:Apache License

/**
 * Perform operations such as setting quota, deletion of files, rename and
 * ensure system can apply edits log during startup.
 *//*from   w  w w  .  ja  va 2 s.c o m*/
public void testEditsLog() throws Exception {
    DistributedFileSystem fs = (DistributedFileSystem) cluster.getFileSystem();
    Path src1 = new Path(dir, "testEditsLog/srcdir/src1");
    Path dst1 = new Path(dir, "testEditsLog/dstdir/dst1");
    createFile(fs, src1);
    fs.mkdirs(dst1.getParent());
    createFile(fs, dst1);

    // Set quota so that dst1 parent cannot allow under it new files/directories 
    fs.setQuota(dst1.getParent(), 2, FSConstants.QUOTA_DONT_SET);
    // Free up quota for a subsequent rename
    fs.delete(dst1, true);
    rename(src1, dst1, true, false);

    // Restart the cluster and ensure the above operations can be
    // loaded from the edits log
    restartCluster();
    fs = (DistributedFileSystem) cluster.getFileSystem();
    assertFalse(fs.exists(src1)); // ensure src1 is already renamed
    assertTrue(fs.exists(dst1)); // ensure rename dst exists
}