public static void prefixKeyWithSalt ( final byte [ ] row_key ) { if ( Const . SALT_WIDTH ( ) > 0 ) { if ( row_key . length < ( Const . SALT_WIDTH ( ) + TSDB . metrics_width ( ) ) || ( Bytes . memcmp ( row_key , new byte [ Const . SALT_WIDTH ( ) + TSDB . metrics_width ( ) ] , Const . SALT_WIDTH ( ) , TSDB . metrics_width ( ) ) == 0 ) ) { // ^ Don't salt the global annotation row, leave it at zero return ; } final int tags_start = Const . SALT_WIDTH ( ) + TSDB . metrics_width ( ) + Const . TIMESTAMP_BYTES ; // we want the metric and tags, not the timestamp final byte [ ] salt_base = new byte [ row_key . length - Const . SALT_WIDTH ( ) - Const . TIMESTAMP_BYTES ] ; System . arraycopy ( row_key , Const . SALT_WIDTH ( ) , salt_base , 0 , TSDB . metrics_width ( ) ) ; System . arraycopy ( row_key , tags_start , salt_base , TSDB . metrics_width ( ) , row_key . length - tags_start ) ; int modulo = Arrays . hashCode ( salt_base ) % Const . SALT_BUCKETS ( ) ; if ( modulo < 0 ) { // make sure we return a positive salt. modulo = modulo * - 1 ; } final byte [ ] salt = getSaltBytes ( modulo ) ; System . arraycopy ( salt , 0 , row_key , 0 , Const . SALT_WIDTH ( ) ) ; } // else salting is disabled so it's a no-op }
Calculates and writes an array of one or more salt bytes at the front of the given row key .