Generates a row key given a TSUID and an absolute timestamp. The timestamp will be normalized to an hourly base time. If salting is enabled then empty salt bytes will be prepended to the key and must be filled in later. @param tsdb The TSDB to use for fetching tag widths @param tsuid The TSUID to us
(final TSDB tsdb, final byte[] tsuid,
final long timestamp)
| 81 | * @since 2.0 |
| 82 | */ |
| 83 | public static byte[] rowKeyFromTSUID(final TSDB tsdb, final byte[] tsuid, |
| 84 | final long timestamp) { |
| 85 | if (tsuid.length < tsdb.metrics.width()) { |
| 86 | throw new IllegalArgumentException("TSUID appears to be missing the metric"); |
| 87 | } |
| 88 | final long base_time; |
| 89 | if ((timestamp & Const.SECOND_MASK) != 0) { |
| 90 | // drop the ms timestamp to seconds to calculate the base timestamp |
| 91 | base_time = ((timestamp / 1000) - |
| 92 | ((timestamp / 1000) % Const.MAX_TIMESPAN)); |
| 93 | } else { |
| 94 | base_time = (timestamp - (timestamp % Const.MAX_TIMESPAN)); |
| 95 | } |
| 96 | final byte[] row = |
| 97 | new byte[Const.SALT_WIDTH() + tsuid.length + Const.TIMESTAMP_BYTES]; |
| 98 | System.arraycopy(tsuid, 0, row, Const.SALT_WIDTH(), tsdb.metrics.width()); |
| 99 | Bytes.setInt(row, (int) base_time, Const.SALT_WIDTH() + tsdb.metrics.width()); |
| 100 | System.arraycopy(tsuid, tsdb.metrics.width(), row, |
| 101 | Const.SALT_WIDTH() + tsdb.metrics.width() + Const.TIMESTAMP_BYTES, |
| 102 | tsuid.length - tsdb.metrics.width()); |
| 103 | RowKey.prefixKeyWithSalt(row); |
| 104 | return row; |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * Returns the byte array for the given salt id |