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; 021 022/** 023 * A load test data generator for MOB 024 */ 025public class LoadTestDataGeneratorWithMOB 026 extends MultiThreadedAction.DefaultDataGenerator { 027 028 private byte[] mobColumnFamily; 029 private LoadTestKVGenerator mobKvGenerator; 030 031 public LoadTestDataGeneratorWithMOB(int minValueSize, int maxValueSize, 032 int minColumnsPerKey, int maxColumnsPerKey, byte[]... columnFamilies) { 033 super(minValueSize, maxValueSize, minColumnsPerKey, maxColumnsPerKey, 034 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( 046 "LoadTestDataGeneratorWithMOB can have 3 arguments." 047 + "1st argument is a column family, the 2nd argument " 048 + "is the minimum mob data size and the 3rd argument " 049 + "is the maximum mob data size."); 050 } 051 String mobColumnFamily = args[0]; 052 int minMobDataSize = Integer.parseInt(args[1]); 053 int maxMobDataSize = Integer.parseInt(args[2]); 054 configureMob(Bytes.toBytes(mobColumnFamily), minMobDataSize, maxMobDataSize); 055 } 056 057 private void configureMob(byte[] mobColumnFamily, int minMobDataSize, 058 int maxMobDataSize) { 059 this.mobColumnFamily = mobColumnFamily; 060 mobKvGenerator = new LoadTestKVGenerator(minMobDataSize, maxMobDataSize); 061 } 062 063 @Override 064 public byte[] generateValue(byte[] rowKey, byte[] cf, 065 byte[] column) { 066 if(Arrays.equals(cf, mobColumnFamily)) 067 return mobKvGenerator.generateRandomSizeValue(rowKey, cf, column); 068 069 return super.generateValue(rowKey, cf, column); 070 } 071}