-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add db-tune ops subcommand + production RDS runbook #27890
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
harshach
wants to merge
6
commits into
main
Choose a base branch
from
harshach/rds-perf-doc
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7611649
Add db-tune ops command + production RDS runbook
harshach a719d47
Remove file
harshach 8b3c3e2
Merge branch 'main' into harshach/rds-perf-doc
harshach f5a945a
db-tune: address review 4230257768 — direction-agnostic status, empty…
harshach 28cdd7d
DbTuneIT: contain apply path to a private isolated table
harshach 2d9f047
db-tune: add --diagnose for read-only DBA findings
harshach File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
187 changes: 187 additions & 0 deletions
187
openmetadata-integration-tests/src/test/java/org/openmetadata/it/tests/DbTuneIT.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,187 @@ | ||
| /* | ||
| * Copyright 2026 Collate | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.openmetadata.it.tests; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertFalse; | ||
| import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| import java.util.Map; | ||
| import java.util.Set; | ||
| import java.util.stream.Collectors; | ||
| import org.jdbi.v3.core.Jdbi; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.parallel.Execution; | ||
| import org.junit.jupiter.api.parallel.ExecutionMode; | ||
| import org.openmetadata.it.bootstrap.TestSuiteBootstrap; | ||
| import org.openmetadata.service.jdbi3.locator.ConnectionType; | ||
| import org.openmetadata.service.util.dbtune.AutoTuner; | ||
| import org.openmetadata.service.util.dbtune.DbTuneResult; | ||
| import org.openmetadata.service.util.dbtune.MysqlAutoTuner; | ||
| import org.openmetadata.service.util.dbtune.PostgresAutoTuner; | ||
| import org.openmetadata.service.util.dbtune.TableRecommendation; | ||
|
|
||
| /** | ||
| * End-to-end tests for {@link AutoTuner} against the live Testcontainers database. The bootstrap | ||
| * runs every migration up to the current version, so the tracked entity tables (e.g. | ||
| * {@code storage_container_entity}) exist; we exercise the analyze → apply → analyze-one path | ||
| * against the real schema and reset the modified reloptions / table options at the end. | ||
| * | ||
| * <p>Sequential because each test mutates table-level reloptions on shared production tables; | ||
| * parallel execution would race between read-stats and apply. | ||
| * | ||
| * <p>Uses {@code entity_relationship} as the target — its tuning profile has a row-count threshold | ||
| * of zero, so the recommendation is actionable on a fresh IT bootstrap (other entity tables are | ||
| * gated behind 10k-row thresholds and would {@code SKIP} on an empty database, defeating the apply | ||
| * assertion). | ||
| */ | ||
| @Execution(ExecutionMode.SAME_THREAD) | ||
| class DbTuneIT { | ||
|
|
||
| private static final String TEST_TABLE = "entity_relationship"; | ||
|
|
||
| @Test | ||
| void analyzeReturnsRecommendationsForKnownTables() { | ||
| AutoTuner tuner = currentTuner(); | ||
| Jdbi jdbi = TestSuiteBootstrap.getJdbi(); | ||
|
|
||
| DbTuneResult result = jdbi.withHandle(tuner::analyze); | ||
|
|
||
| assertNotNull(result); | ||
| assertNotNull(result.engineVersion()); | ||
| assertFalse(result.tableRecommendations().isEmpty(), "Expected at least one recommendation"); | ||
| assertTrue( | ||
| result.tableRecommendations().stream().anyMatch(r -> TEST_TABLE.equals(r.tableName())), | ||
| "storage_container_entity should be in the recommendations"); | ||
|
harshach marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| @Test | ||
| void applyChangesReloptionsAndIsIdempotent() { | ||
| AutoTuner tuner = currentTuner(); | ||
| Jdbi jdbi = TestSuiteBootstrap.getJdbi(); | ||
| ConnectionType connType = currentConnectionType(); | ||
| TableRecommendation rec = recommendationFor(tuner, jdbi, TEST_TABLE); | ||
|
|
||
| try { | ||
| jdbi.useHandle(handle -> tuner.apply(handle, rec)); | ||
| Map<String, String> after = currentSettingsFor(tuner, jdbi, TEST_TABLE); | ||
| assertSettingsMatch(rec.recommendedSettings(), after); | ||
|
|
||
| // Apply twice — must be a no-op | ||
| jdbi.useHandle(handle -> tuner.apply(handle, rec)); | ||
| Map<String, String> afterSecond = currentSettingsFor(tuner, jdbi, TEST_TABLE); | ||
| assertEquals(after, afterSecond, "Apply should be idempotent"); | ||
| } finally { | ||
| resetTableSettings(jdbi, TEST_TABLE, connType, rec.recommendedSettings().keySet()); | ||
| } | ||
| } | ||
|
|
||
|
Comment on lines
+120
to
+129
|
||
| @Test | ||
| void analyzeOneRunsWithoutError() { | ||
| AutoTuner tuner = currentTuner(); | ||
| Jdbi jdbi = TestSuiteBootstrap.getJdbi(); | ||
|
|
||
| jdbi.useHandle(handle -> tuner.analyzeOne(handle, TEST_TABLE)); | ||
| } | ||
|
|
||
| @Test | ||
| void dryRunDoesNotMutateReloptions() { | ||
| AutoTuner tuner = currentTuner(); | ||
| Jdbi jdbi = TestSuiteBootstrap.getJdbi(); | ||
|
|
||
| Map<String, String> before = currentSettingsFor(tuner, jdbi, TEST_TABLE); | ||
|
|
||
| DbTuneResult result = jdbi.withHandle(tuner::analyze); | ||
| assertNotNull(result); | ||
|
|
||
| Map<String, String> after = currentSettingsFor(tuner, jdbi, TEST_TABLE); | ||
| assertEquals(before, after, "Analyze (dry-run) must not change table settings"); | ||
| } | ||
|
|
||
| // ---- helpers ---- | ||
|
|
||
| private AutoTuner currentTuner() { | ||
| return currentConnectionType() == ConnectionType.POSTGRES | ||
| ? new PostgresAutoTuner() | ||
| : new MysqlAutoTuner(); | ||
| } | ||
|
|
||
| private ConnectionType currentConnectionType() { | ||
| return "mysql".equalsIgnoreCase(System.getProperty("databaseType", "postgres")) | ||
| ? ConnectionType.MYSQL | ||
| : ConnectionType.POSTGRES; | ||
| } | ||
|
|
||
| private TableRecommendation recommendationFor( | ||
| final AutoTuner tuner, final Jdbi jdbi, final String tableName) { | ||
| return jdbi.withHandle(tuner::analyze).tableRecommendations().stream() | ||
| .filter(r -> tableName.equals(r.tableName())) | ||
| .findFirst() | ||
| .orElseThrow(() -> new IllegalStateException("No recommendation for " + tableName)); | ||
| } | ||
|
|
||
| /** | ||
| * Re-runs analyze and projects out the {@link TableRecommendation#currentSettings()} for the | ||
| * named table. Going through the same code path that built the original recommendation keeps the | ||
| * assertion stable across either dialect's parsing rules. | ||
| */ | ||
| private Map<String, String> currentSettingsFor( | ||
| final AutoTuner tuner, final Jdbi jdbi, final String tableName) { | ||
| return jdbi.withHandle(tuner::analyze).tableRecommendations().stream() | ||
| .filter(r -> tableName.equals(r.tableName())) | ||
| .findFirst() | ||
| .map(TableRecommendation::currentSettings) | ||
| .orElse(Map.of()); | ||
| } | ||
|
|
||
| private void assertSettingsMatch( | ||
| final Map<String, String> expected, final Map<String, String> actual) { | ||
| for (Map.Entry<String, String> e : expected.entrySet()) { | ||
| String got = actual.get(e.getKey()); | ||
| assertNotNull(got, "Missing setting after apply: " + e.getKey()); | ||
| assertEquals( | ||
| Double.parseDouble(e.getValue()), | ||
| Double.parseDouble(got), | ||
| 0.0, | ||
| "Setting " | ||
| + e.getKey() | ||
| + " did not take effect (expected " | ||
| + e.getValue() | ||
| + ", got " | ||
| + got | ||
| + ")"); | ||
| } | ||
| } | ||
|
|
||
| private void resetTableSettings( | ||
| final Jdbi jdbi, | ||
| final String tableName, | ||
| final ConnectionType connType, | ||
| final Set<String> keys) { | ||
| if (keys.isEmpty()) { | ||
| return; | ||
| } | ||
| jdbi.useHandle( | ||
| handle -> { | ||
| if (connType == ConnectionType.POSTGRES) { | ||
| String resetList = String.join(", ", keys); | ||
| handle.execute("ALTER TABLE \"" + tableName + "\" RESET (" + resetList + ")"); | ||
| } else { | ||
| String resetList = | ||
| keys.stream().map(k -> k + "=DEFAULT").collect(Collectors.joining(", ")); | ||
| handle.execute("ALTER TABLE `" + tableName + "` " + resetList); | ||
| } | ||
| }); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
openmetadata-service/src/main/java/org/openmetadata/service/util/dbtune/Action.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| /* | ||
| * Copyright 2026 Collate | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.openmetadata.service.util.dbtune; | ||
|
|
||
| public enum Action { | ||
| APPLY, | ||
| TIGHTEN, | ||
| RELAX, | ||
| OK, | ||
| SKIP; | ||
|
|
||
| public boolean isActionable() { | ||
| return this == APPLY || this == TIGHTEN || this == RELAX; | ||
| } | ||
| } |
50 changes: 50 additions & 0 deletions
50
openmetadata-service/src/main/java/org/openmetadata/service/util/dbtune/AutoTuner.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| /* | ||
| * Copyright 2026 Collate | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.openmetadata.service.util.dbtune; | ||
|
|
||
| import org.jdbi.v3.core.Handle; | ||
|
|
||
| /** | ||
| * Engine-specific auto-tuner. Implementations: | ||
| * | ||
| * <ul> | ||
| * <li>Read observed table stats and current parameter-group settings from the database. | ||
| * <li>Compute a recommended table-level reloption set per table (pure logic — see | ||
| * {@link #recommend(TableStats)}). | ||
| * <li>Apply the recommendations via {@code ALTER TABLE ... SET (...)} when the operator opts in. | ||
|
|
||
| * <li>Optionally refresh planner stats on tables that were changed. | ||
| * </ul> | ||
| */ | ||
| public interface AutoTuner { | ||
|
|
||
| /** Read stats + settings, then turn them into recommendations. Mixes I/O and pure logic. */ | ||
| DbTuneResult analyze(Handle handle); | ||
|
|
||
| /** | ||
| * Pure decision function. Given observed table stats, return the recommendation. Exposed | ||
| * separately so unit tests can assert the heuristic without hitting a database. | ||
| */ | ||
| TableRecommendation recommend(TableStats stats); | ||
|
|
||
| /** | ||
| * Apply a single actionable recommendation. No-op for non-actionable actions. Idempotent — safe | ||
| * to re-run. | ||
| */ | ||
| void apply(Handle handle, TableRecommendation recommendation); | ||
|
|
||
| /** Refresh planner stats for one table after a settings change. */ | ||
| void analyzeOne(Handle handle, String tableName); | ||
|
|
||
| /** Build the {@code ALTER TABLE} statement for a recommendation. Engine-specific syntax. */ | ||
| String buildAlterStatement(TableRecommendation recommendation); | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in a719d47: added @execution(ExecutionMode.SAME_THREAD) on the class so the tests don't race on shared reloptions when the suite runs in parallel.