Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
madanadit committed May 2, 2017
1 parent ad9de81 commit 56f407b
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 46 deletions.
Expand Up @@ -31,7 +31,7 @@
public final class DeleteOptions { public final class DeleteOptions {
private boolean mRecursive; private boolean mRecursive;
private boolean mAlluxioOnly; private boolean mAlluxioOnly;
private boolean mSkipConsistencyCheck; private boolean mUnchecked;


/** /**
* @return the default {@link DeleteOptions} * @return the default {@link DeleteOptions}
Expand All @@ -43,8 +43,8 @@ public static DeleteOptions defaults() {
private DeleteOptions() { private DeleteOptions() {
mRecursive = false; mRecursive = false;
mAlluxioOnly = false; mAlluxioOnly = false;
mSkipConsistencyCheck = mUnchecked =
Configuration.getBoolean(PropertyKey.USER_FILE_DELETE_SKIP_CONSISTENCY_CHECK); Configuration.getBoolean(PropertyKey.USER_FILE_DELETE_UNCHECKED);
} }


/** /**
Expand All @@ -64,10 +64,10 @@ public boolean isAlluxioOnly() {
} }


/** /**
* @return if the UFS consistency check should be skipped * @return if the UFS sync check should be skipped
*/ */
public boolean isSkipConsistencyCheck() { public boolean isUnchecked() {
return mSkipConsistencyCheck; return mUnchecked;
} }


/** /**
Expand All @@ -91,11 +91,11 @@ public DeleteOptions setAlluxioOnly(boolean alluxioOnly) {
} }


/** /**
* @param skipConsistencyCheck whether to skip UFS consistency check * @param unchecked whether to skip UFS consistency check
* @return the updated options object * @return the updated options object
*/ */
public DeleteOptions setSkipConsistencyCheck(boolean skipConsistencyCheck) { public DeleteOptions setUnchecked(boolean unchecked) {
mSkipConsistencyCheck = skipConsistencyCheck; mUnchecked = unchecked;
return this; return this;
} }


Expand All @@ -110,20 +110,20 @@ public boolean equals(Object o) {
DeleteOptions that = (DeleteOptions) o; DeleteOptions that = (DeleteOptions) o;
return Objects.equal(mRecursive, that.mRecursive) return Objects.equal(mRecursive, that.mRecursive)
&& Objects.equal(mAlluxioOnly, that.mAlluxioOnly) && Objects.equal(mAlluxioOnly, that.mAlluxioOnly)
&& Objects.equal(mSkipConsistencyCheck, that.mSkipConsistencyCheck); && Objects.equal(mUnchecked, that.mUnchecked);
} }


@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hashCode(mRecursive, mAlluxioOnly, mSkipConsistencyCheck); return Objects.hashCode(mRecursive, mAlluxioOnly, mUnchecked);
} }


@Override @Override
public String toString() { public String toString() {
return Objects.toStringHelper(this) return Objects.toStringHelper(this)
.add("recursive", mRecursive) .add("recursive", mRecursive)
.add("alluxioOnly", mAlluxioOnly) .add("alluxioOnly", mAlluxioOnly)
.add("skipConsistencyCheck", mSkipConsistencyCheck) .add("skipConsistencyCheck", mUnchecked)
.toString(); .toString();
} }


Expand All @@ -134,7 +134,7 @@ public DeleteTOptions toThrift() {
DeleteTOptions options = new DeleteTOptions(); DeleteTOptions options = new DeleteTOptions();
options.setRecursive(mRecursive); options.setRecursive(mRecursive);
options.setAlluxioOnly(mAlluxioOnly); options.setAlluxioOnly(mAlluxioOnly);
options.setSkipConsistencyCheck(mSkipConsistencyCheck); options.setSkipConsistencyCheck(mUnchecked);
return options; return options;
} }
} }
Expand Up @@ -35,8 +35,8 @@ public void defaults() {
Assert.assertFalse(options.isRecursive()); Assert.assertFalse(options.isRecursive());
Assert.assertFalse(options.isAlluxioOnly()); Assert.assertFalse(options.isAlluxioOnly());
Assert.assertEquals( Assert.assertEquals(
Configuration.getBoolean(PropertyKey.USER_FILE_DELETE_SKIP_CONSISTENCY_CHECK), Configuration.getBoolean(PropertyKey.USER_FILE_DELETE_UNCHECKED),
options.isSkipConsistencyCheck()); options.isUnchecked());
} }


