Skip to content

Commit fe5ebeb

Browse files
committed
fix bug in /api/search/lookup
1 parent 649bc76 commit fe5ebeb

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/core/query.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,10 +1481,16 @@ QueryExecutor::http_get_api_search_lookup_handler(HttpRequest& request, HttpResp
14811481
n += snprintf(resp_buff+n, size-n, "{\"tsuid\":\"%09X\",\"metric\":\"%s\",\"tags\":{",
14821482
ts->get_id(), metric);
14831483

1484-
for (auto tag = ts->get_tags(); tag != nullptr; tag = tag->next())
1484+
Tag *tags = ts->get_tags();
1485+
for (auto tag = tags; tag != nullptr; tag = tag->next())
14851486
n += snprintf(resp_buff+n, size-n, "\"%s\":\"%s\",", tag->m_key, tag->m_value);
14861487

1487-
if (ts->get_tags() != nullptr) n--;
1488+
if (tags != nullptr)
1489+
{
1490+
n--;
1491+
Tag::free_list(tags, false);
1492+
}
1493+
14881494
n += snprintf(resp_buff+n, size-n, "}},");
14891495
}
14901496

src/core/tsdb.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -681,10 +681,12 @@ Mapping::init_measurement(Measurement *mm, const char *measurement, char *tags,
681681
MetaFile::instance()->add_measurement(measurement, tags, fields);
682682
}
683683

684+
// 'tsv' does NOT have to be empty when calling this function
684685
void
685686
Mapping::query_for_ts(Tag *tags, std::unordered_set<TimeSeries*>& tsv, const char *key, bool explicit_tags)
686687
{
687688
int tag_count = TagOwner::get_tag_count(tags, true);
689+
auto original_size = tsv.size();
688690

689691
if ((key != nullptr) && (tag_count == m_tag_count.load()))
690692
{
@@ -719,7 +721,7 @@ Mapping::query_for_ts(Tag *tags, std::unordered_set<TimeSeries*>& tsv, const cha
719721
}
720722
}
721723

722-
if (tsv.empty())
724+
if (tsv.size() == original_size)
723725
{
724726
if (tags == nullptr)
725727
{
@@ -1584,7 +1586,7 @@ Tsdb::query_for_ts(Tag *tags, std::unordered_set<TimeSeries*>& tsv)
15841586
get_all_mappings(mappings);
15851587

15861588
for (auto mapping: mappings)
1587-
query_for_ts(mapping->get_metric(), tags, tsv, nullptr, false);
1589+
mapping->query_for_ts(tags, tsv, nullptr, false);
15881590
}
15891591

15901592
/* The 'key' should not include the special '_field' tag.

0 commit comments

Comments
 (0)