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

PG17 compatibility: Resolve compilation issues #7699

Merged
merged 26 commits into from
Oct 17, 2024

Conversation

naisila
Copy link
Member

@naisila naisila commented Oct 6, 2024

PG17 compatibility - Part 1

This PR, together with #7700, provides successful compilation against PG17.0.

Notes to reviewer:

  • Review commit by commit - it's much cleaner that way.
  • When merged, Enable configure and add pg17 build test commits will be reverted. They are part of the PR to make sure that the PG17 build is actually successful - see Build for PG17 in the PR checks. These changes will be merged to the release-13.0 branch later, when the PG17 support is fully added.

(Original PR against the main branch #7651)

Copy link

codecov bot commented Oct 6, 2024

Codecov Report

Attention: Patch coverage is 92.50000% with 3 lines in your changes missing coverage. Please review.

Please upload report for BASE (release-13.0@9d36433). Learn more about missing BASE report.

Additional details and impacted files
@@               Coverage Diff               @@
##             release-13.0    #7699   +/-   ##
===============================================
  Coverage                ?   89.65%           
===============================================
  Files                   ?      274           
  Lines                   ?    59584           
  Branches                ?     7436           
===============================================
  Hits                    ?    53418           
  Misses                  ?     4035           
  Partials                ?     2131           

@naisila naisila changed the base branch from release-13.0 to naisila/foreach_macros October 6, 2024 19:46
@jmealo jmealo mentioned this pull request Oct 8, 2024
@jmealo
Copy link

jmealo commented Oct 8, 2024

I'm seeing a different issue compiling this branch on arm64/MacOS than I do on main against 16 (neither work, so this isn't a regression):

Against 17 (this branch):

Undefined symbols for architecture arm64:
  "_deparse_shard_query", referenced from:
      _GenerateTaskListWithColocatedIntermediateResults in repartition_executor.o
      _GenerateTaskListWithRedistributedResults in repartition_executor.o
      _DeparseTaskQuery in deparse_shard_query.o
      _CreateInsertSelectPlan in insert_select_planner.o
      _CacheLocalPlanForShardQuery in local_plan_cache.o
      _deparse_shard_query_test in deparse_shard_query.o
  "_generate_operator_name", referenced from:
      _GetFunctionDDLCommand in function.o
  "_generate_relation_name", referenced from:
      _PreprocessGrantStmt in grant.o
      _PreprocessAlterPolicyStmt in policy.o
      _pg_get_tableschemadef_string in citus_ruleutils.o
      _pg_get_tablecolumnoptionsdef_string in citus_ruleutils.o
      _pg_get_table_grants in citus_ruleutils.o
  "_getOwnedSequences_internal", referenced from:
      _ConvertTable in alter_table.o
      _ExtractDefaultColumnsAndOwnedSequences in sequence.o
  "_get_merged_argument_list", referenced from:
      _CallDistributedProcedureRemotely in call.o
  "_pg_get_query_def", referenced from:
      _BuildSelectStatementViaStdPlanner in combine_query_planner.o
      _DeparseTaskQuery in deparse_shard_query.o
      _CacheLocalPlanForShardQuery in local_plan_cache.o
      _CreatePhysicalDistributedPlan in multi_physical_planner.o
      _QueryPushdownSqlTaskList in multi_physical_planner.o
      _GenerateSubplansForSubqueriesAndCTEs in recursive_planning.o
      _RecursivelyPlanSubqueriesAndCTEs in recursive_planning.o
      ...
  "_pg_get_rule_expr", referenced from:
      _CallDistributedProcedureRemotely in call.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [citus.dylib] Error 1
make: *** [extension] Error 2

Main against 16