/** /**
Expand All @@ -52,10 +52,10 @@ public void fields() {


options.setRecursive(recursive); options.setRecursive(recursive);
options.setAlluxioOnly(alluxioOnly); options.setAlluxioOnly(alluxioOnly);
options.setSkipConsistencyCheck(skipCheck); options.setUnchecked(skipCheck);
Assert.assertEquals(recursive, options.isRecursive()); Assert.assertEquals(recursive, options.isRecursive());
Assert.assertEquals(alluxioOnly, options.isAlluxioOnly()); Assert.assertEquals(alluxioOnly, options.isAlluxioOnly());
Assert.assertEquals(skipCheck, options.isSkipConsistencyCheck()); Assert.assertEquals(skipCheck, options.isUnchecked());
} }


/** /**
Expand Down
8 changes: 4 additions & 4 deletions core/common/src/main/java/alluxio/PropertyKey.java
Expand Up @@ -461,8 +461,8 @@ public class PropertyKey {
create(Name.USER_FILE_BUFFER_BYTES, "1MB"); create(Name.USER_FILE_BUFFER_BYTES, "1MB");
public static final PropertyKey USER_FILE_CACHE_PARTIALLY_READ_BLOCK = public static final PropertyKey USER_FILE_CACHE_PARTIALLY_READ_BLOCK =
create(Name.USER_FILE_CACHE_PARTIALLY_READ_BLOCK, true); create(Name.USER_FILE_CACHE_PARTIALLY_READ_BLOCK, true);
public static final PropertyKey USER_FILE_DELETE_SKIP_CONSISTENCY_CHECK = public static final PropertyKey USER_FILE_DELETE_UNCHECKED =
create(Name.USER_FILE_DELETE_SKIP_CONSISTENCY_CHECK, false); create(Name.USER_FILE_DELETE_UNCHECKED, false);
public static final PropertyKey USER_FILE_MASTER_CLIENT_THREADS = public static final PropertyKey USER_FILE_MASTER_CLIENT_THREADS =
create(Name.USER_FILE_MASTER_CLIENT_THREADS, 10); create(Name.USER_FILE_MASTER_CLIENT_THREADS, 10);
public static final PropertyKey USER_FILE_PASSIVE_CACHE_ENABLED = public static final PropertyKey USER_FILE_PASSIVE_CACHE_ENABLED =
Expand Down Expand Up @@ -954,8 +954,8 @@ public static final class Name {
public static final String USER_FILE_BUFFER_BYTES = "alluxio.user.file.buffer.bytes"; public static final String USER_FILE_BUFFER_BYTES = "alluxio.user.file.buffer.bytes";
public static final String USER_FILE_CACHE_PARTIALLY_READ_BLOCK = public static final String USER_FILE_CACHE_PARTIALLY_READ_BLOCK =
"alluxio.user.file.cache.partially.read.block"; "alluxio.user.file.cache.partially.read.block";
public static final String USER_FILE_DELETE_SKIP_CONSISTENCY_CHECK = public static final String USER_FILE_DELETE_UNCHECKED =
"alluxio.user.file.delete.skip.consistency.check"; "alluxio.user.file.delete.unchecked";
public static final String USER_FILE_MASTER_CLIENT_THREADS = public static final String USER_FILE_MASTER_CLIENT_THREADS =
"alluxio.user.file.master.client.threads"; "alluxio.user.file.master.client.threads";
public static final String USER_FILE_PASSIVE_CACHE_ENABLED = public static final String USER_FILE_PASSIVE_CACHE_ENABLED =
Expand Down
Expand Up @@ -1176,7 +1176,7 @@ private void deleteInternal(LockedInodePath inodePath, boolean replayed, long op
new Pair<AlluxioURI, Inode<?>>(inodePath.getUri(), inode); new Pair<AlluxioURI, Inode<?>>(inodePath.getUri(), inode);
delInodes.add(inodePair); delInodes.add(inodePair);
if (inode.isPersisted() && !replayed && inode.isDirectory() if (inode.isPersisted() && !replayed && inode.isDirectory()
&& !mMountTable.isMountPoint(inodePath.getUri()) && (deleteOptions.isSkipConsistencyCheck() && !mMountTable.isMountPoint(inodePath.getUri()) && (deleteOptions.isUnchecked()
|| isUFSDeleteSafe(inodePath.getInode(), inodePath.getUri()))) { || isUFSDeleteSafe(inodePath.getInode(), inodePath.getUri()))) {
safeRecursiveUFSDeletes.put(inodePath.getUri(), inode); safeRecursiveUFSDeletes.put(inodePath.getUri(), inode);
} }
Expand All @@ -1190,7 +1190,7 @@ private void deleteInternal(LockedInodePath inodePath, boolean replayed, long op
delInodes.add(descendantPair); delInodes.add(descendantPair);
if (descendant.isPersisted() && !replayed && descendant.isDirectory() if (descendant.isPersisted() && !replayed && descendant.isDirectory()
&& !mMountTable.isMountPoint(descendantPath)) { && !mMountTable.isMountPoint(descendantPath)) {
if (deleteOptions.isSkipConsistencyCheck() if (deleteOptions.isUnchecked()
|| isUFSDeleteSafe(descendant, descendantPath)) { || isUFSDeleteSafe(descendant, descendantPath)) {
// Directory is a candidate for recursive deletes // Directory is a candidate for recursive deletes
safeRecursiveUFSDeletes.put(descendantPath, descendant); safeRecursiveUFSDeletes.put(descendantPath, descendant);
Expand Down
Expand Up @@ -350,7 +350,7 @@ public Void call() throws AlluxioException, IOException {
// NOTE, we try to be conservative here so early Alluxio clients will not be able to // NOTE, we try to be conservative here so early Alluxio clients will not be able to
// delete files in Alluxio only. // delete files in Alluxio only.
mFileSystemMaster.delete(new AlluxioURI(path), DeleteOptions.defaults() mFileSystemMaster.delete(new AlluxioURI(path), DeleteOptions.defaults()
.setRecursive(recursive).setSkipConsistencyCheck(options.isSkipConsistencyCheck())); .setRecursive(recursive).setUnchecked(options.isSkipConsistencyCheck()));
} else { } else {
mFileSystemMaster.delete(new AlluxioURI(path), new DeleteOptions(options)); mFileSystemMaster.delete(new AlluxioURI(path), new DeleteOptions(options));
} }
Expand Down
Expand Up @@ -24,7 +24,7 @@
public final class DeleteOptions { public final class DeleteOptions {
private boolean mRecursive; private boolean mRecursive;
private boolean mAlluxioOnly; private boolean mAlluxioOnly;
private boolean mSkipConsistencyCheck; private boolean mUnchecked;


/** /**
* @return the default {@link DeleteOptions} * @return the default {@link DeleteOptions}
Expand All @@ -39,13 +39,13 @@ public static DeleteOptions defaults() {
public DeleteOptions(DeleteTOptions options) { public DeleteOptions(DeleteTOptions options) {
mRecursive = options.isRecursive(); mRecursive = options.isRecursive();
mAlluxioOnly = options.isAlluxioOnly(); mAlluxioOnly = options.isAlluxioOnly();
mSkipConsistencyCheck = options.isSkipConsistencyCheck(); mUnchecked = options.isSkipConsistencyCheck();
} }


private DeleteOptions() { private DeleteOptions() {
mRecursive = false; mRecursive = false;
mAlluxioOnly = false; mAlluxioOnly = false;
mSkipConsistencyCheck = false; mUnchecked = false;
} }


/** /**
Expand All @@ -65,10 +65,10 @@ public boolean isAlluxioOnly() {
} }


/** /**
* @return if the UFS consistency check should be skipped * @return if the UFS sync check should be skipped
*/ */
public boolean isSkipConsistencyCheck() { public boolean isUnchecked() {
return mSkipConsistencyCheck; return mUnchecked;
} }
/** /**
* @param recursive the recursive flag value to use; if the object to be deleted is a directory, * @param recursive the recursive flag value to use; if the object to be deleted is a directory,
Expand All @@ -91,11 +91,11 @@ public DeleteOptions setAlluxioOnly(boolean alluxioOnly) {
} }


/** /**
* @param skipConsistencyCheck whether to skip UFS consistency check * @param skipCheck whether to skip UFS consistency check
* @return the updated options object * @return the updated options object
*/ */
public DeleteOptions setSkipConsistencyCheck(boolean skipConsistencyCheck) { public DeleteOptions setUnchecked(boolean skipCheck) {
mSkipConsistencyCheck = skipConsistencyCheck; mUnchecked = skipCheck;
return this; return this;
} }


