Include update and delete queries

pull/6753/head
Halil Ozan Akgul 2023-03-14 15:52:36 +03:00
parent 2aa30dd303
commit 5e9e67e5bf
5 changed files with 54 additions and 38 deletions

View File

@ -1997,11 +1997,25 @@ GenerateSingleShardRouterTaskList(Job *job, List *relationShardList,
}
else
{
Datum partitionColumnValue;
Oid partitionColumnType = 0;
char *partitionColumnString = NULL;
if (job->partitionKeyValue != NULL)
{
partitionColumnValue = job->partitionKeyValue->constvalue;
partitionColumnType = job->partitionKeyValue->consttype;
partitionColumnString = DatumToString(partitionColumnValue,
partitionColumnType);
}
SetJobColocationId(job);
job->taskList = SingleShardTaskList(originalQuery, job->jobId,
relationShardList, placementList,
shardId,
job->parametersInJobQueryResolved,
isLocalTableModification, "", -1);
isLocalTableModification,
partitionColumnString, job->colocationId);
}
}

View File

@ -127,12 +127,12 @@ citus_stats_tenants(PG_FUNCTION_ARGS)
values[0] = Int32GetDatum(tenantStats->colocationGroupId);
values[1] = PointerGetDatum(cstring_to_text(tenantStats->tenantAttribute));
values[2] = Int32GetDatum(tenantStats->selectsInThisPeriod);
values[3] = Int32GetDatum(tenantStats->selectsInLastPeriod);
values[4] = Int32GetDatum(tenantStats->selectsInThisPeriod +
tenantStats->insertsInThisPeriod);
values[5] = Int32GetDatum(tenantStats->selectsInLastPeriod +
tenantStats->insertsInLastPeriod);
values[2] = Int32GetDatum(tenantStats->readsInThisPeriod);
values[3] = Int32GetDatum(tenantStats->readsInLastPeriod);
values[4] = Int32GetDatum(tenantStats->readsInThisPeriod +
tenantStats->writesInThisPeriod);
values[5] = Int32GetDatum(tenantStats->readsInLastPeriod +
tenantStats->writesInLastPeriod);
values[6] = Int64GetDatum(tenantStats->score);
tuplestore_putvalues(tupleStore, tupleDescriptor, values, isNulls);
@ -347,15 +347,17 @@ AttributeMetricsIfApplicable()
if (attributeCommandType == CMD_SELECT)
{
tenantStats->selectCount++;
tenantStats->selectsInThisPeriod++;
tenantStats->totalSelectTime += cpu_time_used;
tenantStats->readCount++;
tenantStats->readsInThisPeriod++;
tenantStats->totalReadTime += cpu_time_used;
}
else if (attributeCommandType == CMD_INSERT)
else if (attributeCommandType == CMD_UPDATE ||
attributeCommandType == CMD_INSERT ||
attributeCommandType == CMD_DELETE)
{
tenantStats->insertCount++;
tenantStats->insertsInThisPeriod++;
tenantStats->totalInsertTime += cpu_time_used;
tenantStats->writeCount++;
tenantStats->writesInThisPeriod++;
tenantStats->totalWriteTime += cpu_time_used;
}
LWLockRelease(&monitor->lock);
@ -376,10 +378,10 @@ AttributeMetricsIfApplicable()
if (MultiTenantMonitoringLogLevel != CITUS_LOG_LEVEL_OFF)
{
ereport(NOTICE, (errmsg("total select count = %d, total CPU time = %f "
ereport(NOTICE, (errmsg("total read count = %d, total read CPU time = %f "
"to tenant: %s",
tenantStats->selectCount,
tenantStats->totalSelectTime,
tenantStats->readCount,
tenantStats->totalReadTime,
tenantStats->tenantAttribute)));
}
}
@ -405,13 +407,13 @@ UpdatePeriodsIfNecessary(MultiTenantMonitor *monitor, TenantStats *tenantStats)
* but there are some query count for this period we move them to the last period.
*/
if (tenantStats->lastQueryTime < monitor->periodStart &&
(tenantStats->insertsInThisPeriod || tenantStats->selectsInThisPeriod))
(tenantStats->writesInThisPeriod || tenantStats->readsInThisPeriod))
{
tenantStats->insertsInLastPeriod = tenantStats->insertsInThisPeriod;
tenantStats->insertsInThisPeriod = 0;
tenantStats->writesInLastPeriod = tenantStats->writesInThisPeriod;
tenantStats->writesInThisPeriod = 0;
tenantStats->selectsInLastPeriod = tenantStats->selectsInThisPeriod;
tenantStats->selectsInThisPeriod = 0;
tenantStats->readsInLastPeriod = tenantStats->readsInThisPeriod;
tenantStats->readsInThisPeriod = 0;
}
/*
@ -419,9 +421,9 @@ UpdatePeriodsIfNecessary(MultiTenantMonitor *monitor, TenantStats *tenantStats)
*/
if (tenantStats->lastQueryTime < monitor->periodStart - CitusStatsTenantsPeriod)
{
tenantStats->insertsInLastPeriod = 0;
tenantStats->writesInLastPeriod = 0;
tenantStats->selectsInLastPeriod = 0;
tenantStats->readsInLastPeriod = 0;
}
}

View File

@ -21,15 +21,15 @@ typedef struct TenantStats
int colocationGroupId;
int selectCount;
double totalSelectTime;
int selectsInLastPeriod;
int selectsInThisPeriod;
int readCount;
double totalReadTime;
int readsInLastPeriod;
int readsInThisPeriod;
int insertCount;
double totalInsertTime;
int insertsInLastPeriod;
int insertsInThisPeriod;
int writeCount;
double totalWriteTime;
int writesInLastPeriod;
int writesInThisPeriod;
time_t lastQueryTime;

View File

@ -44,9 +44,9 @@ SELECT create_reference_table('ref_tbl');
INSERT INTO dist_tbl VALUES (1, 'abcd');
INSERT INTO dist_tbl VALUES (2, 'abcd');
INSERT INTO dist_tbl VALUES (3, 'abcd');
INSERT INTO dist_tbl VALUES (4, 'abcd');
INSERT INTO dist_tbl VALUES (5, 'abcd');
UPDATE dist_tbl SET b = a + 1 WHERE a = 3;
UPDATE dist_tbl SET b = a + 1 WHERE a = 4;
DELETE FROM dist_tbl WHERE a = 5;
\c - - - :worker_1_port
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_stats_tenants 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

View File

@ -24,9 +24,9 @@ SELECT create_reference_table('ref_tbl');
INSERT INTO dist_tbl VALUES (1, 'abcd');
INSERT INTO dist_tbl VALUES (2, 'abcd');
INSERT INTO dist_tbl VALUES (3, 'abcd');
INSERT INTO dist_tbl VALUES (4, 'abcd');
INSERT INTO dist_tbl VALUES (5, 'abcd');
UPDATE dist_tbl SET b = a + 1 WHERE a = 3;
UPDATE dist_tbl SET b = a + 1 WHERE a = 4;
DELETE FROM dist_tbl WHERE a = 5;
\c - - - :worker_1_port
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_stats_tenants ORDER BY tenant_attribute;