diff --git a/.gitignore b/.gitignore index 8fdaa6b007..24afdb80df 100644 --- a/.gitignore +++ b/.gitignore @@ -38,3 +38,4 @@ guava-rpm-maker/\.project src-main src-test plugin_test.jar +/bin/ diff --git a/src/tsd/UniqueIdRpc.java b/src/tsd/UniqueIdRpc.java index 4c5487abad..7e4ff2c220 100644 --- a/src/tsd/UniqueIdRpc.java +++ b/src/tsd/UniqueIdRpc.java @@ -22,6 +22,7 @@ import java.util.TreeMap; import org.hbase.async.Bytes; +import org.hbase.async.Bytes.ByteMap; import org.hbase.async.PutRequest; import org.jboss.netty.handler.codec.http.HttpMethod; import org.jboss.netty.handler.codec.http.HttpResponseStatus; @@ -549,6 +550,7 @@ private TSMeta parseTSMetaQS(final HttpQuery query) { * @param data_query The query we're building * @throws BadRequestException if we are unable to parse the query or it is * missing components + * @todo - make this asynchronous */ private String getTSUIDForMetric(final String query_string, TSDB tsdb) { if (query_string == null || query_string.isEmpty()) { @@ -565,16 +567,23 @@ private String getTSUIDForMetric(final String query_string, TSDB tsdb) { } catch (IllegalArgumentException e) { throw new BadRequestException(e); } - final TreeMap sortedTags = new TreeMap(tags); + + // sort the UIDs on tagk values + final ByteMap tag_uids = new ByteMap(); + for (final Entry pair : tags.entrySet()) { + tag_uids.put(tsdb.getUID(UniqueIdType.TAGK, pair.getKey()), + tsdb.getUID(UniqueIdType.TAGV, pair.getValue())); + } + // Byte Buffer to generate TSUID, pre allocated to the size of the TSUID final ByteArrayOutputStream buf = new ByteArrayOutputStream( - TSDB.metrics_width() + sortedTags.size() * + TSDB.metrics_width() + tag_uids.size() * (TSDB.tagk_width() + TSDB.tagv_width())); try { - buf.write(tsdb.getUID(UniqueIdType.METRIC, metric)); - for (Entry e: sortedTags.entrySet()) { - buf.write(tsdb.getUID(UniqueIdType.TAGK, e.getKey()), 0, 3); - buf.write(tsdb.getUID(UniqueIdType.TAGV, e.getValue()), 0, 3); + buf.write(tsdb.getUID(UniqueIdType.METRIC, metric)); + for (final Entry uids: tag_uids.entrySet()) { + buf.write(uids.getKey()); + buf.write(uids.getValue()); } } catch (IOException e) { throw new BadRequestException(e);