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] active mv automatically #32829

Merged
merged 4 commits into from
Oct 17, 2023

Conversation

murphyatwork
Copy link
Contributor

@murphyatwork murphyatwork commented Oct 16, 2023

Fixes #issue

Introduce a daemon thread MVActiveChecker:

  1. Try to activate MV, if it's not set to inactive manually
  2. The default check interval is 1 minute, user could modify it through admin set frontend config('mv_active_checker_interval_seconds'='300')

Use case:

  1. The base table of MV could be dropped and created everyday, for Hive external table
  2. Without this mechanism, user need to activate it in the workflow, which is tedious

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

Bugfix cherry-pick branch check:

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

ConnectContext.remove();
}
}
}
Copy link

Choose a reason for hiding this comment

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

Here are some suggested improvements:

  1. Exception handling:
    In several places, the code simply logs the exception with a warning and continues to run. This can make debugging harder since the cause of the problem may get lost. You should consider whether it's appropriate to deal better with exceptions.

  2. Excess object creation:
    Inside the method tryToActivate(MaterializedView mv), you create a new TableName object only to convert it to a string. If the toString() function isn't costly in terms of resources, this might not be an issue, but if it is, consider using another method to construct the full table name from dbName and mv.getName().

  3. Running through databases and tables:
    You might want to consider more effective data structures or methods for searching through your databases and tables. Currently, the complexity is proportional to the number of databases multiplied by the number of tables, which will lead to performance issues as these numbers increase.

  4. Inconsistent usage of Optional:
    In tryToActivate(MaterializedView mv), you’re accessing dbName via Optional. But in other parts of the code, null check isn't done explicitly nor with Optional. Having consistent use of Optional is good practice to avoid NullPointerException.

  5. Thread Safety:
    It's unclear whether the code is running in a multithreaded environment or not. If it does, you need to ensure thread safety especially when manipulating shared resources. Consider potential concurrency issues for methods like process(), runAfterCatalogReady(), and tryToActivate().

  6. Code comments:
    Although there are relevant comments and it's always beneficial to comment your code, remember that the code itself should be mostly self-explanatory. Aim to write descriptive variable, method, and class names so that comments are needed less for explaining what happens and more for why certain decisions were made.

Please ensure to consider these suggestions taking into account the entire application context since some may not be applicable depending on intended behavior of the software, environment among other factors.

@murphyatwork murphyatwork changed the title [Enhancement] introduce a daemon thread MVActiveChecker to fix inactive MV [Enhancement] active mv automatically Oct 16, 2023
@murphyatwork
Copy link
Contributor Author

@Mergifyio rebase

@mergify
Copy link
Contributor

mergify bot commented Oct 16, 2023

rebase

✅ Branch has been successfully rebased

