001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.util;
019
020import java.util.Arrays;
021import org.apache.yetus.audience.InterfaceAudience;
022
023/**
024 * A load test data generator for MOB
025 */
026@InterfaceAudience.Private
027public class LoadTestDataGeneratorWithMOB extends MultiThreadedAction.DefaultDataGenerator {
028
029  private byte[] mobColumnFamily;
030  private LoadTestKVGenerator mobKvGenerator;
031
032  public LoadTestDataGeneratorWithMOB(int minValueSize, int maxValueSize, int minColumnsPerKey,
033    int maxColumnsPerKey, byte[]... columnFamilies) {
034    super(minValueSize, maxValueSize, minColumnsPerKey, maxColumnsPerKey, columnFamilies);
035  }
036
037  public LoadTestDataGeneratorWithMOB(byte[]... columnFamilies) {
038    super(columnFamilies);
039  }
040
041  @Override
042  public void initialize(String[] args) {
043    super.initialize(args);
044    if (args.length != 3) {
045      throw new IllegalArgumentException("LoadTestDataGeneratorWithMOB can have 3 arguments."
046        + "1st argument is a column family, the 2nd argument "
047        + "is the minimum mob data size and the 3rd argument " + "is the maximum mob data size.");
048    }
049    String mobColumnFamily = args[0];
050    int minMobDataSize = Integer.parseInt(args[1]);
051    int maxMobDataSize = Integer.parseInt(args[2]);
052    configureMob(Bytes.toBytes(mobColumnFamily), minMobDataSize, maxMobDataSize);
053  }
054
055  private void configureMob(byte[] mobColumnFamily, int minMobDataSize, int maxMobDataSize) {
056    this.mobColumnFamily = mobColumnFamily;
057    mobKvGenerator = new LoadTestKVGenerator(minMobDataSize, maxMobDataSize);
058  }
059
060  @Override
061  public byte[] generateValue(byte[] rowKey, byte[] cf, byte[] column) {
062    if (Arrays.equals(cf, mobColumnFamily))
063      return mobKvGenerator.generateRandomSizeValue(rowKey, cf, column);
064
065    return super.generateValue(rowKey, cf, column);
066  }
067}