Extracts the TSUID from a storage row key that includes the timestamp. @param row_key The row key to process @param metric_width The width of the metric @param timestamp_width The width of the timestamp @return The TSUID as a byte array @throws IllegalArgumentException if the row key is missing tags
(final byte[] row_key,
final short metric_width, final short timestamp_width)
| 1573 | * corrupt such as a salted key when salting is disabled or vice versa. |
| 1574 | */ |
| 1575 | public static byte[] getTSUIDFromKey(final byte[] row_key, |
| 1576 | final short metric_width, final short timestamp_width) { |
| 1577 | int idx = 0; |
| 1578 | // validation |
| 1579 | final int tag_pair_width = TSDB.tagk_width() + TSDB.tagv_width(); |
| 1580 | final int tags_length = row_key.length - |
| 1581 | (Const.SALT_WIDTH() + metric_width + timestamp_width); |
| 1582 | if (tags_length < tag_pair_width || (tags_length % tag_pair_width) != 0) { |
| 1583 | throw new IllegalArgumentException( |
| 1584 | "Row key is missing tags or it is corrupted " + Arrays.toString(row_key)); |
| 1585 | } |
| 1586 | final byte[] tsuid = new byte[ |
| 1587 | row_key.length - timestamp_width - Const.SALT_WIDTH()]; |
| 1588 | for (int i = Const.SALT_WIDTH(); i < row_key.length; i++) { |
| 1589 | if (i < Const.SALT_WIDTH() + metric_width || |
| 1590 | i >= (Const.SALT_WIDTH() + metric_width + timestamp_width)) { |
| 1591 | tsuid[idx] = row_key[i]; |
| 1592 | idx++; |
| 1593 | } |
| 1594 | } |
| 1595 | return tsuid; |
| 1596 | } |
| 1597 | |
| 1598 | /** |
| 1599 | * Extracts a list of tagks and tagvs as individual values in a list |