Skip to content

Make the set of reserved schemas and extensions configurable.#530

Draft
ibrarahmad wants to merge 2 commits into
mainfrom
reserved_object_catalog
Draft

Make the set of reserved schemas and extensions configurable.#530
ibrarahmad wants to merge 2 commits into
mainfrom
reserved_object_catalog

Conversation

@ibrarahmad

Copy link
Copy Markdown
Contributor

Spock keeps certain schemas and extensions out of the structure synchronization dump, and forbids their tables from being added to a replication set. This set was fixed and could only be changed by rebuilding the extension, and the two behaviours were maintained independently, so they could drift apart.

Keep the set in a catalog instead, seeded with the same defaults as before: spock and snowflake are both excluded from the dump and blocked from replication sets, while lolor is excluded from the dump but still allowed in replication sets so that large objects survive dropping the extension on every node. The seeded entries are protected and cannot be removed, and an operator can now reserve additional schemas or extensions without rebuilding. Such additions are preserved across dump and restore, while the built-in entries are always re-created.

Spock keeps certain schemas and extensions out of the structure
synchronization dump, and forbids their tables from being added to a
replication set.  This set was fixed and could only be changed by
rebuilding the extension, and the two behaviours were maintained
independently, so they could drift apart.

Keep the set in a catalog instead, seeded with the same defaults as
before: spock and snowflake are both excluded from the dump and blocked
from replication sets, while lolor is excluded from the dump but still
allowed in replication sets so that large objects survive dropping the
extension on every node.  The seeded entries are protected and cannot be
removed, and an operator can now reserve additional schemas or extensions
without rebuilding.  Such additions are preserved across dump and
restore, while the built-in entries are always re-created.
@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 0db10b8d-ad8d-48db-a847-3b6163d52f4d

📥 Commits

Reviewing files that changed from the base of the PR and between ced0174 and e20e301.

⛔ Files ignored due to path filters (1)
  • tests/regress/expected/init.out is excluded by !**/*.out
📒 Files selected for processing (3)
  • sql/spock--5.0.10--6.0.0.sql
  • sql/spock--6.0.0.sql
  • tests/regress/sql/init.sql
🚧 Files skipped from review as they are similar to previous changes (2)
  • sql/spock--6.0.0.sql
  • sql/spock--5.0.10--6.0.0.sql

📝 Walkthrough

Walkthrough

Changes

Reserved object catalog

Layer / File(s) Summary
Catalog and management functions
sql/spock--5.0.10--6.0.0.sql, sql/spock--6.0.0.sql
Adds spock.reserved_object, seeds built-in entries, preserves custom rows during dumps, and provides guarded add/remove functions.
Catalog lookup and replication-set enforcement
include/spock_node.h, src/spock_node.c
Defines the catalog lookup API and replaces hard-coded replication-set exclusions with catalog-driven validation.
Structure-dump exclusions
src/spock_sync.c
Generates schema and extension dump exclusions from reserved-object catalog entries.
Documentation and validation
docs/spock_functions/repset_mgmt.md, tests/tap/t/027_reserved_object.pl, tests/regress/sql/init.sql
Documents reserved-object management and tests seeded flags, built-in protection, replication-set rejection, runtime unblocking, and extension configuration output.

Poem

I’m a rabbit with a catalog key,
Guarding schemas carefully.
Built-ins stay, custom rows flow,
Dumps skip names they ought to know.
Repsets pause, then hop anew—
Reserved objects now guide the queue!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: making reserved schemas and extensions configurable.
Description check ✅ Passed The description accurately describes the catalog-backed reserved-object changes and their seeded defaults.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch reserved_object_catalog

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 2 duplication

Metric Results
Duplication 2

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
sql/spock--6.0.0.sql (1)

1-1: 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Upsert race in reserved_object_add, duplicated in both scripts.

The UPDATE-then-INSERT upsert has a TOCTOU window: concurrent first-time adds of the same (name, kind) can both miss the UPDATE and race on the INSERT, surfacing a raw unique-violation instead of a clean upsert. ON CONFLICT is unusable here since the table is user_catalog_table (PostgreSQL rejects ON CONFLICT on catalog-marked relations), but the race can be closed with a caught exception.

  • sql/spock--6.0.0.sql#L380-398: wrap the INSERT in an EXCEPTION WHEN unique_violation block that falls back to UPDATE.
  • sql/spock--5.0.10--6.0.0.sql#L396-414: apply the identical fix so the upgrade script matches the fresh-install script.
🔒 Proposed fix (apply to both files)
     IF NOT FOUND THEN
-        INSERT INTO spock.reserved_object
-            (name, kind, exclude_from_dump, block_in_repset, builtin)
-        VALUES (p_name, p_kind, p_exclude_from_dump, p_block_in_repset, false);
+        BEGIN
+            INSERT INTO spock.reserved_object
+                (name, kind, exclude_from_dump, block_in_repset, builtin)
+            VALUES (p_name, p_kind, p_exclude_from_dump, p_block_in_repset, false);
+        EXCEPTION WHEN unique_violation THEN
+            UPDATE spock.reserved_object
+               SET exclude_from_dump = p_exclude_from_dump,
+                   block_in_repset   = p_block_in_repset
+             WHERE name = p_name AND kind = p_kind;
+        END;
     END IF;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@sql/spock--6.0.0.sql` at line 1, Update the reserved_object_add
implementation in both scripts by wrapping its INSERT path in an exception block
that catches unique_violation and falls back to the existing UPDATE for the same
name and kind. Keep the current update-then-insert behavior and apply the
identical handling in both fresh-install and upgrade definitions.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/spock_functions/repset_mgmt.md`:
- Around line 362-367: Update the documented signature and parameter
descriptions for spock.reserved_object_remove to use the SQL-defined names
object_name and object_kind instead of p_name and p_kind, while preserving their
existing schema/extension meanings.

In `@sql/spock--5.0.10--6.0.0.sql`:
- Around line 396-414: Update spock.reserved_object_add to handle the concurrent
insert race: retain the existing UPDATE-first behavior, but wrap the INSERT in a
unique-violation exception handler and retry the UPDATE for the same (p_name,
p_kind) row when another call wins the insert. Preserve the current values and
builtin=false semantics without using ON CONFLICT.

---

Outside diff comments:
In `@sql/spock--6.0.0.sql`:
- Line 1: Update the reserved_object_add implementation in both scripts by
wrapping its INSERT path in an exception block that catches unique_violation and
falls back to the existing UPDATE for the same name and kind. Keep the current
update-then-insert behavior and apply the identical handling in both
fresh-install and upgrade definitions.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 45fbe9d4-f9ed-46b2-a73a-84d171486cf2

📥 Commits

Reviewing files that changed from the base of the PR and between 5ed173c and ced0174.

📒 Files selected for processing (7)
  • docs/spock_functions/repset_mgmt.md
  • include/spock_node.h
  • sql/spock--5.0.10--6.0.0.sql
  • sql/spock--6.0.0.sql
  • src/spock_node.c
  • src/spock_sync.c
  • tests/tap/t/027_reserved_object.pl

Comment thread docs/spock_functions/repset_mgmt.md
Comment thread sql/spock--5.0.10--6.0.0.sql
Render the extension config table deterministically in the init test,
make the reserved-object add helper upsert race-safe, and give its
remove helper consistent parameter names.

@susan-pgedge susan-pgedge left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The .md files look good to me - I can't speak for the .c/.sql/.pl files!

@mason-sharp
mason-sharp marked this pull request as draft July 15, 2026 15:02
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