mirror of https://github.com/citusdata/citus.git
Fix citus_stat_tenants period updating bug (#6833)
Fixes the bug that causes updating the citus_stat_tenants periods incorrectly. `TimestampDifferenceExceeds` expects the difference in milliseconds but it was microseconds, this is fixed. `tenantStats->lastQueryTime` was updated during monitoring too, now it's updated only when there are tenant queries.pull/6845/head
parent
a20f7e1a55
commit
8b50e95dc8
|
@ -56,7 +56,7 @@ static int CompareTenantScore(const void *leftElement, const void *rightElement)
|
|||
static void UpdatePeriodsIfNecessary(TenantStats *tenantStats, TimestampTz queryTime);
|
||||
static void ReduceScoreIfNecessary(TenantStats *tenantStats, TimestampTz queryTime);
|
||||
static void EvictTenantsIfNecessary(TimestampTz queryTime);
|
||||
static void RecordTenantStats(TenantStats *tenantStats);
|
||||
static void RecordTenantStats(TenantStats *tenantStats, TimestampTz queryTime);
|
||||
static void CreateMultiTenantMonitor(void);
|
||||
static MultiTenantMonitor * CreateSharedMemoryForMultiTenantMonitor(void);
|
||||
static MultiTenantMonitor * GetMultiTenantMonitor(void);
|
||||
|
@ -345,7 +345,7 @@ AttributeMetricsIfApplicable()
|
|||
|
||||
UpdatePeriodsIfNecessary(tenantStats, queryTime);
|
||||
ReduceScoreIfNecessary(tenantStats, queryTime);
|
||||
RecordTenantStats(tenantStats);
|
||||
RecordTenantStats(tenantStats, queryTime);
|
||||
|
||||
LWLockRelease(&tenantStats->lock);
|
||||
}
|
||||
|
@ -372,7 +372,7 @@ AttributeMetricsIfApplicable()
|
|||
|
||||
UpdatePeriodsIfNecessary(tenantStats, queryTime);
|
||||
ReduceScoreIfNecessary(tenantStats, queryTime);
|
||||
RecordTenantStats(tenantStats);
|
||||
RecordTenantStats(tenantStats, queryTime);
|
||||
|
||||
LWLockRelease(&tenantStats->lock);
|
||||
}
|
||||
|
@ -396,6 +396,7 @@ static void
|
|||
UpdatePeriodsIfNecessary(TenantStats *tenantStats, TimestampTz queryTime)
|
||||
{
|
||||
long long int periodInMicroSeconds = StatTenantsPeriod * USECS_PER_SEC;
|
||||
long long int periodInMilliSeconds = StatTenantsPeriod * 1000;
|
||||
TimestampTz periodStart = queryTime - (queryTime % periodInMicroSeconds);
|
||||
|
||||
/*
|
||||
|
@ -416,14 +417,12 @@ UpdatePeriodsIfNecessary(TenantStats *tenantStats, TimestampTz queryTime)
|
|||
* If the last query is more than two periods ago, we clean the last period counts too.
|
||||
*/
|
||||
if (TimestampDifferenceExceeds(tenantStats->lastQueryTime, periodStart,
|
||||
periodInMicroSeconds))
|
||||
periodInMilliSeconds))
|
||||
{
|
||||
tenantStats->writesInLastPeriod = 0;
|
||||
|
||||
tenantStats->readsInLastPeriod = 0;
|
||||
}
|
||||
|
||||
tenantStats->lastQueryTime = queryTime;
|
||||
}
|
||||
|
||||
|
||||
|
@ -503,7 +502,7 @@ EvictTenantsIfNecessary(TimestampTz queryTime)
|
|||
* RecordTenantStats records the query statistics for the tenant.
|
||||
*/
|
||||
static void
|
||||
RecordTenantStats(TenantStats *tenantStats)
|
||||
RecordTenantStats(TenantStats *tenantStats, TimestampTz queryTime)
|
||||
{
|
||||
if (tenantStats->score < LLONG_MAX - ONE_QUERY_SCORE)
|
||||
{
|
||||
|
@ -524,6 +523,8 @@ RecordTenantStats(TenantStats *tenantStats)
|
|||
{
|
||||
tenantStats->writesInThisPeriod++;
|
||||
}
|
||||
|
||||
tenantStats->lastQueryTime = queryTime;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -263,6 +263,19 @@ SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, q
|
|||
5 | 0 | 0 | 0 | 1
|
||||
(2 rows)
|
||||
|
||||
SELECT sleep_until_next_period();
|
||||
sleep_until_next_period
|
||||
---------------------------------------------------------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, query_count_in_this_period, query_count_in_last_period FROM citus_stat_tenants_local ORDER BY tenant_attribute;
|
||||
tenant_attribute | read_count_in_this_period | read_count_in_last_period | query_count_in_this_period | query_count_in_last_period
|
||||
---------------------------------------------------------------------
|
||||
1 | 0 | 0 | 0 | 0
|
||||
5 | 0 | 0 | 0 | 0
|
||||
(2 rows)
|
||||
|
||||
\c - - - :master_port
|
||||
SET search_path TO citus_stat_tenants;
|
||||
-- test logs
|
||||
|
|
|
@ -92,6 +92,10 @@ SELECT sleep_until_next_period();
|
|||
|
||||
SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, query_count_in_this_period, query_count_in_last_period FROM citus_stat_tenants_local ORDER BY tenant_attribute;
|
||||
|
||||
SELECT sleep_until_next_period();
|
||||
|
||||
SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, query_count_in_this_period, query_count_in_last_period FROM citus_stat_tenants_local ORDER BY tenant_attribute;
|
||||
|
||||
\c - - - :master_port
|
||||
SET search_path TO citus_stat_tenants;
|
||||
|
||||
|
|
Loading…
Reference in New Issue