Skip to content

Commit

Permalink
Fix #642 by sorting the tags properly on the bytes, NOT the string
Browse files Browse the repository at this point in the history
values. Sheesh. Thanks @wuxuehong214

Signed-off-by: Chris Larsen <[email protected]>
  • Loading branch information
manolama committed Dec 15, 2015
1 parent 37ca54e commit 3cd59be
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ guava-rpm-maker/\.project
src-main
src-test
plugin_test.jar
/bin/
21 changes: 15 additions & 6 deletions src/tsd/UniqueIdRpc.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()) {
Expand All @@ -565,16 +567,23 @@ private String getTSUIDForMetric(final String query_string, TSDB tsdb) {
} catch (IllegalArgumentException e) {
throw new BadRequestException(e);
}
final TreeMap<String, String> sortedTags = new TreeMap<String, String>(tags);

// sort the UIDs on tagk values
final ByteMap<byte[]> tag_uids = new ByteMap<byte[]>();
for (final Entry<String, String> 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<String, String> 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<byte[], byte[]> uids: tag_uids.entrySet()) {
buf.write(uids.getKey());
buf.write(uids.getValue());
}
} catch (IOException e) {
throw new BadRequestException(e);
Expand Down

0 comments on commit 3cd59be

Please sign in to comment.