Skip to content

Commit

Permalink
HBASE-28686 MapReduceBackupCopyJob should support custom DistCp options
Browse files Browse the repository at this point in the history
  • Loading branch information
Ray Mattingly committed Jun 21, 2024
1 parent f8aa3e2 commit ab064a4
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
Expand All @@ -45,6 +46,7 @@
import org.apache.hadoop.tools.CopyListingFileStatus;
import org.apache.hadoop.tools.DistCp;
import org.apache.hadoop.tools.DistCpConstants;
import org.apache.hadoop.tools.DistCpOptionSwitch;
import org.apache.hadoop.tools.DistCpOptions;
import org.apache.yetus.audience.InterfaceAudience;
import org.slf4j.Logger;
Expand Down Expand Up @@ -394,7 +396,15 @@ public int copy(BackupInfo context, BackupManager backupManager, Configuration c
if (!destfs.exists(dest)) {
destfs.mkdirs(dest);
}
res = distcp.run(newOptions);

List<String> distCpOptionsFromConf = parseDistCpOptions(conf);
String[] finalOptions = new String[newOptions.length + distCpOptionsFromConf.size()];
for (int i = 0; i < distCpOptionsFromConf.size(); i++) {
finalOptions[i] = distCpOptionsFromConf.get(i);
}
System.arraycopy(newOptions, 0, finalOptions, distCpOptionsFromConf.size(),
newOptions.length);
res = distcp.run(finalOptions);
}
return res;

Expand Down Expand Up @@ -425,4 +435,25 @@ public void cancel(String jobId) throws IOException {
}
}

protected static List<String> parseDistCpOptions(Configuration conf) {
List<String> extraArgsFromConf = new ArrayList<>();

for (DistCpOptionSwitch optionSwitch : DistCpOptionSwitch.values()) {
String configLabel = optionSwitch.getConfigLabel();
if (conf.get(configLabel) != null) {
if (optionSwitch.getOption().hasArg()) {
extraArgsFromConf.add("-" + optionSwitch.getOption().getOpt());
extraArgsFromConf.add(conf.get(configLabel));
} else {
boolean value = conf.getBoolean(configLabel, false);
if (value) {
extraArgsFromConf.add("-" + optionSwitch.getOption().getOpt());
}
}
}
}

return extraArgsFromConf;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.hadoop.hbase.backup.mapreduce;

import static org.apache.hadoop.tools.DistCpConstants.CONF_LABEL_DIRECT_WRITE;
import static org.apache.hadoop.tools.DistCpConstants.CONF_LABEL_MAX_MAPS;
import static org.junit.Assert.assertEquals;

import java.util.List;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import org.apache.hbase.thirdparty.com.google.common.collect.ImmutableList;

@Category(SmallTests.class)
public class TestMapReduceBackupCopyJob {

@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestMapReduceBackupCopyJob.class);

@Test
public void testDistCpOptionParsing() {
Configuration conf = new Configuration();
conf.setInt(CONF_LABEL_MAX_MAPS, 1000);
conf.setBoolean(CONF_LABEL_DIRECT_WRITE, true);
List<String> args = MapReduceBackupCopyJob.parseDistCpOptions(conf);

List<String> expectedArgs =
ImmutableList.<String> builder().add("-m", "1000").add("-direct").build();

assertEquals(args, expectedArgs);
}

}

0 comments on commit ab064a4

Please sign in to comment.