satanson
satanson previously approved these changes Oct 17, 2023
private void process() {
Collection<Database> dbs = GlobalStateMgr.getCurrentState().getIdToDb().values();
for (Database db : CollectionUtils.emptyIfNull(dbs)) {
for (Table table : CollectionUtils.emptyIfNull(db.getTables())) {
Copy link
Contributor

Choose a reason for hiding this comment

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

what will happen if dropping the db during processing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. the table list is got from a ConcurrentHashMap
  2. tryToActivate will verify the existence of database again, throw exception if database doesn't exist

@ABingHuang
Copy link
Contributor

can we add a logic to active mv during mv refresh?

Signed-off-by: Murphy <[email protected]>
@sonarcloud
Copy link

sonarcloud bot commented Oct 17, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 9 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

@wanpengfei-git
Copy link
Collaborator

[BE Incremental Coverage Report]

😍 pass : 0 / 0 (0%)

@wanpengfei-git
Copy link
Collaborator

[FE Incremental Coverage Report]

😍 pass : 44 / 51 (86.27%)

file detail

path covered_line new_line coverage not_covered_line_detail
🔵 com/starrocks/scheduler/MVActiveChecker.java 36 43 83.72% [53, 54, 87, 88, 104, 105, 106]
🔵 com/starrocks/scheduler/PartitionBasedMvRefreshProcessor.java 3 3 100.00% []
🔵 com/starrocks/common/Config.java 1 1 100.00% []
🔵 com/starrocks/alter/AlterJobMgr.java 1 1 100.00% []
🔵 com/starrocks/server/GlobalStateMgr.java 3 3 100.00% []

@satanson satanson merged commit c1e3a1e into StarRocks:main Oct 17, 2023
47 checks passed
@wanpengfei-git
Copy link
Collaborator

@Mergifyio backport branch-3.2

@github-actions github-actions bot removed the 3.2 label Oct 17, 2023
@wanpengfei-git
Copy link
Collaborator

@Mergifyio backport branch-3.1

@github-actions github-actions bot removed the 3.1 label Oct 17, 2023
@mergify
Copy link
Contributor

mergify bot commented Oct 17, 2023

backport branch-3.2

✅ Backports have been created

@wanpengfei-git
Copy link
Collaborator

@Mergifyio backport branch-3.0

@github-actions github-actions bot removed the 3.0 label Oct 17, 2023
@mergify
Copy link
Contributor

mergify bot commented Oct 17, 2023

backport branch-3.1

✅ Backports have been created

@mergify
Copy link
Contributor

mergify bot commented Oct 17, 2023

backport branch-3.0

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request Oct 17, 2023
Signed-off-by: Murphy <[email protected]>
(cherry picked from commit c1e3a1e)
mergify bot pushed a commit that referenced this pull request Oct 17, 2023
Signed-off-by: Murphy <[email protected]>
(cherry picked from commit c1e3a1e)

# Conflicts:
#	fe/fe-core/src/main/java/com/starrocks/alter/AlterJobMgr.java
#	fe/fe-core/src/main/java/com/starrocks/server/GlobalStateMgr.java
#	fe/fe-core/src/test/java/com/starrocks/analysis/AlterMaterializedViewTest.java
mergify bot pushed a commit that referenced this pull request Oct 17, 2023
Signed-off-by: Murphy <[email protected]>
(cherry picked from commit c1e3a1e)

# Conflicts:
#	fe/fe-core/src/main/java/com/starrocks/alter/AlterJobMgr.java
#	fe/fe-core/src/main/java/com/starrocks/common/Config.java
#	fe/fe-core/src/main/java/com/starrocks/server/GlobalStateMgr.java
#	fe/fe-core/src/test/java/com/starrocks/analysis/AlterMaterializedViewTest.java
#	fe/fe-core/src/test/java/com/starrocks/scheduler/PartitionBasedMvRefreshProcessorTest.java
wanpengfei-git pushed a commit that referenced this pull request Oct 17, 2023
Signed-off-by: Murphy <[email protected]>
(cherry picked from commit c1e3a1e)
wanpengfei-git pushed a commit that referenced this pull request Nov 3, 2023
Signed-off-by: Murphy <[email protected]>
(cherry picked from commit c1e3a1e)

# Conflicts:
#	fe/fe-core/src/main/java/com/starrocks/alter/AlterJobMgr.java
#	fe/fe-core/src/main/java/com/starrocks/server/GlobalStateMgr.java
#	fe/fe-core/src/test/java/com/starrocks/analysis/AlterMaterializedViewTest.java
@murphyatwork
Copy link
Contributor Author

@Mergifyio backport branch-2.5

Copy link
Contributor

mergify bot commented Jan 5, 2024

backport branch-2.5

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request Jan 5, 2024
Signed-off-by: Murphy <[email protected]>
(cherry picked from commit c1e3a1e)

# Conflicts:
#	fe/fe-core/src/main/java/com/starrocks/alter/Alter.java
#	fe/fe-core/src/main/java/com/starrocks/common/Config.java
#	fe/fe-core/src/main/java/com/starrocks/server/GlobalStateMgr.java
#	fe/fe-core/src/test/java/com/starrocks/analysis/AlterMaterializedViewTest.java
#	fe/fe-core/src/test/java/com/starrocks/scheduler/PartitionBasedMvRefreshProcessorTest.java
murphyatwork added a commit that referenced this pull request Jan 5, 2024
Signed-off-by: Murphy <[email protected]>
(cherry picked from commit c1e3a1e)
murphyatwork added a commit that referenced this pull request Jan 5, 2024
Signed-off-by: Murphy <[email protected]>
(cherry picked from commit c1e3a1e)
Signed-off-by: Murphy <[email protected]>
murphyatwork added a commit that referenced this pull request Jan 5, 2024
Signed-off-by: Murphy <[email protected]>
(cherry picked from commit c1e3a1e)
Signed-off-by: Murphy <[email protected]>
wanpengfei-git pushed a commit that referenced this pull request Jan 6, 2024
wanpengfei-git pushed a commit that referenced this pull request Jan 7, 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