Expand All @@ -110,20 +110,20 @@ public boolean equals(Object o) {
DeleteOptions that = (DeleteOptions) o; DeleteOptions that = (DeleteOptions) o;
return Objects.equal(mRecursive, that.mRecursive) return Objects.equal(mRecursive, that.mRecursive)
&& Objects.equal(mAlluxioOnly, that.mAlluxioOnly) && Objects.equal(mAlluxioOnly, that.mAlluxioOnly)
&& Objects.equal(mSkipConsistencyCheck, that.mSkipConsistencyCheck); && Objects.equal(mUnchecked, that.mUnchecked);
} }


@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hashCode(mRecursive, mAlluxioOnly, mSkipConsistencyCheck); return Objects.hashCode(mRecursive, mAlluxioOnly, mUnchecked);
} }


@Override @Override
public String toString() { public String toString() {
return Objects.toStringHelper(this) return Objects.toStringHelper(this)
.add("recursive", mRecursive) .add("recursive", mRecursive)
.add("alluxioOnly", mAlluxioOnly) .add("alluxioOnly", mAlluxioOnly)
.add("skipConsistencyCheck", mSkipConsistencyCheck) .add("skipConsistencyCheck", mUnchecked)
.toString(); .toString();
} }
} }
Expand Up @@ -31,7 +31,7 @@ public void defaults() throws Exception {
DeleteOptions options = DeleteOptions.defaults(); DeleteOptions options = DeleteOptions.defaults();
Assert.assertFalse(options.isRecursive()); Assert.assertFalse(options.isRecursive());
Assert.assertFalse(options.isAlluxioOnly()); Assert.assertFalse(options.isAlluxioOnly());
Assert.assertFalse(options.isSkipConsistencyCheck()); Assert.assertFalse(options.isUnchecked());
} }


