Skip to content

Commit ae964e8

Browse files
committed
Update waterlevel metric
fixed double send
1 parent 87bcb3a commit ae964e8

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

statshouse.hpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1304,8 +1304,10 @@ class Registry {
13041304
*ptr->queue_ptr = alloc_bucket(ptr->key, ptr->timestamp);
13051305
{
13061306
std::lock_guard<std::mutex> bucket_lock{ptr->mu};
1307+
if (ptr->waterlevel == 0 || ptr->last_flush_timestamp < ptr->timestamp) {
1308+
std::swap((*ptr->queue_ptr)->value, ptr->value);
1309+
}
13071310
ptr->timestamp = timestamp;
1308-
std::swap((*ptr->queue_ptr)->value, ptr->value);
13091311
if (value.increment && !(*ptr->queue_ptr)->value.values.empty()) {
13101312
ptr->value.values.push_back((*ptr->queue_ptr)->value.values.back());
13111313
ptr->value.size = 1;
@@ -1353,13 +1355,15 @@ class Registry {
13531355
if (!ptr->value.empty() && (ptr->waterlevel == 0 || ptr->last_flush_timestamp < now)) {
13541356
buffer[count_flushed] = alloc_bucket(ptr->key, ptr->timestamp);
13551357
std::swap(buffer[count_flushed]->value, ptr->value);
1356-
if (ptr->waterlevel != 0 && !buffer[count_flushed]->value.values.empty()) {
1357-
buffer[count_flushed]->waterlevel = 1;
1358-
ptr->value.values.push_back(buffer[count_flushed]->value.values.back());
1359-
ptr->value.size = 1;
1358+
if (ptr->waterlevel != 0) {
1359+
if (!buffer[count_flushed]->value.values.empty()) {
1360+
buffer[count_flushed]->waterlevel = 1;
1361+
ptr->value.values.push_back(buffer[count_flushed]->value.values.back());
1362+
ptr->value.size = 1;
1363+
}
1364+
ptr->last_flush_timestamp = now;
13601365
}
13611366
++count_flushed;
1362-
ptr->last_flush_timestamp = now;
13631367
}
13641368
}
13651369
// pop front

0 commit comments

Comments
 (0)