open locks

pull/6763/head
Halil Ozan Akgul 2023-03-09 12:12:28 +03:00
parent 963712897b
commit e8b31058e7
1 changed files with 25 additions and 20 deletions

View File

@ -93,10 +93,11 @@ citus_stats_tenants(PG_FUNCTION_ARGS)
PG_RETURN_VOID(); PG_RETURN_VOID();
} }
//!!!!!!!LWLockAcquire(&monitor->lock, LW_EXCLUSIVE); LWLockAcquire(&monitor->lock, LW_EXCLUSIVE);
monitor->periodStart = monitor->periodStart + monitor->periodStart = monitor->periodStart +
((monitoringTime - monitor->periodStart) / CitusStatsTenantsPeriod) * ((monitoringTime - monitor->periodStart) /
CitusStatsTenantsPeriod) *
CitusStatsTenantsPeriod; CitusStatsTenantsPeriod;
int numberOfRowsToReturn = 0; int numberOfRowsToReturn = 0;
@ -132,7 +133,7 @@ citus_stats_tenants(PG_FUNCTION_ARGS)
tuplestore_putvalues(tupleStore, tupleDescriptor, values, isNulls); tuplestore_putvalues(tupleStore, tupleDescriptor, values, isNulls);
} }
//!!!!!!!LWLockRelease(&monitor->lock); LWLockRelease(&monitor->lock);
PG_RETURN_VOID(); PG_RETURN_VOID();
} }
@ -144,7 +145,7 @@ citus_stats_tenants(PG_FUNCTION_ARGS)
void void
AttributeQueryIfAnnotated(const char *query_string, CmdType commandType) AttributeQueryIfAnnotated(const char *query_string, CmdType commandType)
{ {
// attributeToTenant = NULL; /* attributeToTenant = NULL; */
attributeCommandType = commandType; attributeCommandType = commandType;
@ -183,9 +184,10 @@ AttributeQueryIfAnnotated(const char *query_string, CmdType commandType)
while (t) while (t)
{ {
colocationGroupId *= 10; colocationGroupId *= 10;
colocationGroupId += t%10; colocationGroupId += t % 10;
t/=10; t /= 10;
} }
/* hack to get a clean copy of the tenant id string */ /* hack to get a clean copy of the tenant id string */
char tenantEndTmp = *tenantEnd; char tenantEndTmp = *tenantEnd;
*tenantEnd = '\0'; *tenantEnd = '\0';
@ -198,12 +200,12 @@ AttributeQueryIfAnnotated(const char *query_string, CmdType commandType)
quote_literal_cstr(tenantId)))); quote_literal_cstr(tenantId))));
} }
// attributeToTenant = (char *) malloc(strlen(tenantId)); /* attributeToTenant = (char *) malloc(strlen(tenantId)); */
strcpy(attributeToTenant, tenantId); strcpy(attributeToTenant, tenantId);
} }
else else
{ {
//Assert(attributeToTenant == NULL); /*Assert(attributeToTenant == NULL); */
} }
/*DetachSegment(); */ /*DetachSegment(); */
@ -275,10 +277,11 @@ AttributeMetricsIfApplicable()
MultiTenantMonitor *monitor = GetMultiTenantMonitor(); MultiTenantMonitor *monitor = GetMultiTenantMonitor();
//!!!!!!!LWLockAcquire(&monitor->lock, LW_SHARED); LWLockAcquire(&monitor->lock, LW_SHARED);
monitor->periodStart = monitor->periodStart + monitor->periodStart = monitor->periodStart +
((queryTime - monitor->periodStart) / CitusStatsTenantsPeriod) * ((queryTime - monitor->periodStart) /
CitusStatsTenantsPeriod) *
CitusStatsTenantsPeriod; CitusStatsTenantsPeriod;
int tenantIndex = FindTenantStats(monitor); int tenantIndex = FindTenantStats(monitor);
@ -289,7 +292,7 @@ AttributeMetricsIfApplicable()
} }
TenantStats *tenantStats = &monitor->tenants[tenantIndex]; TenantStats *tenantStats = &monitor->tenants[tenantIndex];
//!!!!!!!LWLockAcquire(&tenantStats->lock, LW_EXCLUSIVE); LWLockAcquire(&tenantStats->lock, LW_EXCLUSIVE);
UpdatePeriodsIfNecessary(monitor, tenantStats); UpdatePeriodsIfNecessary(monitor, tenantStats);
tenantStats->lastQueryTime = queryTime; tenantStats->lastQueryTime = queryTime;
@ -308,15 +311,16 @@ AttributeMetricsIfApplicable()
while (tenantIndex != 0 && while (tenantIndex != 0 &&
monitor->tenants[tenantIndex - 1].score < tenantStats->score) monitor->tenants[tenantIndex - 1].score < tenantStats->score)
{ {
//!!!!!!!LWLockAcquire(&monitor->tenants[tenantIndex - 1].lock, LW_EXCLUSIVE); LWLockAcquire(&monitor->tenants[tenantIndex - 1].lock, LW_EXCLUSIVE);
ReduceScoreIfNecessary(monitor, &monitor->tenants[tenantIndex - 1], queryTime); ReduceScoreIfNecessary(monitor, &monitor->tenants[tenantIndex - 1],
queryTime);
TenantStats tempTenant = monitor->tenants[tenantIndex]; TenantStats tempTenant = monitor->tenants[tenantIndex];
monitor->tenants[tenantIndex] = monitor->tenants[tenantIndex - 1]; monitor->tenants[tenantIndex] = monitor->tenants[tenantIndex - 1];
monitor->tenants[tenantIndex - 1] = tempTenant; monitor->tenants[tenantIndex - 1] = tempTenant;
//!!!!!!!LWLockRelease(&monitor->tenants[tenantIndex - 1].lock); LWLockRelease(&monitor->tenants[tenantIndex - 1].lock);
tenantIndex--; tenantIndex--;
} }
@ -334,8 +338,8 @@ AttributeMetricsIfApplicable()
tenantStats->totalInsertTime += cpu_time_used; tenantStats->totalInsertTime += cpu_time_used;
} }
//!!!!!!!LWLockRelease(&tenantStats->lock); LWLockRelease(&tenantStats->lock);
//!!!!!!!LWLockRelease(&monitor->lock); LWLockRelease(&monitor->lock);
/* /*
* We keep up to CitusStatsTenantsLimit * 3 tenants instead of CitusStatsTenantsLimit, * We keep up to CitusStatsTenantsLimit * 3 tenants instead of CitusStatsTenantsLimit,
@ -345,19 +349,20 @@ AttributeMetricsIfApplicable()
*/ */
if (monitor->tenantCount >= CitusStatsTenantsLimit * 3) if (monitor->tenantCount >= CitusStatsTenantsLimit * 3)
{ {
//!!!!!!!LWLockAcquire(&monitor->lock, LW_EXCLUSIVE); LWLockAcquire(&monitor->lock, LW_EXCLUSIVE);
monitor->tenantCount = CitusStatsTenantsLimit * 2; monitor->tenantCount = CitusStatsTenantsLimit * 2;
//!!!!!!!LWLockRelease(&monitor->lock); LWLockRelease(&monitor->lock);
} }
if (MultiTenantMonitoringLogLevel != CITUS_LOG_LEVEL_OFF) if (MultiTenantMonitoringLogLevel != CITUS_LOG_LEVEL_OFF)
{ {
ereport(NOTICE, (errmsg("total select count = %d, total CPU time = %f to tenant: %s", ereport(NOTICE, (errmsg("total select count = %d, total CPU time = %f "
"to tenant: %s",
tenantStats->selectCount, tenantStats->totalSelectTime, tenantStats->selectCount, tenantStats->totalSelectTime,
tenantStats->tenantAttribute))); tenantStats->tenantAttribute)));
} }
} }
//attributeToTenant = NULL; /*attributeToTenant = NULL; */
} }