Skip to content

Track cluster-wide Citus version - method 3 - (shmem cache + daemon invalidate) - #8690

Closed
alperkocatas wants to merge 1 commit into
mainfrom
alperkocatas/method-3-min-cluster-version-daemon
Closed

Track cluster-wide Citus version - method 3 - (shmem cache + daemon invalidate)#8690
alperkocatas wants to merge 1 commit into
mainfrom
alperkocatas/method-3-min-cluster-version-daemon

Conversation

@alperkocatas

@alperkocatas alperkocatas commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

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

…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.
Copilot AI review requested due to automatic review settings July 22, 2026 11:51
@alperkocatas alperkocatas changed the title Track cluster-wide minimum Citus version (shmem cache + daemon invali… Track cluster-wide Citus version - method 3 - (shmem cache + daemon invalidate) Jul 22, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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$$;
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.

2 participants