From 56f407b99762e095781c6d65dd5fbb9257800c85 Mon Sep 17 00:00:00 2001 From: madanadit Date: Mon, 1 May 2017 17:53:04 -0700 Subject: [PATCH] refactor --- .../client/file/options/DeleteOptions.java | 26 +++++++++---------- .../file/options/DeleteOptionsTest.java | 8 +++--- .../src/main/java/alluxio/PropertyKey.java | 8 +++--- .../master/file/DefaultFileSystemMaster.java | 4 +-- .../FileSystemMasterClientServiceHandler.java | 2 +- .../master/file/options/DeleteOptions.java | 24 ++++++++--------- .../file/options/DeleteOptionsTest.java | 6 ++--- .../shell/command/AbstractShellCommand.java | 8 +++--- .../java/alluxio/shell/command/RmCommand.java | 6 ++--- 9 files changed, 46 insertions(+), 46 deletions(-) diff --git a/core/client/src/main/java/alluxio/client/file/options/DeleteOptions.java b/core/client/src/main/java/alluxio/client/file/options/DeleteOptions.java index 66659ee74cd0..39de80de567b 100644 --- a/core/client/src/main/java/alluxio/client/file/options/DeleteOptions.java +++ b/core/client/src/main/java/alluxio/client/file/options/DeleteOptions.java @@ -31,7 +31,7 @@ public final class DeleteOptions { private boolean mRecursive; private boolean mAlluxioOnly; - private boolean mSkipConsistencyCheck; + private boolean mUnchecked; /** * @return the default {@link DeleteOptions} @@ -43,8 +43,8 @@ public static DeleteOptions defaults() { private DeleteOptions() { mRecursive = false; mAlluxioOnly = false; - mSkipConsistencyCheck = - Configuration.getBoolean(PropertyKey.USER_FILE_DELETE_SKIP_CONSISTENCY_CHECK); + mUnchecked = + Configuration.getBoolean(PropertyKey.USER_FILE_DELETE_UNCHECKED); } /** @@ -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() { - return mSkipConsistencyCheck; + public boolean isUnchecked() { + return mUnchecked; } /** @@ -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 */ - public DeleteOptions setSkipConsistencyCheck(boolean skipConsistencyCheck) { - mSkipConsistencyCheck = skipConsistencyCheck; + public DeleteOptions setUnchecked(boolean unchecked) { + mUnchecked = unchecked; return this; } @@ -110,12 +110,12 @@ public boolean equals(Object o) { DeleteOptions that = (DeleteOptions) o; return Objects.equal(mRecursive, that.mRecursive) && Objects.equal(mAlluxioOnly, that.mAlluxioOnly) - && Objects.equal(mSkipConsistencyCheck, that.mSkipConsistencyCheck); + && Objects.equal(mUnchecked, that.mUnchecked); } @Override public int hashCode() { - return Objects.hashCode(mRecursive, mAlluxioOnly, mSkipConsistencyCheck); + return Objects.hashCode(mRecursive, mAlluxioOnly, mUnchecked); } @Override @@ -123,7 +123,7 @@ public String toString() { return Objects.toStringHelper(this) .add("recursive", mRecursive) .add("alluxioOnly", mAlluxioOnly) - .add("skipConsistencyCheck", mSkipConsistencyCheck) + .add("skipConsistencyCheck", mUnchecked) .toString(); } @@ -134,7 +134,7 @@ public DeleteTOptions toThrift() { DeleteTOptions options = new DeleteTOptions(); options.setRecursive(mRecursive); options.setAlluxioOnly(mAlluxioOnly); - options.setSkipConsistencyCheck(mSkipConsistencyCheck); + options.setSkipConsistencyCheck(mUnchecked); return options; } } diff --git a/core/client/src/test/java/alluxio/client/file/options/DeleteOptionsTest.java b/core/client/src/test/java/alluxio/client/file/options/DeleteOptionsTest.java index 7269a519c7aa..fb05dd61d07a 100644 --- a/core/client/src/test/java/alluxio/client/file/options/DeleteOptionsTest.java +++ b/core/client/src/test/java/alluxio/client/file/options/DeleteOptionsTest.java @@ -35,8 +35,8 @@ public void defaults() { Assert.assertFalse(options.isRecursive()); Assert.assertFalse(options.isAlluxioOnly()); Assert.assertEquals( - Configuration.getBoolean(PropertyKey.USER_FILE_DELETE_SKIP_CONSISTENCY_CHECK), - options.isSkipConsistencyCheck()); + Configuration.getBoolean(PropertyKey.USER_FILE_DELETE_UNCHECKED), + options.isUnchecked()); } /** @@ -52,10 +52,10 @@ public void fields() { options.setRecursive(recursive); options.setAlluxioOnly(alluxioOnly); - options.setSkipConsistencyCheck(skipCheck); + options.setUnchecked(skipCheck); Assert.assertEquals(recursive, options.isRecursive()); Assert.assertEquals(alluxioOnly, options.isAlluxioOnly()); - Assert.assertEquals(skipCheck, options.isSkipConsistencyCheck()); + Assert.assertEquals(skipCheck, options.isUnchecked()); } /** diff --git a/core/common/src/main/java/alluxio/PropertyKey.java b/core/common/src/main/java/alluxio/PropertyKey.java index 86f529dbcccb..8b591f39cfce 100644 --- a/core/common/src/main/java/alluxio/PropertyKey.java +++ b/core/common/src/main/java/alluxio/PropertyKey.java @@ -461,8 +461,8 @@ public class PropertyKey { create(Name.USER_FILE_BUFFER_BYTES, "1MB"); public static final PropertyKey USER_FILE_CACHE_PARTIALLY_READ_BLOCK = create(Name.USER_FILE_CACHE_PARTIALLY_READ_BLOCK, true); - public static final PropertyKey USER_FILE_DELETE_SKIP_CONSISTENCY_CHECK = - create(Name.USER_FILE_DELETE_SKIP_CONSISTENCY_CHECK, false); + public static final PropertyKey USER_FILE_DELETE_UNCHECKED = + create(Name.USER_FILE_DELETE_UNCHECKED, false); public static final PropertyKey USER_FILE_MASTER_CLIENT_THREADS = create(Name.USER_FILE_MASTER_CLIENT_THREADS, 10); public static final PropertyKey USER_FILE_PASSIVE_CACHE_ENABLED = @@ -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_CACHE_PARTIALLY_READ_BLOCK = "alluxio.user.file.cache.partially.read.block"; - public static final String USER_FILE_DELETE_SKIP_CONSISTENCY_CHECK = - "alluxio.user.file.delete.skip.consistency.check"; + public static final String USER_FILE_DELETE_UNCHECKED = + "alluxio.user.file.delete.unchecked"; public static final String USER_FILE_MASTER_CLIENT_THREADS = "alluxio.user.file.master.client.threads"; public static final String USER_FILE_PASSIVE_CACHE_ENABLED = diff --git a/core/server/master/src/main/java/alluxio/master/file/DefaultFileSystemMaster.java b/core/server/master/src/main/java/alluxio/master/file/DefaultFileSystemMaster.java index ecd9a2822214..e0078278914b 100644 --- a/core/server/master/src/main/java/alluxio/master/file/DefaultFileSystemMaster.java +++ b/core/server/master/src/main/java/alluxio/master/file/DefaultFileSystemMaster.java @@ -1176,7 +1176,7 @@ private void deleteInternal(LockedInodePath inodePath, boolean replayed, long op new Pair>(inodePath.getUri(), inode); delInodes.add(inodePair); if (inode.isPersisted() && !replayed && inode.isDirectory() - && !mMountTable.isMountPoint(inodePath.getUri()) && (deleteOptions.isSkipConsistencyCheck() + && !mMountTable.isMountPoint(inodePath.getUri()) && (deleteOptions.isUnchecked() || isUFSDeleteSafe(inodePath.getInode(), inodePath.getUri()))) { safeRecursiveUFSDeletes.put(inodePath.getUri(), inode); } @@ -1190,7 +1190,7 @@ private void deleteInternal(LockedInodePath inodePath, boolean replayed, long op delInodes.add(descendantPair); if (descendant.isPersisted() && !replayed && descendant.isDirectory() && !mMountTable.isMountPoint(descendantPath)) { - if (deleteOptions.isSkipConsistencyCheck() + if (deleteOptions.isUnchecked() || isUFSDeleteSafe(descendant, descendantPath)) { // Directory is a candidate for recursive deletes safeRecursiveUFSDeletes.put(descendantPath, descendant); diff --git a/core/server/master/src/main/java/alluxio/master/file/FileSystemMasterClientServiceHandler.java b/core/server/master/src/main/java/alluxio/master/file/FileSystemMasterClientServiceHandler.java index 68ce596f056a..1cb3d05ef493 100644 --- a/core/server/master/src/main/java/alluxio/master/file/FileSystemMasterClientServiceHandler.java +++ b/core/server/master/src/main/java/alluxio/master/file/FileSystemMasterClientServiceHandler.java @@ -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 // delete files in Alluxio only. mFileSystemMaster.delete(new AlluxioURI(path), DeleteOptions.defaults() - .setRecursive(recursive).setSkipConsistencyCheck(options.isSkipConsistencyCheck())); + .setRecursive(recursive).setUnchecked(options.isSkipConsistencyCheck())); } else { mFileSystemMaster.delete(new AlluxioURI(path), new DeleteOptions(options)); } diff --git a/core/server/master/src/main/java/alluxio/master/file/options/DeleteOptions.java b/core/server/master/src/main/java/alluxio/master/file/options/DeleteOptions.java index 675be595f5c5..3790b7f5677b 100644 --- a/core/server/master/src/main/java/alluxio/master/file/options/DeleteOptions.java +++ b/core/server/master/src/main/java/alluxio/master/file/options/DeleteOptions.java @@ -24,7 +24,7 @@ public final class DeleteOptions { private boolean mRecursive; private boolean mAlluxioOnly; - private boolean mSkipConsistencyCheck; + private boolean mUnchecked; /** * @return the default {@link DeleteOptions} @@ -39,13 +39,13 @@ public static DeleteOptions defaults() { public DeleteOptions(DeleteTOptions options) { mRecursive = options.isRecursive(); mAlluxioOnly = options.isAlluxioOnly(); - mSkipConsistencyCheck = options.isSkipConsistencyCheck(); + mUnchecked = options.isSkipConsistencyCheck(); } private DeleteOptions() { mRecursive = false; mAlluxioOnly = false; - mSkipConsistencyCheck = false; + mUnchecked = false; } /** @@ -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() { - return mSkipConsistencyCheck; + public boolean isUnchecked() { + return mUnchecked; } /** * @param recursive the recursive flag value to use; if the object to be deleted is a directory, @@ -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 */ - public DeleteOptions setSkipConsistencyCheck(boolean skipConsistencyCheck) { - mSkipConsistencyCheck = skipConsistencyCheck; + public DeleteOptions setUnchecked(boolean skipCheck) { + mUnchecked = skipCheck; return this; } @@ -110,12 +110,12 @@ public boolean equals(Object o) { DeleteOptions that = (DeleteOptions) o; return Objects.equal(mRecursive, that.mRecursive) && Objects.equal(mAlluxioOnly, that.mAlluxioOnly) - && Objects.equal(mSkipConsistencyCheck, that.mSkipConsistencyCheck); + && Objects.equal(mUnchecked, that.mUnchecked); } @Override public int hashCode() { - return Objects.hashCode(mRecursive, mAlluxioOnly, mSkipConsistencyCheck); + return Objects.hashCode(mRecursive, mAlluxioOnly, mUnchecked); } @Override @@ -123,7 +123,7 @@ public String toString() { return Objects.toStringHelper(this) .add("recursive", mRecursive) .add("alluxioOnly", mAlluxioOnly) - .add("skipConsistencyCheck", mSkipConsistencyCheck) + .add("skipConsistencyCheck", mUnchecked) .toString(); } } diff --git a/core/server/master/src/test/java/alluxio/master/file/options/DeleteOptionsTest.java b/core/server/master/src/test/java/alluxio/master/file/options/DeleteOptionsTest.java index 40938c4c8a11..f138785ae23e 100644 --- a/core/server/master/src/test/java/alluxio/master/file/options/DeleteOptionsTest.java +++ b/core/server/master/src/test/java/alluxio/master/file/options/DeleteOptionsTest.java @@ -31,7 +31,7 @@ public void defaults() throws Exception { DeleteOptions options = DeleteOptions.defaults(); Assert.assertFalse(options.isRecursive()); Assert.assertFalse(options.isAlluxioOnly()); - Assert.assertFalse(options.isSkipConsistencyCheck()); + Assert.assertFalse(options.isUnchecked()); } /** @@ -47,11 +47,11 @@ public void fields() throws Exception { options.setRecursive(recursive); options.setAlluxioOnly(alluxioOnly); - options.setSkipConsistencyCheck(skipCheck); + options.setUnchecked(skipCheck); Assert.assertEquals(recursive, options.isRecursive()); Assert.assertEquals(alluxioOnly, options.isAlluxioOnly()); - Assert.assertEquals(skipCheck, options.isSkipConsistencyCheck()); + Assert.assertEquals(skipCheck, options.isUnchecked()); } @Test diff --git a/shell/src/main/java/alluxio/shell/command/AbstractShellCommand.java b/shell/src/main/java/alluxio/shell/command/AbstractShellCommand.java index 0b3f157fe099..a08446b3af84 100644 --- a/shell/src/main/java/alluxio/shell/command/AbstractShellCommand.java +++ b/shell/src/main/java/alluxio/shell/command/AbstractShellCommand.java @@ -67,12 +67,12 @@ public abstract class AbstractShellCommand implements ShellCommand { .desc("print human-readable format sizes") .build(); - protected static final String REMOVE_INCONSISTENT_OPTION_CHAR = "I"; - protected static final Option REMOVE_INCONSISTENT_OPTION = - Option.builder(REMOVE_INCONSISTENT_OPTION_CHAR) + protected static final String REMOVE_UNCHECKED_OPTION_CHAR = "U"; + protected static final Option REMOVE_UNCHECKED_OPTION = + Option.builder(REMOVE_UNCHECKED_OPTION_CHAR) .required(false) .hasArg(false) - .desc("remove inconsistent directories") + .desc("remove directories without checking UFS contents are in sync") .build(); protected AbstractShellCommand(FileSystem fs) { diff --git a/shell/src/main/java/alluxio/shell/command/RmCommand.java b/shell/src/main/java/alluxio/shell/command/RmCommand.java index 251e126e55b3..634a3414ec9a 100644 --- a/shell/src/main/java/alluxio/shell/command/RmCommand.java +++ b/shell/src/main/java/alluxio/shell/command/RmCommand.java @@ -50,7 +50,7 @@ protected int getNumOfArgs() { @Override public Options getOptions() { - return new Options().addOption(RECURSIVE_OPTION).addOption(REMOVE_INCONSISTENT_OPTION); + return new Options().addOption(RECURSIVE_OPTION).addOption(REMOVE_UNCHECKED_OPTION); } @Override @@ -66,8 +66,8 @@ protected void runCommand(AlluxioURI path, CommandLine cl) throws AlluxioExcepti } DeleteOptions options = DeleteOptions.defaults().setRecursive(recursive); - if (cl.hasOption(REMOVE_INCONSISTENT_OPTION_CHAR)) { - options.setSkipConsistencyCheck(true); + if (cl.hasOption(REMOVE_UNCHECKED_OPTION_CHAR)) { + options.setUnchecked(true); } mFileSystem.delete(path, options); System.out.println(path + " has been removed");