Track cluster-wide Citus version - method 3 - (shmem cache + daemon invalidate) - #8690
Closed
alperkocatas wants to merge 1 commit into
Closed
Track cluster-wide Citus version - method 3 - (shmem cache + daemon invalidate)#8690alperkocatas wants to merge 1 commit into
alperkocatas wants to merge 1 commit into
Conversation
…dation) Add citus_version_num() and citus_minimum_cluster_version() backed by a node-local shared-memory cache. The cache is invalidated from the pg_dist_node relcache callback and periodically by the maintenance daemon (citus.cluster_version_refresh_interval) so the next read recomputes. The daemon task only flips a flag: no transaction, lock, or fan-out. No catalog changes.
Contributor
There was a problem hiding this comment.
Pull request overview
Adds cluster-wide Citus version introspection by introducing a node-local shared-memory cache for the computed minimum Citus version across active primary nodes, with invalidation triggered by pg_dist_node relcache events and periodically by the maintenance daemon.
Changes:
- Add
pg_catalog.citus_version_num()(integer-encoded Citus version) and SQL wiring. - Add
pg_catalog.citus_minimum_cluster_version()backed by a shared-memory cache and remote fan-out computation on cache miss. - Add cache invalidation hooks (relcache callback + maintenance daemon) and a new GUC
citus.cluster_version_refresh_interval.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/include/distributed/cluster_version.h | Declares cluster version cache APIs and refresh-interval GUC. |
| src/backend/distributed/utils/maintenanced.c | Adds periodic invalidation of the cluster version cache. |
| src/backend/distributed/utils/citus_version.c | Exposes new citus_version_num() C UDF. |
| src/backend/distributed/sql/udfs/citus_version_num/latest.sql | Creates pg_catalog.citus_version_num() for new installs. |
| src/backend/distributed/sql/udfs/citus_version_num/15.0-1.sql | Creates pg_catalog.citus_version_num() for 15.0-1 upgrade path. |
| src/backend/distributed/sql/udfs/citus_minimum_cluster_version/latest.sql | Creates pg_catalog.citus_minimum_cluster_version() for new installs. |
| src/backend/distributed/sql/udfs/citus_minimum_cluster_version/15.0-1.sql | Creates pg_catalog.citus_minimum_cluster_version() for 15.0-1 upgrade path. |
| src/backend/distributed/sql/downgrades/citus--15.0-1--14.0-1.sql | Drops the newly added version-tracking UDFs on downgrade. |
| src/backend/distributed/sql/citus--14.0-1--15.0-1.sql | Includes the new UDF SQL files in the 14→15 upgrade script. |
| src/backend/distributed/shared_library_init.c | Requests shmem + installs init hook + registers the refresh-interval GUC. |
| src/backend/distributed/operations/cluster_version.c | Implements shmem cache, minimum version computation, and invalidation. |
| src/backend/distributed/metadata/metadata_cache.c | Invalidates the version cache when pg_dist_node changes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+270
to
+284
| /* | ||
| * InvalidateClusterVersionCache marks the cached minimum version as stale so | ||
| * that the next reader recomputes it. It is called from the pg_dist_node | ||
| * relcache invalidation callback. We intentionally do not take the LWLock here, | ||
| * matching InvalidateNodeRelationCacheCallback, to keep the callback safe and | ||
| * cheap; a racy stale read only costs one extra recompute. | ||
| */ | ||
| void | ||
| InvalidateClusterVersionCache(void) | ||
| { | ||
| if (ClusterVersionShmem != NULL) | ||
| { | ||
| ClusterVersionShmem->cacheValid = false; | ||
| } | ||
| } |
Comment on lines
+1
to
+4
| CREATE OR REPLACE FUNCTION pg_catalog.citus_minimum_cluster_version() | ||
| RETURNS text | ||
| LANGUAGE C STRICT | ||
| AS 'MODULE_PATHNAME', $$citus_minimum_cluster_version$$; |
Comment on lines
+1
to
+4
| CREATE OR REPLACE FUNCTION pg_catalog.citus_minimum_cluster_version() | ||
| RETURNS text | ||
| LANGUAGE C STRICT | ||
| AS 'MODULE_PATHNAME', $$citus_minimum_cluster_version$$; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add citus_version_num() and citus_minimum_cluster_version() backed by a node-local shared-memory cache. The cache is invalidated from the pg_dist_node relcache callback and periodically by the maintenance daemon (citus.cluster_version_refresh_interval) so the next read recomputes. The daemon task only flips a flag: no transaction, lock, or fan-out. No catalog changes.
Downside is: daemon will invalidate cache even if no change has occurred in the cluster since last recompute of minimum version.
DESCRIPTION: PR description that will go into the change log, up to 78 characters