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

Fix inserting to pg_dist_object for queries from other nodes #7402

Merged
merged 6 commits into from
Jan 11, 2024

Conversation

halilozanakgul
Copy link
Contributor

Running a query from a Citus non-main database that inserts to pg_dist_object requires a new connection to the main database itself. This PR adds that connection to the main database.

Copy link

codecov bot commented Jan 4, 2024

Codecov Report

Merging #7402 (e55d8fe) into main (00068e0) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7402   +/-   ##
=======================================
  Coverage   89.61%   89.61%           
=======================================
  Files         280      280           
  Lines       60310    60318    +8     
  Branches     7507     7509    +2     
=======================================
+ Hits        54044    54052    +8     
+ Misses       4113     4111    -2     
- Partials     2153     2155    +2     

Comment on lines 8 to 10
c.sql("SELECT citus_set_coordinator_host('localhost')")

Copy link
Contributor

@JelteF JelteF Jan 4, 2024

Choose a reason for hiding this comment

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

Is this actually necessary? Afaict CitusCluster its __init__ function already does this. If that doesn't work for some reason we should fix it there instead of working around the problem here.

i.e. this should be removed afaict.

@@ -60,14 +73,23 @@ def test_main_commited_outer_not_yet(cluster):
int(role_after_commit) == 1
), "role is not created during recovery despite committing"

# check that the user is on pg_dist_object on the coordinator after transaction recovery
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# check that the user is on pg_dist_object on the coordinator after transaction recovery
# check that the user is in pg_dist_object on the coordinator after transaction recovery

assert (
int(pdo_coordinator_after_commit) == 1
), "role is not on pg_dist_object on coordinator after recovery despite committing"

# check that the user is on pg_dist_object on the worker after transaction recovery
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# check that the user is on pg_dist_object on the worker after transaction recovery
# check that the user is in pg_dist_object on the worker after transaction recovery

assert (
int(pdo_coordinator_after_recovery) == 0
), "role is on pg_dist_object on coordinator after recovery despite aborting"

# check that the user is not on pg_dist_object on the worker after transaction recovery
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# check that the user is not on pg_dist_object on the worker after transaction recovery
# check that the user is not in pg_dist_object on the worker after transaction recovery

@@ -142,13 +181,22 @@ def test_main_commited_outer_aborted(cluster):
int(role_after_recovery) == 0
), "role is created during recovery despite aborting"

# check that the user is not on pg_dist_object on the coordinator after transaction recovery
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# check that the user is not on pg_dist_object on the coordinator after transaction recovery
# check that the user is not in pg_dist_object on the coordinator after transaction recovery

@@ -80,7 +81,8 @@ mark_object_distributed(PG_FUNCTION_ARGS)
Oid objectId = PG_GETARG_OID(2);
ObjectAddress *objectAddress = palloc0(sizeof(ObjectAddress));
ObjectAddressSet(*objectAddress, classId, objectId);
MarkObjectDistributedWithName(objectAddress, objectName);
bool useConnectionForLocalQuery = true;
Copy link
Contributor

@JelteF JelteF Jan 4, 2024

Choose a reason for hiding this comment

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

I think it's useful to say why we want true here (I pretty much copy pasted the one you had in the other spot, feel free to change)

Suggested change
bool useConnectionForLocalQuery = true;
/*
* This function is called when a query is run from a Citus non-main database. We need to insert into pg_dist_object
* over a connection to make sure 2PC still works.
*/
bool useConnectionForLocalQuery = true;

Comment on lines 8 to 9
c.sql("ALTER SYSTEM SET citus.local_hostname TO '127.0.0.1'")
c.sql("SELECT pg_reload_conf()")
Copy link
Contributor

Choose a reason for hiding this comment

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

This should not be necessary. In production environments it's expected that citus.local_hostname is not the same as the value in pg_dist_node. So if the tests require that to pass, then that's a big problem (because that means they would fail in production environments).

Copy link
Contributor

@JelteF JelteF left a comment

Choose a reason for hiding this comment

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

We should fix/work around the citus.local_hostname thing. If we work around it, that should happen in the C code not in the test code.

@JelteF JelteF force-pushed the fix_other_db_pg_dist_obj_update branch from 73ff86f to e55d8fe Compare January 11, 2024 10:28
@halilozanakgul halilozanakgul merged commit 739c6d2 into main Jan 11, 2024
157 checks passed
@halilozanakgul halilozanakgul deleted the fix_other_db_pg_dist_obj_update branch January 11, 2024 13:05
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