1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with this 4 * work for additional information regarding copyright ownership. The ASF 5 * licenses this file to you under the Apache License, Version 2.0 (the 6 * "License"); you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 * License for the specific language governing permissions and limitations 15 * under the License. 16 */ 17 package org.apache.hadoop.hbase.util.test; 18 19 import java.util.Set; 20 21 import org.apache.hadoop.classification.InterfaceAudience; 22 23 /** 24 * A generator of random data (keys/cfs/columns/values) for load testing. 25 * Contains LoadTestKVGenerator as a matter of convenience... 26 */ 27 @InterfaceAudience.Private 28 public abstract class LoadTestDataGenerator { 29 protected final LoadTestKVGenerator kvGenerator; 30 31 // The mutate info column stores information 32 // about update done to this column family this row. 33 public final static byte[] MUTATE_INFO = "mutate_info".getBytes(); 34 35 // The increment column always has a long value, 36 // which can be incremented later on during updates. 37 public final static byte[] INCREMENT = "increment".getBytes(); 38 39 /** 40 * Initializes the object. 41 * @param minValueSize minimum size of the value generated by 42 * {@link #generateValue(byte[], byte[], byte[])}. 43 * @param maxValueSize maximum size of the value generated by 44 * {@link #generateValue(byte[], byte[], byte[])}. 45 */ 46 public LoadTestDataGenerator(int minValueSize, int maxValueSize) { 47 this.kvGenerator = new LoadTestKVGenerator(minValueSize, maxValueSize); 48 } 49 50 /** 51 * Generates a deterministic, unique hashed row key from a number. That way, the user can 52 * keep track of numbers, without messing with byte array and ensuring key distribution. 53 * @param keyBase Base number for a key, such as a loop counter. 54 */ 55 public abstract byte[] getDeterministicUniqueKey(long keyBase); 56 57 /** 58 * Gets column families for the load test table. 59 * @return The array of byte[]s representing column family names. 60 */ 61 public abstract byte[][] getColumnFamilies(); 62 63 /** 64 * Generates an applicable set of columns to be used for a particular key and family. 65 * @param rowKey The row key to generate for. 66 * @param cf The column family name to generate for. 67 * @return The array of byte[]s representing column names. 68 */ 69 public abstract byte[][] generateColumnsForCf(byte[] rowKey, byte[] cf); 70 71 /** 72 * Generates a value to be used for a particular row/cf/column. 73 * @param rowKey The row key to generate for. 74 * @param cf The column family name to generate for. 75 * @param column The column name to generate for. 76 * @return The value to use. 77 */ 78 public abstract byte[] generateValue(byte[] rowKey, byte[] cf, byte[] column); 79 80 /** 81 * Checks that columns for a rowKey and cf are valid if generated via 82 * {@link #generateColumnsForCf(byte[], byte[])} 83 * @param rowKey The row key to verify for. 84 * @param cf The column family name to verify for. 85 * @param columnSet The column set (for example, encountered by read). 86 * @return True iff valid. 87 */ 88 public abstract boolean verify(byte[] rowKey, byte[] cf, Set<byte[]> columnSet); 89 90 /** 91 * Checks that value for a rowKey/cf/column is valid if generated via 92 * {@link #generateValue(byte[], byte[], byte[])} 93 * @param rowKey The row key to verify for. 94 * @param cf The column family name to verify for. 95 * @param column The column name to verify for. 96 * @param value The value (for example, encountered by read). 97 * @return True iff valid. 98 */ 99 public abstract boolean verify(byte[] rowKey, byte[] cf, byte[] column, byte[] value); 100 }