Class LoadTestKVGenerator

java.lang.Object
org.apache.hadoop.hbase.util.LoadTestKVGenerator

@Private public class LoadTestKVGenerator extends Object
A generator of random keys and values for load testing. Keys are generated by converting numeric indexes to strings and prefixing them with an MD5 hash. Values are generated by selecting value size in the configured range and generating a pseudo-random sequence of bytes seeded by key, column qualifier, and value size.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final org.slf4j.Logger
     
    private static int
     
    private final int
     
    private final int
     
    private Random
    A random number generator for determining value size
  • Constructor Summary

    Constructors
    Constructor
    Description
    LoadTestKVGenerator(int minValueSize, int maxValueSize)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    byte[]
    generateRandomSizeValue(byte[]... seedStrings)
    Generates a value for the given key index and column qualifier.
    private static byte[]
    getValueForRowColumn(int dataSize, byte[]... seedStrings)
    Generates random bytes of the given size for the given row and column qualifier.
    static String
    md5PrefixedKey(long key)
    Converts the given key to string, and prefixes it with the MD5 hash of the index's string representation.
    static boolean
    verify(byte[] value, byte[]... seedStrings)
    Verifies that the given byte array is the same as what would be generated for the given seed strings (row/cf/column/...).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

  • Method Details

    • verify

      public static boolean verify(byte[] value, byte[]... seedStrings)
      Verifies that the given byte array is the same as what would be generated for the given seed strings (row/cf/column/...). We are assuming that the value size is correct, and only verify the actual bytes. However, if the min/max value sizes are set sufficiently high, an accidental match should be extremely improbable.
    • md5PrefixedKey

      public static String md5PrefixedKey(long key)
      Converts the given key to string, and prefixes it with the MD5 hash of the index's string representation.
    • generateRandomSizeValue

      public byte[] generateRandomSizeValue(byte[]... seedStrings)
      Generates a value for the given key index and column qualifier. Size is selected randomly in the configured range. The generated value depends only on the combination of the strings passed (key/cf/column/...) and the selected value size. This allows to verify the actual value bytes when reading, as done in {#verify(byte[], byte[]...)} This method is as thread-safe as Random class. It appears that the worst bug ever found with the latter is that multiple threads will get some duplicate values, which we don't care about.
    • getValueForRowColumn

      private static byte[] getValueForRowColumn(int dataSize, byte[]... seedStrings)
      Generates random bytes of the given size for the given row and column qualifier. The random seed is fully determined by these parameters.