/** /**
Expand All @@ -47,11 +47,11 @@ public void fields() throws Exception {


options.setRecursive(recursive); options.setRecursive(recursive);
options.setAlluxioOnly(alluxioOnly); options.setAlluxioOnly(alluxioOnly);
options.setSkipConsistencyCheck(skipCheck); options.setUnchecked(skipCheck);


Assert.assertEquals(recursive, options.isRecursive()); Assert.assertEquals(recursive, options.isRecursive());
Assert.assertEquals(alluxioOnly, options.isAlluxioOnly()); Assert.assertEquals(alluxioOnly, options.isAlluxioOnly());
Assert.assertEquals(skipCheck, options.isSkipConsistencyCheck()); Assert.assertEquals(skipCheck, options.isUnchecked());
} }


@Test @Test
Expand Down
Expand Up @@ -67,12 +67,12 @@ public abstract class AbstractShellCommand implements ShellCommand {
.desc("print human-readable format sizes") .desc("print human-readable format sizes")
.build(); .build();


protected static final String REMOVE_INCONSISTENT_OPTION_CHAR = "I"; protected static final String REMOVE_UNCHECKED_OPTION_CHAR = "U";
protected static final Option REMOVE_INCONSISTENT_OPTION = protected static final Option REMOVE_UNCHECKED_OPTION =
Option.builder(REMOVE_INCONSISTENT_OPTION_CHAR) Option.builder(REMOVE_UNCHECKED_OPTION_CHAR)
.required(false) .required(false)
.hasArg(false) .hasArg(false)
.desc("remove inconsistent directories") .desc("remove directories without checking UFS contents are in sync")
.build(); .build();


protected AbstractShellCommand(FileSystem fs) { protected AbstractShellCommand(FileSystem fs) {
Expand Down
6 changes: 3 additions & 3 deletions shell/src/main/java/alluxio/shell/command/RmCommand.java
Expand Up @@ -50,7 +50,7 @@ protected int getNumOfArgs() {


@Override @Override
public Options getOptions() { public Options getOptions() {
return new Options().addOption(RECURSIVE_OPTION).addOption(REMOVE_INCONSISTENT_OPTION); return new Options().addOption(RECURSIVE_OPTION).addOption(REMOVE_UNCHECKED_OPTION);
} }


@Override @Override
Expand All @@ -66,8 +66,8 @@ protected void runCommand(AlluxioURI path, CommandLine cl) throws AlluxioExcepti
} }


DeleteOptions options = DeleteOptions.defaults().setRecursive(recursive); DeleteOptions options = DeleteOptions.defaults().setRecursive(recursive);
if (cl.hasOption(REMOVE_INCONSISTENT_OPTION_CHAR)) { if (cl.hasOption(REMOVE_UNCHECKED_OPTION_CHAR)) {
options.setSkipConsistencyCheck(true); options.setUnchecked(true);
} }
mFileSystem.delete(path, options); mFileSystem.delete(path, options);
System.out.println(path + " has been removed"); System.out.println(path + " has been removed");
Expand Down

0 comments on commit 56f407b

Please sign in to comment.