ld: warning: ignoring file '/opt/local/lib/libcurl.4.dylib': found architecture 'arm64', required architecture 'x86_64'
Undefined symbols for architecture x86_64:
  "_curl_easy_cleanup", referenced from:
      _CollectBasicUsageStatistics in statistics_collection.o
  "_curl_easy_getinfo", referenced from:
      _CollectBasicUsageStatistics in statistics_collection.o
  "_curl_easy_init", referenced from:
      _CollectBasicUsageStatistics in statistics_collection.o
  "_curl_easy_perform", referenced from:
      _CollectBasicUsageStatistics in statistics_collection.o
  "_curl_easy_setopt", referenced from:
      _CollectBasicUsageStatistics in statistics_collection.o
      _CollectBasicUsageStatistics in statistics_collection.o
      _CollectBasicUsageStatistics in statistics_collection.o
      _CollectBasicUsageStatistics in statistics_collection.o
      _CollectBasicUsageStatistics in statistics_collection.o
  "_curl_easy_strerror", referenced from:
      _CollectBasicUsageStatistics in statistics_collection.o
  "_curl_global_cleanup", referenced from:
      _CollectBasicUsageStatistics in statistics_collection.o
  "_curl_global_init", referenced from:
      _CollectBasicUsageStatistics in statistics_collection.o
  "_curl_slist_append", referenced from:
      _CollectBasicUsageStatistics in statistics_collection.o
      _CollectBasicUsageStatistics in statistics_collection.o
      _CollectBasicUsageStatistics in statistics_collection.o
  "_curl_slist_free_all", referenced from:
      _CollectBasicUsageStatistics in statistics_collection.o
  "_curl_version_info", referenced from:
      _WarnIfSyncDNS in statistics_collection.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [citus.dylib] Error 1
make: *** [extension] Error 2

if (es->memory)
{
MemoryContextSwitchTo(saved_ctx);
MemoryContextMemConsumed(planner_ctx, &mem_counters);
Copy link
Member

Choose a reason for hiding this comment

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

should we switch back to older context after L454

Copy link
Member Author

Choose a reason for hiding this comment

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

I followed the logic in the Postgres code here. Let me paste the relevant lines, where the context is not switched back. Do you think that is enough?
https://github.com/postgres/postgres/blob/REL_17_0/src/backend/commands/explain.c#L495-L512
https://github.com/postgres/postgres/blob/REL_17_0/src/backend/commands/prepare.c#L637-L642

@onurctirtir
Copy link
Member

onurctirtir commented Oct 15, 2024

Note to self; Only remaining commit to review is cfba6ff.


update: done

@onurctirtir
Copy link
Member

Btw, thank you for cleanly separating the work into commits, it made reviews so much easier!

@onurctirtir onurctirtir self-requested a review October 15, 2024 08:32
Copy link
Member

@onurctirtir onurctirtir left a comment

Choose a reason for hiding this comment

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

LGTM. @rajeshkt78, would you like to review cfba6ff since it introduces some changes to cdc subsystem, or should we just merge this?

@emelsimsek
Copy link
Contributor

Looks like PG 17 introduced a new ACL called ACL_MAINTAIN

PG commit:
ecb0fd33720fab91df1207e85704f382f55e1eb7
postgres/postgres@ecb0fd3

Our deparser does not handle that

elog(ERROR, "unrecognized aclright: %d", aclright);

I understand that this commit is for getting Citus compile against PG17.

Let's create an issue to track "ACL_MAINTAIN" should be supported.

src/include/pg_version_compat.h Outdated Show resolved Hide resolved
@emelsimsek
Copy link
Contributor

MergeAction can have 3 merge kinds (now enum) in PG17, write compat
Relevant PG commit:
0294df2f1f842dfb0eed79007b21016f486a3c6c
postgres/postgres@0294df2

New merge kinds should be handled in deparser and Merge logic in Citus.
- MATCHED BY SOURCE
- MATCHED_BY_TARGET

Let's track this as a github issue.

)

#endif
static inline CitusNode *
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we delete two lines here:

/* support for CitusNewNode() macro */

Copy link
Member Author

@naisila naisila Oct 16, 2024

Choose a reason for hiding this comment

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

We still have CitusNewNode(size_t size, CitusNodeTag tag) function, so I guess not.

Copy link
Contributor

Choose a reason for hiding this comment

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

CitusNode *newCitusNodeMacroHolder; is not referenced anywhere. So I assumed it was related to getting around an issue with macro usage. Now since we have a function instead, this line may be redundant and confusing.

