Skip to content

Commit 19a0018

Browse files
committed
Revert "HDFS-9913. DistCp to add -useTrash to move deleted files to Trash."
Reverting due to test failures if ~/.Trash not present during test setup. This reverts commit ee3115f. Change-Id: Icbeeb261570b9131ff99d765ac0945c335b26658
1 parent ee3115f commit 19a0018

File tree

11 files changed

+9
-262
lines changed

11 files changed

+9
-262
lines changed

hadoop-tools/hadoop-distcp/src/main/java/org/apache/hadoop/tools/DistCpConstants.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ private DistCpConstants() {
6161
public static final String CONF_LABEL_DELETE_MISSING = "distcp.delete.missing.source";
6262
public static final String CONF_LABEL_TRACK_MISSING =
6363
"distcp.track.missing.source";
64-
public static final String CONF_LABEL_DELETE_MISSING_USETRASH =
65-
"distcp.delete.missing.usetrash";
6664
public static final String CONF_LABEL_LISTSTATUS_THREADS = "distcp.liststatus.threads";
6765
public static final String CONF_LABEL_MAX_MAPS = "distcp.max.maps";
6866
public static final String CONF_LABEL_SOURCE_LISTING = "distcp.source.listing";

hadoop-tools/hadoop-distcp/src/main/java/org/apache/hadoop/tools/DistCpOptionSwitch.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,6 @@ public enum DistCpOptionSwitch {
7676
new Option("delete", false, "Delete from target, " +
7777
"files missing in source. Delete is applicable only with update or overwrite options")),
7878

79-
/**
80-
* When -delete option on, files in target that are missing from source
81-
* will be delete by default. This allows the files to be
82-
* moved to the trash
83-
*/
84-
DELETE_USETRASH(DistCpConstants.CONF_LABEL_DELETE_MISSING_USETRASH,
85-
new Option("useTrash", false, "Move deleted files into " +
86-
"the user's trash directory in the destination filesystem")),
87-
8879
/**
8980
* Track missing files in target that are missing from source
9081
* This allows for other applications to complete the synchronization,

hadoop-tools/hadoop-distcp/src/main/java/org/apache/hadoop/tools/DistCpOptions.java

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,6 @@ public final class DistCpOptions {
9595
/** Whether to run blocking or non-blocking. */
9696
private final boolean blocking;
9797

98-
private boolean deleteUseTrash;
99-
10098
// When "-diff s1 s2 src tgt" is passed, apply forward snapshot diff (from s1
10199
// to s2) of source cluster to the target cluster to sync target cluster with
102100
// the source cluster. Referred to as "Fdiff" in the code.
@@ -223,7 +221,6 @@ private DistCpOptions(Builder builder) {
223221
this.trackPath = builder.trackPath;
224222

225223
this.directWrite = builder.directWrite;
226-
this.deleteUseTrash = builder.deleteUseTrash;
227224
}
228225

229226
public Path getSourceFileListing() {
@@ -287,10 +284,6 @@ public boolean shouldUseSnapshotDiff() {
287284
return shouldUseDiff() || shouldUseRdiff();
288285
}
289286

290-
public boolean shouldDeleteUseTrash() {
291-
return deleteUseTrash;
292-
}
293-
294287
public String getFromSnapshot() {
295288
return this.fromSnapshot;
296289
}
@@ -381,8 +374,6 @@ public void appendToConf(Configuration conf) {
381374
String.valueOf(useDiff));
382375
DistCpOptionSwitch.addToConf(conf, DistCpOptionSwitch.RDIFF,
383376
String.valueOf(useRdiff));
384-
DistCpOptionSwitch.addToConf(conf, DistCpOptionSwitch.DELETE_USETRASH,
385-
String.valueOf(deleteUseTrash));
386377
DistCpOptionSwitch.addToConf(conf, DistCpOptionSwitch.SKIP_CRC,
387378
String.valueOf(skipCRC));
388379
if (mapBandwidth > 0) {
@@ -424,7 +415,6 @@ public String toString() {
424415
"atomicCommit=" + atomicCommit +
425416
", syncFolder=" + syncFolder +
426417
", deleteMissing=" + deleteMissing +
427-
", deleteUseTrash=" + deleteUseTrash +
428418
", ignoreFailures=" + ignoreFailures +
429419
", overwrite=" + overwrite +
430420
", append=" + append +
@@ -477,8 +467,6 @@ public static class Builder {
477467

478468
private boolean useDiff = false;
479469
private boolean useRdiff = false;
480-
private boolean deleteUseTrash = false;
481-
482470
private String fromSnapshot;
483471
private String toSnapshot;
484472

@@ -576,11 +564,6 @@ private void validate() {
576564
+ "only with update or overwrite options");
577565
}
578566

579-
if (deleteUseTrash && !deleteMissing) {
580-
throw new IllegalArgumentException("Delete useTrash is applicable "
581-
+ "only with delete option");
582-
}
583-
584567
if (overwrite && syncFolder) {
585568
throw new IllegalArgumentException("Overwrite and update options are "
586569
+ "mutually exclusive");
@@ -644,11 +627,6 @@ public Builder withDeleteMissing(boolean newDeleteMissing) {
644627
return this;
645628
}
646629

647-
public Builder withDeleteUseTrash(boolean newDeleteUseTrash) {
648-
this.deleteUseTrash = newDeleteUseTrash;
649-
return this;
650-
}
651-
652630
public Builder withIgnoreFailures(boolean newIgnoreFailures) {
653631
this.ignoreFailures = newIgnoreFailures;
654632
return this;

hadoop-tools/hadoop-distcp/src/main/java/org/apache/hadoop/tools/OptionsParser.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,6 @@ public static DistCpOptions parse(String[] args)
102102
command.hasOption(DistCpOptionSwitch.SYNC_FOLDERS.getSwitch()))
103103
.withDeleteMissing(
104104
command.hasOption(DistCpOptionSwitch.DELETE_MISSING.getSwitch()))
105-
.withDeleteUseTrash(
106-
command.hasOption(DistCpOptionSwitch.DELETE_USETRASH.getSwitch()))
107105
.withIgnoreFailures(
108106
command.hasOption(DistCpOptionSwitch.IGNORE_FAILURES.getSwitch()))
109107
.withOverwrite(
@@ -155,9 +153,6 @@ public static DistCpOptions parse(String[] args)
155153
command,
156154
DistCpOptionSwitch.TRACK_MISSING.getSwitch())));
157155
}
158-
if (command.hasOption(DistCpOptionSwitch.DELETE_USETRASH.getSwitch())) {
159-
builder.withDeleteUseTrash(true);
160-
}
161156

162157
if (command.hasOption(DistCpOptionSwitch.BANDWIDTH.getSwitch())) {
163158
try {

hadoop-tools/hadoop-distcp/src/main/java/org/apache/hadoop/tools/mapred/CopyCommitter.java

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import org.apache.hadoop.fs.FileStatus;
2626
import org.apache.hadoop.fs.FileSystem;
2727
import org.apache.hadoop.fs.Path;
28-
import org.apache.hadoop.fs.Trash;
2928
import org.apache.hadoop.io.IOUtils;
3029
import org.apache.hadoop.io.SequenceFile;
3130
import org.apache.hadoop.io.Text;
@@ -454,8 +453,7 @@ private void deleteMissing(Configuration conf) throws IOException {
454453
if (tracker.shouldDelete(trgtFileStatus)) {
455454
showProgress = true;
456455
try {
457-
boolean result = deletePath(targetFS, targetEntry, conf);
458-
if (result) {
456+
if (targetFS.delete(targetEntry, true)) {
459457
// the delete worked. Unless the file is actually missing, this is the
460458
LOG.info("Deleted " + targetEntry + " - missing at source");
461459
deletedEntries++;
@@ -469,8 +467,7 @@ private void deleteMissing(Configuration conf) throws IOException {
469467
// For all the filestores which implement the FS spec properly,
470468
// this means "the file wasn't there".
471469
// so track but don't worry about it.
472-
LOG.info("delete({}) returned false ({}). Consider using " +
473-
"-useTrash option if trash is enabled.",
470+
LOG.info("delete({}) returned false ({})",
474471
targetEntry, trgtFileStatus);
475472
missingDeletes++;
476473
}
@@ -518,17 +515,6 @@ private void deleteMissing(Configuration conf) throws IOException {
518515
formatDuration(deletionEnd - listingStart));
519516
}
520517

521-
private boolean deletePath(FileSystem targetFS, Path targetEntry,
522-
Configuration conf) throws IOException {
523-
if (conf.getBoolean(DistCpConstants.CONF_LABEL_DELETE_MISSING_USETRASH,
524-
false)) {
525-
return Trash.moveToAppropriateTrash(
526-
targetFS, targetEntry, conf);
527-
} else {
528-
return targetFS.delete(targetEntry, true);
529-
}
530-
}
531-
532518
/**
533519
* Take a duration and return a human-readable duration of
534520
* hours:minutes:seconds.millis.

hadoop-tools/hadoop-distcp/src/site/markdown/DistCp.md.vm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ Command Line Options
349349
| `-filters` | The path to a file containing a list of pattern strings, one string per line, such that paths matching the pattern will be excluded from the copy. | Support regular expressions specified by java.util.regex.Pattern. |
350350
| `-filelimit <n>` | Limit the total number of files to be <= n | **Deprecated!** Ignored in the new DistCp. |
351351
| `-sizelimit <n>` | Limit the total size to be <= n bytes | **Deprecated!** Ignored in the new DistCp. |
352-
| `-delete [-useTrash]` | Delete the files existing in the `/dst/` but not in `/src/` . when `[-useTrash]` is enabled, the files will be moved into the user's trash directory. Notice that `[-useTrash]` option on some object store does a copy and delete ops and can be slow. Delete is applicable only with update or overwrite options. |
352+
| `-delete` | Delete the files existing in the dst but not in src | The deletion is done by FS Shell. So the trash will be used, if it is enable. Delete is applicable only with update or overwrite options. |
353353
| `-strategy {dynamic|uniformsize}` | Choose the copy-strategy to be used in DistCp. | By default, uniformsize is used. (i.e. Maps are balanced on the total size of files copied by each map. Similar to legacy.) If "dynamic" is specified, `DynamicInputFormat` is used instead. (This is described in the Architecture section, under InputFormats.) |
354354
| `-bandwidth` | Specify bandwidth per map, in MB/second. | Each map will be restricted to consume only the specified bandwidth. This is not always exact. The map throttles back its bandwidth consumption during a copy, such that the **net** bandwidth used tends towards the specified value. |
355355
| `-atomic {-tmp <tmp_dir>}` | Specify atomic commit, with optional tmp directory. | `-atomic` instructs DistCp to copy the source data to a temporary target location, and then move the temporary target to the final-location atomically. Data will either be available at final target in a complete and consistent form, or not at all. Optionally, `-tmp` may be used to specify the location of the tmp-target. If not specified, a default is chosen. **Note:** tmp_dir must be on the final target cluster. |

hadoop-tools/hadoop-distcp/src/test/java/org/apache/hadoop/tools/TestDistCpOptions.java

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,10 @@
2121
import java.util.Collections;
2222

2323
import org.apache.hadoop.conf.Configuration;
24-
2524
import org.junit.Assert;
2625
import org.junit.Test;
2726

2827
import org.apache.hadoop.fs.Path;
29-
import org.apache.hadoop.test.LambdaTestUtils;
3028
import org.apache.hadoop.tools.DistCpOptions.FileAttribute;
3129

3230
import static org.apache.hadoop.test.GenericTestUtils.assertExceptionContains;
@@ -227,42 +225,6 @@ public void testSetDeleteMissing() {
227225
}
228226
}
229227

230-
@Test
231-
public void testDeleteMissingUseTrash() throws Exception {
232-
final DistCpOptions.Builder builder = new DistCpOptions.Builder(
233-
Collections.singletonList(new Path("hdfs://localhost:8020/source")),
234-
new Path("hdfs://localhost:8020/target/"));
235-
Assert.assertFalse("Delete does not use trash by default.",
236-
builder.build().shouldDeleteUseTrash());
237-
238-
DistCpOptions options = builder.withSyncFolder(true)
239-
.withDeleteMissing(true)
240-
.withDeleteUseTrash(true)
241-
.build();
242-
Assert.assertTrue(options.shouldSyncFolder());
243-
Assert.assertTrue(options.shouldDeleteMissing());
244-
Assert.assertTrue(options.shouldDeleteUseTrash());
245-
246-
options = new DistCpOptions.Builder(
247-
Collections.singletonList(new Path("hdfs://localhost:8020/source")),
248-
new Path("hdfs://localhost:8020/target/"))
249-
.withOverwrite(true)
250-
.withDeleteMissing(true)
251-
.withDeleteUseTrash(true)
252-
.build();
253-
254-
Assert.assertTrue(options.shouldDeleteUseTrash());
255-
Assert.assertTrue(options.shouldOverwrite());
256-
Assert.assertTrue(options.shouldDeleteMissing());
257-
258-
LambdaTestUtils.intercept(IllegalArgumentException.class,
259-
() -> new DistCpOptions.Builder(Collections.singletonList(
260-
new Path("hdfs://localhost:8020/source")),
261-
new Path("hdfs://localhost:8020/target/"))
262-
.withDeleteUseTrash(true)
263-
.build());
264-
}
265-
266228
@Test
267229
public void testSetMaps() {
268230
final DistCpOptions.Builder builder = new DistCpOptions.Builder(
@@ -319,8 +281,8 @@ public void testToString() {
319281
DistCpOptions option = new DistCpOptions.Builder(new Path("abc"),
320282
new Path("xyz")).build();
321283
String val = "DistCpOptions{atomicCommit=false, syncFolder=false, " +
322-
"deleteMissing=false, deleteUseTrash=false, ignoreFailures=false, " +
323-
"overwrite=false, append=false, useDiff=false, useRdiff=false, " +
284+
"deleteMissing=false, ignoreFailures=false, overwrite=false, " +
285+
"append=false, useDiff=false, useRdiff=false, " +
324286
"fromSnapshot=null, toSnapshot=null, " +
325287
"skipCRC=false, blocking=true, numListstatusThreads=0, maxMaps=20, " +
326288
"mapBandwidth=0.0, copyStrategy='uniformsize', preserveStatus=[], " +

hadoop-tools/hadoop-distcp/src/test/java/org/apache/hadoop/tools/TestIntegration.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ public void testDeleteMissingInDestination() {
348348
createFiles("srcdir/file1", "dstdir/file1", "dstdir/file2");
349349

350350
Path target = new Path(root + "/dstdir");
351-
runTest(listFile, target, false, true, true, false, false);
351+
runTest(listFile, target, false, true, true, false);
352352

353353
checkResult(target, 1, "file1");
354354
} catch (IOException e) {
@@ -372,7 +372,7 @@ public void testOverwrite() {
372372
createWithContents("dstdir/file1", contents2);
373373

374374
Path target = new Path(root + "/dstdir");
375-
runTest(listFile, target, false, false, false, true, false);
375+
runTest(listFile, target, false, false, false, true);
376376

377377
checkResult(target, 1, "file1");
378378

@@ -553,16 +553,15 @@ private void mkdirs(String... entries) throws IOException {
553553

554554
private void runTest(Path listFile, Path target, boolean targetExists,
555555
boolean sync) throws IOException {
556-
runTest(listFile, target, targetExists, sync, false, false, false);
556+
runTest(listFile, target, targetExists, sync, false, false);
557557
}
558558

559559
private void runTest(Path listFile, Path target, boolean targetExists,
560560
boolean sync, boolean delete,
561-
boolean overwrite, boolean useTrash) throws IOException {
561+
boolean overwrite) throws IOException {
562562
final DistCpOptions options = new DistCpOptions.Builder(listFile, target)
563563
.withSyncFolder(sync)
564564
.withDeleteMissing(delete)
565-
.withDeleteUseTrash(useTrash)
566565
.withOverwrite(overwrite)
567566
.withNumListstatusThreads(numListstatusThreads)
568567
.build();

hadoop-tools/hadoop-distcp/src/test/java/org/apache/hadoop/tools/TestOptionsParser.java

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -802,23 +802,4 @@ public void testExclusionsOption() {
802802
"hdfs://localhost:8020/target/"});
803803
Assert.assertEquals(options.getFiltersFile(), "/tmp/filters.txt");
804804
}
805-
806-
@Test
807-
public void testParseDeleteSkipTrash() {
808-
DistCpOptions options = OptionsParser.parse(new String[] {
809-
"-overwrite",
810-
"-delete",
811-
"-useTrash",
812-
"hdfs://localhost:8020/source/first",
813-
"hdfs://localhost:8020/target/"});
814-
Assert.assertTrue("Delete with useTrash.",
815-
options.shouldDeleteUseTrash());
816-
options = OptionsParser.parse(new String[] {
817-
"-overwrite",
818-
"-delete",
819-
"hdfs://localhost:8020/source/first",
820-
"hdfs://localhost:8020/target/"});
821-
Assert.assertFalse("Delete does not use trash.",
822-
options.shouldDeleteUseTrash());
823-
}
824805
}

0 commit comments

Comments
 (0)