Skip to content

Fix VLE queries failing on read-only replicas (#2160)#2345

Merged
jrgemignani merged 1 commit intoapache:masterfrom
gregfelice:fix_2160_vle_sharelock_replica
Feb 27, 2026
Merged

Fix VLE queries failing on read-only replicas (#2160)#2345
jrgemignani merged 1 commit intoapache:masterfrom
gregfelice:fix_2160_vle_sharelock_replica

Conversation

@gregfelice
Copy link
Contributor

Summary

Fixes #2160.

VLE queries fail on read-only replicas (standby servers) with:

ERROR: cannot acquire lock mode ShareLock on database objects while recovery is in progress
HINT: Only RowExclusiveLock or less can be acquired on database objects during recovery.

Root Cause

The VLE global graph cache (age_global_graph.c) acquires ShareLock when scanning vertex and edge label tables to populate in-memory hashtables. On standby servers in recovery mode, PostgreSQL restricts locks to RowExclusiveLock or lower. ShareLock exceeds this threshold.

The three affected functions are:

  • get_ag_labels_names() — scans ag_label catalog table
  • load_vertex_hashtable() — scans vertex label tables
  • load_edge_hashtable() — scans edge label tables

All three perform read-only sequential scans to populate caches — no writes.

Fix

Change ShareLock to AccessShareLock in all three functions (6 call sites: 3 table_open + 3 table_close).

AccessShareLock is:

  • Sufficient for read-only table scans (blocks DDL, allows concurrent reads and DML)
  • Allowed on read-only replicas
  • Consistent with the existing ag_cache.c code, which performs identical catalog scan operations using AccessShareLock (18 call sites)

Test Plan

  • All 31 regression tests pass
  • Manual VLE test: multi-hop path traversal works correctly
  • Lock change is minimal (6 substitutions in 1 file) with no logic changes

@jrgemignani
Copy link
Contributor

@gregfelice Again, ty!

Three things -

  • This PR needs to be applied to the master branch. You have it set to a release branch, which is frozen.
  • You should rebase it now that the other VLE PR has been merged. This will likely apply to other PRs of yours that are waiting in line.
  • I know this was from the previous batch, so if it is AI, please give it a nod.

Copy link
Contributor

@jrgemignani jrgemignani left a comment

Choose a reason for hiding this comment

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

Wrong branch

@gregfelice
Copy link
Contributor Author

gregfelice commented Feb 27, 2026 via email

The global graph cache used by VLE acquired ShareLock when scanning
vertex and edge label tables to populate in-memory hashtables. On
read-only replicas (standby servers in recovery), PostgreSQL only
allows RowExclusiveLock or less, so VLE queries would fail with:

  "cannot acquire lock mode ShareLock on database objects while
   recovery is in progress"

Change all three functions in age_global_graph.c to use AccessShareLock
instead, which is sufficient for read-only table scans and is consistent
with the existing ag_cache.c code that performs identical operations.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@gregfelice gregfelice force-pushed the fix_2160_vle_sharelock_replica branch from 5184acb to 55fd557 Compare February 27, 2026 00:09
@gregfelice gregfelice changed the base branch from release/PG18/1.7.0 to master February 27, 2026 00:09
@gregfelice
Copy link
Contributor Author

@jrgemignani Thanks for the review! Rebased onto master (on top of the merged VLE PR) and retarget the PR base branch. AI (Claude, Anthropic) was used to assist in developing this fix.

@jrgemignani
Copy link
Contributor

Looks like I have to close and reopen the PR to get the CI to run. Don't panic!

@jrgemignani jrgemignani reopened this Feb 27, 2026
@jrgemignani jrgemignani merged commit 346f319 into apache:master Feb 27, 2026
6 checks passed
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.

VLE Query on read-only replica

2 participants