Skip to content

feat(persistence): replace EventEntity.REALM_SCOPED sentinel with nullable catalog_id#4981

Open
sririshindra wants to merge 2 commits into
apache:mainfrom
sririshindra:issue-4674-nullable-event-catalog-id
Open

feat(persistence): replace EventEntity.REALM_SCOPED sentinel with nullable catalog_id#4981
sririshindra wants to merge 2 commits into
apache:mainfrom
sririshindra:issue-4674-nullable-event-catalog-id

Conversation

@sririshindra

Copy link
Copy Markdown
Contributor

Events that are not scoped to a catalog (principal, principal-role, policy, credential,
transaction, config, rate-limiting, etc.) previously persisted the magic string "__realm__"
in the events.catalog_id column because that column was NOT NULL. This replaces the sentinel
with a proper SQL NULL.

Changes

  • Removed the REALM_SCOPED constant from EventEntity; catalogId is now @Nullable end to
    end (entity, listener, ModelEvent).
  • Added relational-JDBC schema v5 for Postgres/H2/CockroachDB with a nullable events.catalog_id,
    and bumped DatabaseType.getLatestSchemaVersion() to 5.
  • Kept a narrow, version-gated compatibility shim in JdbcBasePersistenceImpl.writeEvents that
    still writes the legacy "__realm__" sentinel when schemaVersion < 5 (Polaris has no automated
    schema migrations), and coalesces the sentinel back to null on read in ModelEvent.fromResultSet.
  • Updated CHANGELOG.md and the relational-jdbc metastore docs with the one-time operator
    migration SQL for existing v3/v4 deployments.

Checklist

@github-project-automation github-project-automation Bot moved this to PRs In Progress in Basic Kanban Board Jul 6, 2026
@sririshindra
sririshindra force-pushed the issue-4674-nullable-event-catalog-id branch from b8d56d3 to d2e5d4e Compare July 6, 2026 17:49
@sririshindra
sririshindra marked this pull request as ready for review July 7, 2026 13:02
dimas-b
dimas-b previously approved these changes Jul 10, 2026

@dimas-b dimas-b 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.

Thanks for your contribution, @sririshindra !

This PR LGTM in general, but let's collect some more reviews as it's a major change.

Do you feel like also starting a dev discussion for visibility?

case POSTGRES -> 4; // PostgreSQL has schemas v1, v2, v3, v4
case COCKROACHDB -> 4; // CockroachDB schema version kept in sync with PostgreSQL
case H2 -> 4; // H2 uses same schemas as PostgreSQL
case POSTGRES -> 5; // PostgreSQL has schemas v1, v2, v3, v4, v5

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.

side note: it is unfortunate that changes to events tables require a schema version bump that also affects metastore tables 🤷 Would it be nicer to evolve events schema and metastore scheme separately (not in this PR, but in general)? WDYT?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Makes sense @dimas-b , I will send an email to the dev mailing list.

@github-project-automation github-project-automation Bot moved this from PRs In Progress to Ready to merge in Basic Kanban Board Jul 10, 2026
@nandorKollar nandorKollar self-assigned this Jul 10, 2026
Comment thread CHANGELOG.md
### Highlights

### Upgrade notes
- Relational JDBC: a new schema version 5 makes the `events.catalog_id` column nullable. Events that

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.

I'm wondering how long should we support old schemas? With our support rolling upgrades policy (https://polaris.apache.org/releases/1.6.0/evolution/#managing-polaris-database), after we release 1.7 with this change, can we eliminate the sentinel completely in 1.9?

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.

I 've been meaning to start this thread on dev for a long time, but never find a break to just write that email 😅

Feel free to initiate this conversation.

@sririshindra sririshindra left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the reviews, @dimas-b and @nandorKollar . I will send a follow up email to the dev mailing list as suggested.

nandorKollar
nandorKollar previously approved these changes Jul 13, 2026
@dimas-b

dimas-b commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

@dimas-b

dimas-b commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

@sririshindra : Please resolve merge conflicts

…lable catalog_id

Events not scoped to a catalog (principal, policy, rate-limiting, etc.)
previously stored the magic string "__realm__" in events.catalog_id
because the column was NOT NULL. Introduce relational-JDBC schema v5
with a nullable events.catalog_id and persist SQL NULL instead:

- Remove the REALM_SCOPED constant from EventEntity; catalogId is now
  @nullable end to end (entity, listener, ModelEvent).
- Add schema-v5.sql for postgres/h2/cockroachdb and bump the latest
  schema version to 5.
- Keep a version-gated shim in JdbcBasePersistenceImpl.writeEvents that
  writes the legacy sentinel on pre-v5 schemas (no automated
  migrations), and coalesce "__realm__" back to null on read.
- Document the one-time operator migration in CHANGELOG.md and the
  relational-jdbc metastore docs.

Fixes apache#4674
…nto ModelEvent.fromEvent

Follow the ModelEntity.fromEntity(entity, schemaVersion) pattern so both
halves of the sentinel round-trip (write substitution and read coalescing)
live in ModelEvent, and drop the redundant second immutable build in the
event write path. Also document that the sentinel string stays reserved on
all schema versions, and fix the copied changelog headers in the v5 schema
files to state the actual v4 -> v5 delta.
@sririshindra
sririshindra dismissed stale reviews from nandorKollar and dimas-b via 3ea3437 July 16, 2026 19:00
@sririshindra
sririshindra force-pushed the issue-4674-nullable-event-catalog-id branch from e632926 to 3ea3437 Compare July 16, 2026 19:00
@dimas-b

dimas-b commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

I'm planning to merge on July 19 unless concerns are raised in GH or of the dev thread (link above).

@flyrain flyrain 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.

LGTM Thanks @sririshindra !

CockroachDB, and H2), then restart Polaris:

```sql
ALTER TABLE polaris_schema.events ALTER COLUMN catalog_id DROP NOT NULL;

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.

Small doc nit: this block is presented as working on PostgreSQL, CockroachDB, and H2, but ALTER COLUMN ... DROP NOT NULL is the Postgres/Cockroach spelling — H2 historically uses ALTER COLUMN catalog_id SET NULL. The "adjust the ALTER syntax to your database if needed" hedge covers it, and H2 is effectively test-only, so this is optional — but if you want it copy-pasteable, worth naming H2's variant. (I couldn't verify the exact H2 version's syntax here, so flag if this is already fine.)

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.

This PR has been in review for a long time 😅 Given the low impact, let's merge "as is". Follow-up doc improvements are welcome, of course.

@dimas-b

dimas-b commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

@sririshindra : A v5 schema was introduced via #5086. Sorry about conflicts on your PR but the other one merged first 🤷 Please adjust current v5 DDL according to this PR (no need to add v6 since this scheme version has not been released yet).

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.

Replace PolarisEvent.REALM_SCOPED sentinel with nullable catalogId column

5 participants