mirror of https://github.com/citusdata/citus.git
Remove unneccesarry locks and add comments
parent
779af6a7b4
commit
817b1dfb64
|
@ -128,25 +128,24 @@ citus_stat_tenants_local(PG_FUNCTION_ARGS)
|
||||||
StatTenantsLimit);
|
StatTenantsLimit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Allocate an array to hold the tenants.
|
||||||
TenantStats **stats = palloc(tenantStatsCount *
|
TenantStats **stats = palloc(tenantStatsCount *
|
||||||
sizeof(TenantStats *));
|
sizeof(TenantStats *));
|
||||||
|
|
||||||
HASH_SEQ_STATUS hash_seq;
|
HASH_SEQ_STATUS hash_seq;
|
||||||
TenantStats *stat;
|
TenantStats *stat;
|
||||||
|
|
||||||
|
// Get all the tenants from the hash table.
|
||||||
int j = 0;
|
int j = 0;
|
||||||
hash_seq_init(&hash_seq, monitor->tenants);
|
hash_seq_init(&hash_seq, monitor->tenants);
|
||||||
while ((stat = hash_seq_search(&hash_seq)) != NULL)
|
while ((stat = hash_seq_search(&hash_seq)) != NULL)
|
||||||
{
|
{
|
||||||
SpinLockAcquire(&stat->lock);
|
|
||||||
|
|
||||||
stats[j++] = stat;
|
stats[j++] = stat;
|
||||||
UpdatePeriodsIfNecessary(stat, monitoringTime);
|
UpdatePeriodsIfNecessary(stat, monitoringTime);
|
||||||
ReduceScoreIfNecessary(stat, monitoringTime);
|
ReduceScoreIfNecessary(stat, monitoringTime);
|
||||||
|
|
||||||
SpinLockRelease(&stat->lock);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sort the tenants by their score.
|
||||||
SafeQsort(stats, j, sizeof(TenantStats *),
|
SafeQsort(stats, j, sizeof(TenantStats *),
|
||||||
CompareTenantScore);
|
CompareTenantScore);
|
||||||
|
|
||||||
|
@ -157,8 +156,6 @@ citus_stat_tenants_local(PG_FUNCTION_ARGS)
|
||||||
|
|
||||||
TenantStats *tenantStats = stats[i];
|
TenantStats *tenantStats = stats[i];
|
||||||
|
|
||||||
SpinLockAcquire(&tenantStats->lock);
|
|
||||||
|
|
||||||
values[0] = Int32GetDatum(tenantStats->key.colocationGroupId);
|
values[0] = Int32GetDatum(tenantStats->key.colocationGroupId);
|
||||||
values[1] = PointerGetDatum(cstring_to_text(tenantStats->key.tenantAttribute));
|
values[1] = PointerGetDatum(cstring_to_text(tenantStats->key.tenantAttribute));
|
||||||
values[2] = Int32GetDatum(tenantStats->readsInThisPeriod);
|
values[2] = Int32GetDatum(tenantStats->readsInThisPeriod);
|
||||||
|
@ -171,8 +168,6 @@ citus_stat_tenants_local(PG_FUNCTION_ARGS)
|
||||||
values[7] = Float8GetDatum(tenantStats->cpuUsageInLastPeriod);
|
values[7] = Float8GetDatum(tenantStats->cpuUsageInLastPeriod);
|
||||||
values[8] = Int64GetDatum(tenantStats->score);
|
values[8] = Int64GetDatum(tenantStats->score);
|
||||||
|
|
||||||
SpinLockRelease(&tenantStats->lock);
|
|
||||||
|
|
||||||
tuplestore_putvalues(tupleStore, tupleDescriptor, values, isNulls);
|
tuplestore_putvalues(tupleStore, tupleDescriptor, values, isNulls);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,22 +207,7 @@ citus_stat_tenants_local_reset(PG_FUNCTION_ARGS)
|
||||||
hash_seq_init(&hash_seq, monitor->tenants);
|
hash_seq_init(&hash_seq, monitor->tenants);
|
||||||
while ((stats = hash_seq_search(&hash_seq)) != NULL)
|
while ((stats = hash_seq_search(&hash_seq)) != NULL)
|
||||||
{
|
{
|
||||||
bool found = false;
|
hash_search(monitor->tenants, &stats->key, HASH_REMOVE, NULL);
|
||||||
hash_search(monitor->tenants, &stats->key, HASH_REMOVE, &found);
|
|
||||||
|
|
||||||
if (found)
|
|
||||||
{
|
|
||||||
stats->writesInLastPeriod = 0;
|
|
||||||
stats->writesInThisPeriod = 0;
|
|
||||||
stats->readsInLastPeriod = 0;
|
|
||||||
stats->readsInThisPeriod = 0;
|
|
||||||
stats->cpuUsageInLastPeriod = 0;
|
|
||||||
stats->cpuUsageInThisPeriod = 0;
|
|
||||||
stats->score = 0;
|
|
||||||
stats->lastScoreReduction = 0;
|
|
||||||
|
|
||||||
/* pfree(stats); */
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LWLockRelease(&monitor->lock);
|
LWLockRelease(&monitor->lock);
|
||||||
|
@ -739,6 +719,15 @@ CreateTenantStats(MultiTenantMonitor *monitor, TimestampTz queryTime)
|
||||||
|
|
||||||
pfree(key);
|
pfree(key);
|
||||||
|
|
||||||
|
stats->writesInLastPeriod = 0;
|
||||||
|
stats->writesInThisPeriod = 0;
|
||||||
|
stats->readsInLastPeriod = 0;
|
||||||
|
stats->readsInThisPeriod = 0;
|
||||||
|
stats->cpuUsageInLastPeriod = 0;
|
||||||
|
stats->cpuUsageInThisPeriod = 0;
|
||||||
|
stats->score = 0;
|
||||||
|
stats->lastScoreReduction = 0;
|
||||||
|
|
||||||
if (!found)
|
if (!found)
|
||||||
{
|
{
|
||||||
/* initialize the stats lock for the new entry in the hash table */
|
/* initialize the stats lock for the new entry in the hash table */
|
||||||
|
|
Loading…
Reference in New Issue