Copy link
Member Author

Choose a reason for hiding this comment

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

Just noticed that, you are right. It is redundant. Let me remove it.

naisila added a commit that referenced this pull request Oct 16, 2024
This is prep work for successful compilation with PG17

PG17added foreach_ptr, foreach_int and foreach_oid macros
Relevant PG commit
14dd0f27d7cd56ffae9ecdbe324965073d01a9ff

postgres/postgres@14dd0f2

We already have these macros, but they are different with the
PG17 ones because our macros take a DECLARED variable, whereas
the PG16 macros declare a locally-scoped loop variable themselves.

Hence I am renaming our macros to foreach_declared_

I am separating this into its own PR since it touches many files. The
main compilation PR is #7699
Base automatically changed from naisila/foreach_macros to release-13.0 October 16, 2024 14:01
Relevant PG commit
d060e921ea5aa47b6265174c32e1128cebdbc3df
postgres/postgres@d060e92
Relevant PG commit:
89e5ef7e21812916c9cf9fcf56e45f0f74034656
postgres/postgres@89e5ef7
Relevant PG commit:
08e6344fd6423210b339e92c069bb979ba4e7cd6
postgres/postgres@08e6344
Relevant PG commit:
f696c0cd5f299f1b51e214efc55a22a782cc175d
postgres/postgres@f696c0c
Relevant PG commit:
de3600452b61d1bc3967e9e37e86db8956c8f577
postgres/postgres@de36004
naisila and others added 15 commits October 16, 2024 21:28
Relevant PG commit:
4f622503d6de975ac87448aea5cea7de4bc140d5
postgres/postgres@4f62250
Relevant PG commit:
012460ee93c304fbc7220e5b55d9d0577fc766ab
postgres/postgres@012460e
Relevant PG commit:
50c67c2019ab9ade8aa8768bfe604cd802fe8591
postgres/postgres@50c67c2
Relevant PG commit:
509199587df73f06eda898ae13284292f4ae573a
postgres/postgres@5091995
Relevant PG commit:
75680c3d805e2323cd437ac567f0677fdfc7b680
postgres/postgres@75680c3
Relevant PG commit:
0294df2f1f842dfb0eed79007b21016f486a3c6c
postgres/postgres@0294df2
Relevant PG commit:
5de890e3610d5a12cdaea36413d967cf5c544e20
postgres/postgres@5de890e
…ON_COUNT

Relevant PG commit:
a6be0600ac3b71dda8277ab0fcbe59ee101ac1ce
postgres/postgres@a6be060
Relevant PG commits:
28f3915b73f75bd1b50ba070f56b34241fe53fd1
postgres/postgres@28f3915

ab355e3a88de745607f6dd4c21f0119b5c68f2ad
postgres/postgres@ab355e3

024c521117579a6d356050ad3d78fdc95e44eefa
postgres/postgres@024c521
postgres refactored newNode() in PG 17, the main point for doing this is
the original tricks is no longer neccessary for modern compilers[1].

This does the same for Citus.

This should have no backward compatibility issues since it just replaces
palloc0fast with palloc0.

This is good for forward compatibility since palloc0fast no longer
exists in PG 17.

[1]
https://www.postgresql.org/message-id/[email protected]

(cherry picked from commit 4b295cc)
@naisila
Copy link
Member Author

naisila commented Oct 16, 2024

Looks like PG 17 introduced a new ACL called ACL_MAINTAIN
...
I understand that this commit is for getting Citus compile against PG17.

MergeAction can have 3 merge kinds (now enum) in PG17, write compat

@emelsimsek you are right, it's not part of the compile PR. We might need a separate issue for new features in PG17 which will encapsulate these subtasks, like this one: #7138. For now, I added your comments in here #7708

@naisila
Copy link
Member Author

naisila commented Oct 16, 2024

@jmealo Thanks for catching that, as it's not a regression caused by this PR I opened an issue to track this: #7707

@naisila naisila merged commit da2624c into release-13.0 Oct 17, 2024
120 checks passed
@naisila naisila deleted the naisila/pg17_compile branch October 17, 2024 12:37
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.

5 participants