Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make citus_stat_tenants work with schema-based tenants. #6936

Merged
merged 27 commits into from Jun 13, 2023

Conversation

gokhangulbiz
Copy link
Contributor

@gokhangulbiz gokhangulbiz commented May 23, 2023

DESCRIPTION: Enabling citus_stat_tenants to support schema-based tenants.

This pull request modifies the existing logic to enable tenant monitoring with schema-based tenants. The changes made are as follows:

  • If a query has a partitionKeyValue (which serves as a tenant key/identifier for distributed tables), Citus annotates the query with both the partitionKeyValue and colocationId. This allows for accurate tracking of the query.
  • If a query does not have a partitionKeyValue, but its colocationId belongs to a distributed schema, Citus annotates the query with only the colocationId. The tenant monitor can then easily look up the schema to determine if it's a distributed schema and make a decision on whether to track the query.

Base automatically changed from schema-based-sharding-via-guc to main May 26, 2023 07:50
@gokhangulbiz gokhangulbiz force-pushed the gokhangulbiz/schema-based-tenant-monitoring branch from e3e140d to d76e072 Compare May 29, 2023 07:49
@codecov
Copy link

codecov bot commented May 29, 2023

Codecov Report

Merging #6936 (91661a6) into main (5acbd73) will increase coverage by 0.00%.
The diff coverage is 100.00%.

❗ Current head 91661a6 differs from pull request most recent head 4dc9d23. Consider uploading reports for the commit 4dc9d23 to get more accurate results

@@           Coverage Diff            @@
##             main    #6936    +/-   ##
========================================
  Coverage   93.27%   93.28%            
========================================
  Files         272      272            
  Lines       58137    57942   -195     
========================================
- Hits        54230    54049   -181     
+ Misses       3907     3893    -14     

@gokhangulbiz gokhangulbiz force-pushed the gokhangulbiz/schema-based-tenant-monitoring branch from d76e072 to 4923ad4 Compare May 29, 2023 08:11
@gokhangulbiz gokhangulbiz changed the title Initial implementation of schema-based tenants integration to citus_s… Make citus_stat_tenants work with schema-based tenants. May 29, 2023
@gokhangulbiz gokhangulbiz marked this pull request as ready for review May 29, 2023 08:26
@gokhangulbiz gokhangulbiz requested a review from JelteF May 29, 2023 08:27
@gokhangulbiz gokhangulbiz force-pushed the gokhangulbiz/schema-based-tenant-monitoring branch from aeb2288 to 83b5f0e Compare June 5, 2023 14:06
*/
static void
SetColocationIdAndPartitionKeyValueForTasks(List *taskList, Job *workerJob)
{
if (workerJob->colocationId != 0 &&
Copy link
Contributor

@JelteF JelteF Jun 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can keep the workerJob->colocationId != 0 check, might be a nice optimization for multi shard queries with many tasks.

gokhangulbiz and others added 2 commits June 7, 2023 10:46
Co-authored-by: Jelte Fennema <jelte.fennema@microsoft.com>
@gokhangulbiz gokhangulbiz force-pushed the gokhangulbiz/schema-based-tenant-monitoring branch from 9e2b205 to 80a52a0 Compare June 7, 2023 07:57
Comment on lines 241 to 252
/*
* if tenantId is NULL, it must be a schema-based tenant and
* we try to get the tenantId from the colocationId to lookup schema name and use it as a tenantId
*/
if (tenantId == NULL)
{
if (!IsTenantSchemaColocationGroup(colocationId))
{
return;
}

}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this check is needed anymore. We only annotate the query if with tenantId=NULL if IsTenantSchemaColocationGroup returned true. So no need to re-check it here again.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, except for locally executed queries (ex: queries to reference tables) that directly follow the AttributeTask(..) flow without being annotated. We can move this check to local_executor. Let me know your thoughts.

@@ -683,7 +740,8 @@ FindTenantStats(MultiTenantMonitor *monitor)
for (int i = 0; i < monitor->tenantCount; i++)
{
TenantStats *tenantStats = &monitor->tenants[i];
if (strcmp(tenantStats->tenantAttribute, AttributeToTenant) == 0 &&

if (strncmp(tenantStats->tenantAttribute, AttributeToTenant, MAX_TENANT_ATTRIBUTE_LENGTH) == 0 &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this change necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a solid reason. I was just curious about its impact on performance. In any case, it's no longer necessary.

@gokhangulbiz gokhangulbiz force-pushed the gokhangulbiz/schema-based-tenant-monitoring branch 2 times, most recently from c1aaae8 to 0bc4ced Compare June 9, 2023 13:24
@gokhangulbiz gokhangulbiz force-pushed the gokhangulbiz/schema-based-tenant-monitoring branch from 0bc4ced to 56691d7 Compare June 9, 2023 13:41
@@ -173,6 +173,6 @@ DETAIL: drop cascades to table ab
drop cascades to table single_hash_repartition_first
drop cascades to table single_hash_repartition_second
drop cascades to table ref_table
drop cascades to table ref_table_361397
drop cascades to table ref_table_361399
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you instead fix this by running SET client_min_messages TO WARNING; before the DROP SCHEMA? That will make this diff is not necessary anymore.

@gokhangulbiz gokhangulbiz force-pushed the gokhangulbiz/schema-based-tenant-monitoring branch from 0585a36 to dcfe045 Compare June 12, 2023 09:02
@gokhangulbiz gokhangulbiz requested a review from JelteF June 13, 2023 09:36
@gokhangulbiz gokhangulbiz force-pushed the gokhangulbiz/schema-based-tenant-monitoring branch from cc11493 to 10d42ca Compare June 13, 2023 10:49
@gokhangulbiz gokhangulbiz enabled auto-merge (squash) June 13, 2023 10:52
@gokhangulbiz gokhangulbiz force-pushed the gokhangulbiz/schema-based-tenant-monitoring branch from 10d42ca to 4dc9d23 Compare June 13, 2023 10:56
@gokhangulbiz gokhangulbiz merged commit e0ccd15 into main Jun 13, 2023
111 checks passed
@gokhangulbiz gokhangulbiz deleted the gokhangulbiz/schema-based-tenant-monitoring branch June 13, 2023 11:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants