Skip to content

Commit 9faccd1

Browse files
HADOOP-13587. distcp.map.bandwidth.mb is overwritten even when -bandwidth flag isn't set. Contributed by Zoran Dimitrijevic
1 parent cc01ed7 commit 9faccd1

File tree

3 files changed

+70
-6
lines changed

3 files changed

+70
-6
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public class DistCp extends Configured implements Tool {
7171
private static final String PREFIX = "_distcp";
7272
private static final String WIP_PREFIX = "._WIP_";
7373
private static final String DISTCP_DEFAULT_XML = "distcp-default.xml";
74+
private static final String DISTCP_SITE_XML = "distcp-site.xml";
7475
static final Random rand = new Random();
7576

7677
private boolean submitted;
@@ -86,6 +87,7 @@ public class DistCp extends Configured implements Tool {
8687
public DistCp(Configuration configuration, DistCpOptions inputOptions) throws Exception {
8788
Configuration config = new Configuration(configuration);
8889
config.addResource(DISTCP_DEFAULT_XML);
90+
config.addResource(DISTCP_SITE_XML);
8991
setConf(config);
9092
this.inputOptions = inputOptions;
9193
this.metaFolder = createMetaFolderPath();
@@ -393,10 +395,12 @@ public static void main(String argv[]) {
393395
* Loads properties from distcp-default.xml into configuration
394396
* object
395397
* @return Configuration which includes properties from distcp-default.xml
398+
* and distcp-site.xml
396399
*/
397400
private static Configuration getDefaultConf() {
398401
Configuration config = new Configuration();
399402
config.addResource(DISTCP_DEFAULT_XML);
403+
config.addResource(DISTCP_SITE_XML);
400404
return config;
401405
}
402406

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public class DistCpOptions {
4747
public static final int maxNumListstatusThreads = 40;
4848
private int numListstatusThreads = 0; // Indicates that flag is not set.
4949
private int maxMaps = DistCpConstants.DEFAULT_MAPS;
50-
private float mapBandwidth = DistCpConstants.DEFAULT_BANDWIDTH_MB;
50+
private float mapBandwidth = 0; // Indicates that we should use the default.
5151

5252
private String copyStrategy = DistCpConstants.UNIFORMSIZE;
5353

@@ -609,8 +609,10 @@ public void appendToConf(Configuration conf) {
609609
String.valueOf(useDiff));
610610
DistCpOptionSwitch.addToConf(conf, DistCpOptionSwitch.SKIP_CRC,
611611
String.valueOf(skipCRC));
612-
DistCpOptionSwitch.addToConf(conf, DistCpOptionSwitch.BANDWIDTH,
613-
String.valueOf(mapBandwidth));
612+
if (mapBandwidth > 0) {
613+
DistCpOptionSwitch.addToConf(conf, DistCpOptionSwitch.BANDWIDTH,
614+
String.valueOf(mapBandwidth));
615+
}
614616
DistCpOptionSwitch.addToConf(conf, DistCpOptionSwitch.PRESERVE_STATUS,
615617
DistCpUtils.packAttributes(preserveStatus));
616618
if (filtersFile != null) {

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

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public void testParsebandwidth() {
107107
DistCpOptions options = OptionsParser.parse(new String[] {
108108
"hdfs://localhost:9820/source/first",
109109
"hdfs://localhost:9820/target/"});
110-
Assert.assertEquals(options.getMapBandwidth(), DistCpConstants.DEFAULT_BANDWIDTH_MB, DELTA);
110+
Assert.assertEquals(options.getMapBandwidth(), 0, DELTA);
111111

112112
options = OptionsParser.parse(new String[] {
113113
"-bandwidth",
@@ -389,7 +389,7 @@ public void testToString() {
389389
+ "deleteMissing=false, ignoreFailures=false, overwrite=false, "
390390
+ "append=false, useDiff=false, fromSnapshot=null, toSnapshot=null, "
391391
+ "skipCRC=false, blocking=true, numListstatusThreads=0, maxMaps=20, "
392-
+ "mapBandwidth=100.0, "
392+
+ "mapBandwidth=0.0, "
393393
+ "copyStrategy='uniformsize', preserveStatus=[], "
394394
+ "preserveRawXattrs=false, atomicWorkPath=null, logPath=null, "
395395
+ "sourceFileListing=abc, sourcePaths=null, targetPath=xyz, "
@@ -572,6 +572,8 @@ public void testOptionsAppendToConf() {
572572
Configuration conf = new Configuration();
573573
Assert.assertFalse(conf.getBoolean(DistCpOptionSwitch.IGNORE_FAILURES.getConfigLabel(), false));
574574
Assert.assertFalse(conf.getBoolean(DistCpOptionSwitch.ATOMIC_COMMIT.getConfigLabel(), false));
575+
Assert.assertEquals(
576+
conf.getRaw(DistCpOptionSwitch.BANDWIDTH.getConfigLabel()), null);
575577
DistCpOptions options = OptionsParser.parse(new String[] {
576578
"-atomic",
577579
"-i",
@@ -581,7 +583,7 @@ public void testOptionsAppendToConf() {
581583
Assert.assertTrue(conf.getBoolean(DistCpOptionSwitch.IGNORE_FAILURES.getConfigLabel(), false));
582584
Assert.assertTrue(conf.getBoolean(DistCpOptionSwitch.ATOMIC_COMMIT.getConfigLabel(), false));
583585
Assert.assertEquals(conf.getFloat(DistCpOptionSwitch.BANDWIDTH.getConfigLabel(), -1),
584-
DistCpConstants.DEFAULT_BANDWIDTH_MB, DELTA);
586+
-1.0, DELTA);
585587

586588
conf = new Configuration();
587589
Assert.assertFalse(conf.getBoolean(DistCpOptionSwitch.SYNC_FOLDERS.getConfigLabel(), false));
@@ -602,6 +604,62 @@ public void testOptionsAppendToConf() {
602604
Assert.assertEquals(conf.getFloat(DistCpOptionSwitch.BANDWIDTH.getConfigLabel(), -1), 11.2, DELTA);
603605
}
604606

607+
@Test
608+
public void testOptionsAppendToConfDoesntOverwriteBandwidth() {
609+
Configuration conf = new Configuration();
610+
Assert.assertEquals(
611+
conf.getRaw(DistCpOptionSwitch.BANDWIDTH.getConfigLabel()), null);
612+
DistCpOptions options = OptionsParser.parse(new String[] {
613+
"hdfs://localhost:8020/source/first",
614+
"hdfs://localhost:8020/target/"});
615+
options.appendToConf(conf);
616+
Assert.assertEquals(
617+
conf.getFloat(DistCpOptionSwitch.BANDWIDTH.getConfigLabel(), -1), -1.0,
618+
DELTA);
619+
620+
conf = new Configuration();
621+
Assert.assertEquals(
622+
conf.getRaw(DistCpOptionSwitch.BANDWIDTH.getConfigLabel()), null);
623+
options = OptionsParser.parse(new String[] {
624+
"-update",
625+
"-delete",
626+
"-pu",
627+
"-bandwidth",
628+
"77",
629+
"hdfs://localhost:8020/source/first",
630+
"hdfs://localhost:8020/target/"});
631+
options.appendToConf(conf);
632+
Assert.assertEquals(
633+
conf.getFloat(DistCpOptionSwitch.BANDWIDTH.getConfigLabel(), -1), 77.0,
634+
DELTA);
635+
636+
conf = new Configuration();
637+
conf.set(DistCpOptionSwitch.BANDWIDTH.getConfigLabel(), "88");
638+
Assert.assertEquals(
639+
conf.getRaw(DistCpOptionSwitch.BANDWIDTH.getConfigLabel()), "88");
640+
options = OptionsParser.parse(new String[] {
641+
"hdfs://localhost:8020/source/first",
642+
"hdfs://localhost:8020/target/"});
643+
options.appendToConf(conf);
644+
Assert.assertEquals(
645+
conf.getFloat(DistCpOptionSwitch.BANDWIDTH.getConfigLabel(), -1), 88.0,
646+
DELTA);
647+
648+
conf = new Configuration();
649+
conf.set(DistCpOptionSwitch.BANDWIDTH.getConfigLabel(), "88.0");
650+
Assert.assertEquals(
651+
conf.getRaw(DistCpOptionSwitch.BANDWIDTH.getConfigLabel()), "88.0");
652+
options = OptionsParser.parse(new String[] {
653+
"-bandwidth",
654+
"99",
655+
"hdfs://localhost:8020/source/first",
656+
"hdfs://localhost:8020/target/"});
657+
options.appendToConf(conf);
658+
Assert.assertEquals(
659+
conf.getFloat(DistCpOptionSwitch.BANDWIDTH.getConfigLabel(), -1), 99.0,
660+
DELTA);
661+
}
662+
605663
@Test
606664
public void testAppendOption() {
607665
Configuration conf = new Configuration();

0 commit comments

Comments
 (0)