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

Method prepareRequests

src/core/MultiGetQuery.java:1193–1290  ·  view source on GitHub ↗

Generates a map of TSUIDs per salt to get requests given the tag permutations. If all salts is enabled, each TSUID will have Const.SALT_BUCKETS() number of entries. Otherwise each TSUID will have one row key. @param tagv_compounds The cardinality of tag key and value combinations to search for. @par

(final List<Long> base_time_list, List<ByteMap<byte[][]>> tags)

Source from the content-addressed store, hash-verified

1191 * @return A non-null map of TSUIDs to lists of get requests to send to HBase.
1192 */
1193 @VisibleForTesting
1194 ByteMap<ByteMap<List<GetRequest>>> prepareRequests(final List<Long> base_time_list, List<ByteMap<byte[][]>> tags) {
1195
1196 final ByteMap<ByteMap<List<GetRequest>>> tsuid_rows = new ByteMap<ByteMap<List<GetRequest>>>();
1197 // TSUID's don't have salts
1198 // final byte[] tsuid = new byte[tsdb.metrics.width()
1199 // + (tags.size() * tsdb.tag_names.width())
1200 // + tags.size() * tsdb.tag_values.width()];
1201 // final byte[] row_key = new byte[row_size];
1202
1203
1204 // copy tagks and tagvs to the row key
1205 for (ByteMap<byte[][]> each_row_key : tags) {
1206
1207 final int row_size = (Const.SALT_WIDTH() + tsdb.metrics.width()
1208 + Const.TIMESTAMP_BYTES
1209 + (tsdb.tag_names.width() * each_row_key.size())
1210 + (tsdb.tag_values.width() * each_row_key.size()));
1211 byte[] tsuid = new byte[tsdb.metrics.width()
1212 + (each_row_key.size() * tsdb.tag_names.width())
1213 + each_row_key.size() * tsdb.tag_values.width()];
1214 byte[] row_key = new byte[row_size];
1215 int row_key_copy_offset = Const.SALT_WIDTH() + tsdb.metrics.width()
1216 + Const.TIMESTAMP_BYTES;
1217 int tsuid_copy_offset = tsdb.metrics.width();
1218
1219 // metric
1220 System.arraycopy(metric, 0, row_key, Const.SALT_WIDTH(), tsdb.metrics.width());
1221 System.arraycopy(metric, 0, tsuid, 0, tsdb.metrics.width());
1222
1223 final List<GetRequest> rows =
1224 new ArrayList<GetRequest>(base_time_list.size());
1225 for (Map.Entry<byte[], byte[][]> tag_arr : each_row_key.entrySet()) {
1226 byte[] tagv = tag_arr.getValue()[0];
1227 // tagk
1228 byte[] tagk = tag_arr.getKey();
1229
1230 System.arraycopy(tagk, 0, row_key, row_key_copy_offset, tsdb.tag_names.width());
1231 System.arraycopy(tagk, 0, tsuid, tsuid_copy_offset, tsdb.tag_names.width());
1232 row_key_copy_offset += tsdb.tag_names.width();
1233 tsuid_copy_offset += tsdb.tag_names.width();
1234
1235 // tagv
1236 System.arraycopy(tagv, 0, row_key, row_key_copy_offset,
1237 tsdb.tag_values.width());
1238 System.arraycopy(tagv, 0, tsuid, tsuid_copy_offset,
1239 tsdb.tag_values.width());
1240 row_key_copy_offset += tsdb.tag_values.width();
1241 tsuid_copy_offset += tsdb.tag_values.width();
1242
1243 }
1244
1245 // iterate for each timestamp, making a copy of the key and tweaking it's
1246 // timestamp.
1247 for (final long row_base_time : base_time_list) {
1248 final byte[] key_copy = Arrays.copyOf(row_key, row_key.length);
1249
1250 // base time

Callers 2

prepareRequestsMethod · 0.95

Calls 13

SALT_WIDTHMethod · 0.95
setBaseTimeMethod · 0.95
SALT_BUCKETSMethod · 0.95
getSaltBytesMethod · 0.95
prefixKeyWithSaltMethod · 0.95
putMethod · 0.80
widthMethod · 0.65
sizeMethod · 0.65
keyMethod · 0.65
getValueMethod · 0.45
getKeyMethod · 0.45
addMethod · 0.45

Tested by 1

prepareRequestsMethod · 0.76