MCPcopy
hub / github.com/OpenTSDB/opentsdb / getRowKey

Method getRowKey

src/meta/Annotation.java:658–692  ·  view source on GitHub ↗

Calculates the row key based on the TSUID and the start time. If the TSUID is empty, the row key is a 0 filled byte array TSDB.metrics_width() wide plus the normalized start timestamp without any tag bytes. @param start_time The start time as a Unix epoch timestamp @param tsuid An optional T

(final long start_time, final byte[] tsuid)

Source from the content-addressed store, hash-verified

656 * @return The row key as a byte array
657 */
658 private static byte[] getRowKey(final long start_time, final byte[] tsuid) {
659 if (start_time < 1) {
660 throw new IllegalArgumentException("The start timestamp has not been set");
661 }
662
663 final long base_time;
664 if ((start_time & Const.SECOND_MASK) != 0) {
665 // drop the ms timestamp to seconds to calculate the base timestamp
666 base_time = ((start_time / 1000) -
667 ((start_time / 1000) % Const.MAX_TIMESPAN));
668 } else {
669 base_time = (start_time - (start_time % Const.MAX_TIMESPAN));
670 }
671
672 // if the TSUID is empty, then we're a global annotation. The row key will
673 // just be an empty byte array of metric width plus the timestamp. We also
674 // don't salt the global row key (though it has space for salts)
675 if (tsuid == null || tsuid.length < 1) {
676 final byte[] row = new byte[Const.SALT_WIDTH() +
677 TSDB.metrics_width() + Const.TIMESTAMP_BYTES];
678 Bytes.setInt(row, (int) base_time, Const.SALT_WIDTH() + TSDB.metrics_width());
679 return row;
680 }
681
682 // otherwise we need to build the row key from the TSUID and start time
683 final byte[] row = new byte[Const.SALT_WIDTH() + Const.TIMESTAMP_BYTES +
684 tsuid.length];
685 System.arraycopy(tsuid, 0, row, Const.SALT_WIDTH(), TSDB.metrics_width());
686 Bytes.setInt(row, (int) base_time, Const.SALT_WIDTH() + TSDB.metrics_width());
687 System.arraycopy(tsuid, TSDB.metrics_width(), row,
688 Const.SALT_WIDTH() + TSDB.metrics_width() + Const.TIMESTAMP_BYTES,
689 (tsuid.length - TSDB.metrics_width()));
690 RowKey.prefixKeyWithSalt(row);
691 return row;
692 }
693
694// Getters and Setters --------------
695

Callers 5

deleteMethod · 0.95
getAnnotationMethod · 0.95
compareMethod · 0.45
callMethod · 0.45

Calls 3

SALT_WIDTHMethod · 0.95
metrics_widthMethod · 0.95
prefixKeyWithSaltMethod · 0.95

Tested by

no test coverage detected