Skip to content

[2.0] Add the audit log entity-type index before the 2.0.8 audit cleanup (backport 2.0 #38152) - #38153

Merged
sonika-shah merged 2 commits into
2.0from
fix/audit-log-entity-type-index-v208-2.0
Nov 18, 2026
Merged

sonika-shah merged 2 commits into
2.0from
fix/audit-log-entity-type-index-v208-2.0

Conversation

@sonika-shah

@sonika-shah sonika-shah commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #38157

Describe your changes:

Backport of #38152 to 2.0. Same change, no differences.

The 2.0.8 post-data script rewrites audit_log_event rows WHERE entity_type = 'user', and the table has no entity_type index before 2.1.0, so each UPDATE scans the whole table and a large audit log makes the 2.0.8 upgrade run for hours. The 2.0.8 Java data migration, which runs after schemaChanges.sql and before postDataMigrationSQLScript.sql, now adds idx_audit_log_entity_type_ts (MySQL in place, PostgreSQL CONCURRENTLY with an INVALID index rebuilt).

  • No released SQL changes: no statement hash changes, nothing replays on databases already past 2.0.8.
  • Same name and columns as 2.1.0's index, so 2.1.0 skips its own.
  • A 2.0.8 upgrade interrupted in the post-data script picks the step up on retry.

Type of change:

  • Bug fix

Tests:

  • 2.0: AuditLogEntityTypeIndexTest (real MySQL 8.3 and PostgreSQL 15) Tests run: 2, Failures: 0, Skipped: 0; WorkflowRedeployEntryPointTest Tests run: 2, Failures: 0.
  • mvn clean install -pl openmetadata-service -am -DskipTests: BUILD SUCCESS.

Checklist:

  • I have read the CONTRIBUTING document.
  • I have added tests around the new logic.

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge, with no outstanding findings.

Summary

The PR adds the audit-log index before the 2.0.8 cleanup, with database tests and checks that both migration entry points call the new step. Since the previous review, only migration review guidance changed.

  • The 2.0.8 upgrade adds an audit-log index before cleaning up user events.
  • Migration reviews now check indexes before large-table queries run.

No new actionable issues found.

Reviews (6) · Last reviewed commit: "Document that migration queries on large..." · Reviewed by Greptile

The 2.0.8 post-data script rewrites audit_log_event rows WHERE entity_type = 'user', and
the table has no entity_type index before 2.1.0, so each UPDATE scans the whole table.
The 2.0.8 Java data migration, which runs before that script, now adds
idx_audit_log_entity_type_ts (same name and columns as 2.1.0, which then skips it).
The released 2.0.8 SQL is unchanged, so no database that ran it replays anything.
@sonika-shah
sonika-shah requested a review from a team as a code owner November 18, 2026 16:58
@sonika-shah
sonika-shah requested review from TeddyCr and removed request for a team November 18, 2026 16:58
@github-actions

Copy link
Copy Markdown
Contributor

❌ PR checklist incomplete

This PR cannot be merged until the following are addressed on its linked issue:

  • No GitHub issue is linked. Link an issue in the Development section of the PR (or add Fixes #12345 to the description). For a same-org cross-repo issue, add Fixes open-metadata/<repo>#123 to the description.

The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically.

Maintainers can bypass this check by adding the skip-pr-checks label.

Comment on lines +40 to +51
void addsTheIndexOnceOnMysql() {
try (GenericContainer<?> database =
new GenericContainer<>("mysql:8.3.0")
.withEnv("MYSQL_DATABASE", DATABASE)
.withEnv("MYSQL_ROOT_PASSWORD", PASSWORD)
.withEnv("MYSQL_ROOT_HOST", "%")
.withExposedPorts(3306)
.waitingFor(
Wait.forSuccessfulCommand(
"mysql --protocol=TCP --host=127.0.0.1 --user=root --password="
+ PASSWORD
+ " --execute='SELECT 1'"))) {

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.

P2 Test methods are too long. Both new tests combine container setup, table creation, migration calls, upgrade checks, and assertions in methods over 40 lines long. The repository requires small, focused methods and says to aim for 15 lines or fewer. Extract the setup and index checks into named helpers so each test shows the behavior it checks.

Context Used: CLAUDE.md (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Noted. The test follows the existing Testcontainers migration tests in this package. I'm keeping this fix limited to the migration step and leaving the test style as is.

@sonika-shah

Copy link
Copy Markdown
Collaborator Author

Upgrade run on a real 2.0.7 database, MySQL 8.3 and PostgreSQL 15: fresh database migrated by the released 2.0.7 image, 5,000 audit_log_event rows seeded (151 user rows, some holding authenticationMechanism as an object and some inside a JSON string), then migrate with this branch's jars and bootstrap SQL (the 2.0 build; main and 2.1 carry the identical change).

MySQL PostgreSQL
migrate exit 0, WorkFlow Completed, change log 2.0.9, 2.0.8, 2.0.7 same
Index after upgrade idx_audit_log_entity_type_ts = entity_type ASC, event_ts DESC valid, USING btree (entity_type, event_ts DESC)
Step before the cleanup data migration runs between Run Schema Changes and Run Post DDL in the log step marker 17:00:39.216, audit UPDATEs 17:00:39.384 / .436
Cleanup filter plan type=ref key=idx_audit_log_entity_type_ts Bitmap Index Scan on idx_audit_log_entity_type_ts (unforced)
user rows still holding authenticationMechanism 0 0
migrate again on the upgraded database exit 0, 2.0.8 log rows 31 → 31 exit 0, 26 → 26

@sonika-shah

Copy link
Copy Markdown
Collaborator Author

Upgrade test on real release instances, MySQL 8.3 and PostgreSQL 15, using the released openmetadata/server 2.0.7, 2.0.8 and 2.1.0-rc2 images. The fixed builds are the release image with this branch's common, spec and service jars and its bootstrap/sql. Every migration ran with openmetadata-ops.sh migrate.

Setup: a 2.0.7 server was started and given data through its API (tables, glossary terms, users, bots with JWT tokens, an admin access token). Before the upgrade, 22 of the 32 user audit events it wrote still had authenticationMechanism. After each upgrade the server was started again and checked through its API: version, tables, glossary terms, bots, /v1/audit/logs?entityType=user, and a write.

Path Index built before the 2.0.8 cleanup UPDATEs User rows left to clean Upgraded server
2.0.7 -> this branch (2.0.9) -> 2.1 yes (PG: step 19:34:15.369, UPDATEs .458/.467; MySQL general log: CREATE INDEX 19:45:16.113, UPDATEs .372/.412) 0 starts, 0 ERROR lines, audit API 200, 0 events with authenticationMechanism, writes OK
2.0.7 -> 2.1 directly yes 0 same
Real 2.0.8 killed (SIGKILL) during its audit UPDATE -> retried with the 2.0 or the 2.1 build yes; steps that already ran are skipped 0 same
Same, with the index created by hand before the retry step finds the index and does nothing 0 same
Real 2.0.8 finished -> 2.0.9 2.0.8 not re-run (no new SQL) 0 same
Real 2.0.8 finished -> 2.1 cleanup already done in 2.0.8; v208 step builds the index, 2.1.0's statement then skips 0 same
Already on 2.1.0 -> 2.1 build again nothing re-runs; 2.0.8 log rows unchanged (PG 26 -> 26, MySQL 31 -> 31) 0 same

2.1.0's own index statement never errors when the index already exists: on PostgreSQL IF NOT EXISTS skips it, and on MySQL the information_schema guard runs SELECT 1.

@gitar-bot

gitar-bot Bot commented Nov 18, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 🔴 High risk

The 2.0.8 migration adds an audit-log index, changing database schema; index-build interruption or load could delay upgrades on large installations.

Adds the idx_audit_log_entity_type_ts index on audit_log_event during the 2.0.8 Java data migration so the post-data entity_type cleanup no longer scans the full table. Released SQL is unchanged, and no issues were found.

Verification

Rules No rules evaluated

Functional validation Not enabled

Set up

Auto-approval Not enabled

Set up

For more verification details, comment gitar display:verbose.

Options

Display: compact → Showing compact verification results.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

@sonika-shah
sonika-shah merged commit 4c83272 into 2.0 Nov 18, 2026
63 of 68 checks passed
@sonika-shah
sonika-shah deleted the fix/audit-log-entity-type-index-v208-2.0 branch November 18, 2026 21:58
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