|
| 1 | +/** |
| 2 | + * |
| 3 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 4 | + * or more contributor license agreements. See the NOTICE file |
| 5 | + * distributed with this work for additional information |
| 6 | + * regarding copyright ownership. The ASF licenses this file |
| 7 | + * to you under the Apache License, Version 2.0 (the |
| 8 | + * "License"); you may not use this file except in compliance |
| 9 | + * with the License. You may obtain a copy of the License at |
| 10 | + * |
| 11 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | + * |
| 13 | + * Unless required by applicable law or agreed to in writing, software |
| 14 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | + * See the License for the specific language governing permissions and |
| 17 | + * limitations under the License. |
| 18 | + */ |
| 19 | +package org.apache.hadoop.hbase.mapreduce; |
| 20 | + |
| 21 | +import org.apache.commons.lang3.RandomStringUtils; |
| 22 | +import org.apache.hadoop.conf.Configuration; |
| 23 | +import org.apache.hadoop.fs.Path; |
| 24 | +import org.apache.hadoop.hbase.Cell; |
| 25 | +import org.apache.hadoop.hbase.CellUtil; |
| 26 | +import org.apache.hadoop.hbase.HBaseConfiguration; |
| 27 | +import org.apache.hadoop.hbase.HBaseTestingUtil; |
| 28 | +import org.apache.hadoop.hbase.IntegrationTestBase; |
| 29 | +import org.apache.hadoop.hbase.IntegrationTestingUtility; |
| 30 | +import org.apache.hadoop.hbase.KeyValue; |
| 31 | +import org.apache.hadoop.hbase.TableName; |
| 32 | +import org.apache.hadoop.hbase.client.Admin; |
| 33 | +import org.apache.hadoop.hbase.client.Connection; |
| 34 | +import org.apache.hadoop.hbase.client.ConnectionFactory; |
| 35 | +import org.apache.hadoop.hbase.client.Consistency; |
| 36 | +import org.apache.hadoop.hbase.client.RegionLocator; |
| 37 | +import org.apache.hadoop.hbase.client.Result; |
| 38 | +import org.apache.hadoop.hbase.client.Scan; |
| 39 | +import org.apache.hadoop.hbase.client.TableDescriptor; |
| 40 | +import org.apache.hadoop.hbase.client.TableDescriptorBuilder; |
| 41 | +import org.apache.hadoop.hbase.coprocessor.ObserverContext; |
| 42 | +import org.apache.hadoop.hbase.coprocessor.RegionCoprocessor; |
| 43 | +import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment; |
| 44 | +import org.apache.hadoop.hbase.coprocessor.RegionObserver; |
| 45 | +import org.apache.hadoop.hbase.io.ImmutableBytesWritable; |
| 46 | +import org.apache.hadoop.hbase.regionserver.InternalScanner; |
| 47 | +import org.apache.hadoop.hbase.regionserver.storefiletracker.StoreFileTrackerFactory; |
| 48 | +import org.apache.hadoop.hbase.testclassification.IntegrationTests; |
| 49 | +import org.apache.hadoop.hbase.tool.BulkLoadHFiles; |
| 50 | +import org.apache.hadoop.hbase.util.Bytes; |
| 51 | +import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; |
| 52 | +import org.apache.hadoop.hbase.util.RegionSplitter; |
| 53 | +import org.apache.hadoop.io.LongWritable; |
| 54 | +import org.apache.hadoop.io.NullWritable; |
| 55 | +import org.apache.hadoop.io.Writable; |
| 56 | +import org.apache.hadoop.io.WritableComparable; |
| 57 | +import org.apache.hadoop.io.WritableComparator; |
| 58 | +import org.apache.hadoop.io.WritableUtils; |
| 59 | +import org.apache.hadoop.mapreduce.InputFormat; |
| 60 | +import org.apache.hadoop.mapreduce.InputSplit; |
| 61 | +import org.apache.hadoop.mapreduce.Job; |
| 62 | +import org.apache.hadoop.mapreduce.JobContext; |
| 63 | +import org.apache.hadoop.mapreduce.Mapper; |
| 64 | +import org.apache.hadoop.mapreduce.Partitioner; |
| 65 | +import org.apache.hadoop.mapreduce.RecordReader; |
| 66 | +import org.apache.hadoop.mapreduce.Reducer; |
| 67 | +import org.apache.hadoop.mapreduce.TaskAttemptContext; |
| 68 | +import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat; |
| 69 | +import org.apache.hadoop.util.StringUtils; |
| 70 | +import org.apache.hadoop.util.ToolRunner; |
| 71 | +import org.apache.hbase.thirdparty.com.google.common.base.Joiner; |
| 72 | +import org.apache.hbase.thirdparty.com.google.common.collect.Sets; |
| 73 | +import org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine; |
| 74 | +import org.junit.Test; |
| 75 | +import org.junit.experimental.categories.Category; |
| 76 | +import org.slf4j.Logger; |
| 77 | +import org.slf4j.LoggerFactory; |
| 78 | +import java.io.DataInput; |
| 79 | +import java.io.DataOutput; |
| 80 | +import java.io.IOException; |
| 81 | +import java.util.ArrayList; |
| 82 | +import java.util.List; |
| 83 | +import java.util.Map; |
| 84 | +import java.util.Optional; |
| 85 | +import java.util.Random; |
| 86 | +import java.util.Set; |
| 87 | +import java.util.concurrent.atomic.AtomicLong; |
| 88 | +import static org.junit.Assert.assertEquals; |
| 89 | + |
| 90 | +/** |
| 91 | + * Test Bulk Load and MR on a distributed cluster. |
| 92 | + * With FileBased StorefileTracker enabled. |
| 93 | + * It starts an MR job that creates linked chains |
| 94 | + * |
| 95 | + * The format of rows is like this: |
| 96 | + * Row Key -> Long |
| 97 | + * |
| 98 | + * L:<< Chain Id >> -> Row Key of the next link in the chain |
| 99 | + * S:<< Chain Id >> -> The step in the chain that his link is. |
| 100 | + * D:<< Chain Id >> -> Random Data. |
| 101 | + * |
| 102 | + * All chains start on row 0. |
| 103 | + * All rk's are > 0. |
| 104 | + * |
| 105 | + * After creating the linked lists they are walked over using a TableMapper based Mapreduce Job. |
| 106 | + * |
| 107 | + * There are a few options exposed: |
| 108 | + * |
| 109 | + * hbase.IntegrationTestBulkLoad.chainLength |
| 110 | + * The number of rows that will be part of each and every chain. |
| 111 | + * |
| 112 | + * hbase.IntegrationTestBulkLoad.numMaps |
| 113 | + * The number of mappers that will be run. Each mapper creates on linked list chain. |
| 114 | + * |
| 115 | + * hbase.IntegrationTestBulkLoad.numImportRounds |
| 116 | + * How many jobs will be run to create linked lists. |
| 117 | + * |
| 118 | + * hbase.IntegrationTestBulkLoad.tableName |
| 119 | + * The name of the table. |
| 120 | + * |
| 121 | + * hbase.IntegrationTestBulkLoad.replicaCount |
| 122 | + * How many region replicas to configure for the table under test. |
| 123 | + */ |
| 124 | +@Category(IntegrationTests.class) |
| 125 | +public class IntegrationTestFileBasedSFTBulkLoad extends IntegrationTestBulkLoad { |
| 126 | + |
| 127 | + private static final Logger LOG = LoggerFactory.getLogger(IntegrationTestFileBasedSFTBulkLoad.class); |
| 128 | + |
| 129 | + private static String NUM_MAPS_KEY = "hbase.IntegrationTestBulkLoad.numMaps"; |
| 130 | + private static String NUM_IMPORT_ROUNDS_KEY = "hbase.IntegrationTestBulkLoad.numImportRounds"; |
| 131 | + private static String NUM_REPLICA_COUNT_KEY = "hbase.IntegrationTestBulkLoad.replicaCount"; |
| 132 | + private static int NUM_REPLICA_COUNT_DEFAULT = 1; |
| 133 | + |
| 134 | + @Test |
| 135 | + public void testFileBasedSFTBulkLoad() throws Exception { |
| 136 | + super.testBulkLoad(); |
| 137 | + } |
| 138 | + |
| 139 | + @Override |
| 140 | + public void setUpCluster() throws Exception { |
| 141 | + util = getTestingUtil(getConf()); |
| 142 | + util.getConfiguration().set(StoreFileTrackerFactory.TRACKER_IMPL, |
| 143 | + "org.apache.hadoop.hbase.regionserver.storefiletracker.FileBasedStoreFileTracker"); |
| 144 | + util.initializeCluster(1); |
| 145 | + int replicaCount = getConf().getInt(NUM_REPLICA_COUNT_KEY, NUM_REPLICA_COUNT_DEFAULT); |
| 146 | + if (LOG.isDebugEnabled() && replicaCount != NUM_REPLICA_COUNT_DEFAULT) { |
| 147 | + LOG.debug("Region Replicas enabled: " + replicaCount); |
| 148 | + } |
| 149 | + |
| 150 | + // Scale this up on a real cluster |
| 151 | + if (util.isDistributedCluster()) { |
| 152 | + util.getConfiguration().setIfUnset(NUM_MAPS_KEY, |
| 153 | + Integer.toString(util.getAdmin().getRegionServers().size() * 10)); |
| 154 | + util.getConfiguration().setIfUnset(NUM_IMPORT_ROUNDS_KEY, "5"); |
| 155 | + } else { |
| 156 | + util.startMiniMapReduceCluster(); |
| 157 | + } |
| 158 | + } |
| 159 | + |
| 160 | + public static void main(String[] args) throws Exception { |
| 161 | + Configuration conf = HBaseConfiguration.create(); |
| 162 | + IntegrationTestingUtility.setUseDistributedCluster(conf); |
| 163 | + int status = ToolRunner.run(conf, new IntegrationTestFileBasedSFTBulkLoad(), args); |
| 164 | + System.exit(status); |
| 165 | + } |
| 166 | +} |
0 commit comments