Skip to content
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

[Enhancement] Migrate part of db lock to table lock in SchemaChange #43907

Merged
merged 1 commit into from
Jul 12, 2024

Conversation

HangyuanLiu
Copy link
Contributor

@HangyuanLiu HangyuanLiu commented Apr 11, 2024

Why I'm doing:

What I'm doing:

Fixes #issue

What type of PR is this:

  • BugFix
  • Feature
  • Enhancement
  • Refactor
  • UT
  • Doc
  • Tool

Does this PR entail a change in behavior?

  • Yes, this PR will result in a change in behavior.
  • No, this PR will not result in a change in behavior.

If yes, please specify the type of change:

  • Interface/UI changes: syntax, type conversion, expression evaluation, display information
  • Parameter changes: default values, similar parameters but with different default values
  • Policy changes: use new policy to replace old one, functionality automatically enabled
  • Feature removed
  • Miscellaneous: upgrade & downgrade compatibility, etc.

Checklist:

  • I have added test cases for my bug fix or my new feature
  • This pr needs user documentation (for new or modified features or behaviors)
    • I have added documentation for my new feature or new function
  • This is a backport pr

Bugfix cherry-pick branch check:

  • I have checked the version labels which the pr will be auto-backported to the target branch
    • 3.3
    • 3.2
    • 3.1
    • 3.0
    • 2.5

@@ -2159,7 +2163,7 @@ public ShowResultSet visitShowIndexStatement(ShowIndexStmt statement, ConnectCon
// do nothing
}
} finally {
locker.unLockDatabase(db, LockType.READ);
locker.unLockTablesWithIntensiveDbLock(db, Lists.newArrayList(table.getId()), LockType.READ);
}
return new ShowResultSet(statement.getMetaData(), rows);
}
Copy link

Choose a reason for hiding this comment

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

The most risky bug in this code is:
Potential null pointer exception when using the table variable.

You can modify the code like this:

locker.lockTablesWithIntensiveDbLock(db, table != null ? Lists.newArrayList(table.getId()) : Collections.emptyList(), LockType.READ);
try {
    // Existing try block code remains unchanged
} finally {
    locker.unLockTablesWithIntensiveDbLock(db, table != null ? Lists.newArrayList(table.getId()) : Collections.emptyList(), LockType.READ);
}

This modification ensures that the code checks if the table variable is null before attempting to use it, avoiding a potential NullPointerException.

Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarCloud

Catch issues before they fail your Quality Gate with our IDE extension SonarLint

@HangyuanLiu HangyuanLiu force-pushed the show-exe-lock branch 3 times, most recently from 7c46143 to 7e28d4d Compare July 5, 2024 11:29
@HangyuanLiu HangyuanLiu requested review from a team as code owners July 5, 2024 11:29
@HangyuanLiu HangyuanLiu changed the title [Enhancement] Migrate part of db lock to table lock in ShowExecutor [Enhancement] Migrate part of db lock to table lock in SchemaChange Jul 10, 2024
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarCloud

Catch issues before they fail your Quality Gate with our IDE extension SonarLint

Copy link

[BE Incremental Coverage Report]

pass : 0 / 0 (0%)

Copy link

[FE Incremental Coverage Report]

fail : 170 / 219 (77.63%)

file detail

path covered_line new_line coverage not_covered_line_detail
🔵 com/starrocks/alter/AlterJobMgr.java 27 48 56.25% [375, 376, 377, 381, 385, 386, 388, 398, 458, 459, 487, 488, 489, 503, 504, 519, 520, 554, 997, 1000, 1016]
🔵 com/starrocks/alter/MaterializedViewHandler.java 9 13 69.23% [738, 765, 904, 1074]
🔵 com/starrocks/qe/ShowExecutor.java 10 14 71.43% [1037, 1038, 2206, 2207]
🔵 com/starrocks/task/AlterReplicaTask.java 4 5 80.00% [311]
🔵 com/starrocks/alter/SchemaChangeHandler.java 34 42 80.95% [2112, 2129, 2214, 2268, 2269, 2270, 2619, 2622]
🔵 com/starrocks/alter/AlterJobV2.java 6 7 85.71% [267]
🔵 com/starrocks/alter/SchemaChangeJobV2.java 35 41 85.37% [318, 438, 518, 711, 1029, 1079]
🔵 com/starrocks/alter/LakeTableAlterMetaJobBase.java 41 45 91.11% [195, 196, 428, 486]
🔵 com/starrocks/alter/CompactionHandler.java 4 4 100.00% []


MaterializedView oldMaterializedView = (MaterializedView) db.getTable(id);
if (oldMaterializedView == null) {
LOG.warn("Ignore change materialized view refresh scheme log because table:" + id + "is null");
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
LOG.warn("Ignore change materialized view refresh scheme log because table:" + id + "is null");
LOG.warn("Ignore change materialized view refresh scheme log because table:" + id + " is null");

@nshangyiming nshangyiming enabled auto-merge (squash) July 12, 2024 11:01
@wanpengfei-git wanpengfei-git disabled auto-merge July 12, 2024 11:42
@wanpengfei-git wanpengfei-git merged commit d8649e3 into StarRocks:main Jul 12, 2024
57 of 59 checks passed
Copy link

@Mergifyio backport branch-3.3

@github-actions github-actions bot removed the 3.3 label Jul 12, 2024
Copy link
Contributor

mergify bot commented Jul 12, 2024

backport branch-3.3

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request Jul 12, 2024
wanpengfei-git pushed a commit that referenced this pull request Jul 12, 2024
wanpengfei-git added a commit that referenced this pull request Jul 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants