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] Support use table_name to filter scan in information_schema.tables #45351

Merged
merged 2 commits into from
May 9, 2024

Conversation

HangyuanLiu
Copy link
Contributor

@HangyuanLiu HangyuanLiu commented May 9, 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

Signed-off-by: HangyuanLiu <460660596@qq.com>
# Conflicts:
#	be/src/exec/schema_scanner/schema_tables_scanner.cpp
@HangyuanLiu HangyuanLiu requested a review from a team as a code owner May 9, 2024 08:20
if (table.isNativeTableOrMaterializedView()) {
tableLocker.unLockTablesWithIntensiveDbLock(db, Lists.newArrayList(((OlapTable) table).getId()),
LockType.READ);
}
}
}
}
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 deadlock due to nested locking mechanisms without a consistent lock acquisition order.

You can modify the code like this:

// Before introducing new lock (tableLocker) inside the loop for tables,
// ensure there's a global policy or mechanism to avoid deadlocks.
// One approach could be ensuring that locks are always acquired in a consistent order and possibly reducing the scope where locks are held.
// For example, rather than acquiring a second lock inside the loop while still holding the first lock,
// consider restructuring the code to release the database lock before working on individual tables if feasible.

// This suggestion points towards a conceptual modification since the exact fix would need a detailed understanding of the overall locking strategy and application structure.

// Potential approach:
for (String dbName : result.authorizedDbs) {
    Database db = metadataMgr.getDb(catalogName, dbName);
    if (db == null) {
        continue;
    }

    List<String> tableNames = metadataMgr.listTableNames(catalogName, dbName);
    
    // Release the first lock before acquiring more specific table locks
    // Assuming some mechanism or rearrangement enables us to do so safely

    for (String tableName : tableNames) {
        if (request.isSetTable_name() && !tableName.equals(request.getTable_name())) {
            continue;
        }

        Locker tableLocker = new Locker();
        try {
            BasicTable table = metadataMgr.getBasicTable(catalogName, dbName, tableName);
            if (table == null) {
                continue;
            }

            tableLocker.lockTablesWithIntensiveDbLock(db, Lists.newArrayList(((OlapTable) table).getId()), LockType.READ);

            // process table...

        } catch (Exception e) {
            LOG.warn(e.getMessage());
        } finally {
            tableLocker.unLockTablesWithIntensiveDbLock(db, Lists.newArrayList(((OlapTable) table).getId()), LockType.READ);
        }
    }
}

// Note: This does not represent a complete solution but highlights the importance of addressing potential deadlock scenarios by carefully managing lock acquisition and release sequences.

Copy link

sonarcloud bot commented May 9, 2024

Copy link

github-actions bot commented May 9, 2024

[FE Incremental Coverage Report]

pass : 44 / 48 (91.67%)

file detail

path covered_line new_line coverage not_covered_line_detail
🔵 com/starrocks/service/InformationSchemaDataSource.java 44 48 91.67% [397, 415, 416, 419]

Copy link

github-actions bot commented May 9, 2024

[BE Incremental Coverage Report]

pass : 2 / 2 (100.00%)

file detail

path covered_line new_line coverage not_covered_line_detail
🔵 be/src/exec/schema_scanner/schema_tables_scanner.cpp 2 2 100.00% []

@trueeyu trueeyu merged commit 948e48f into StarRocks:main May 9, 2024
63 of 67 checks passed
Copy link

github-actions bot commented May 9, 2024

@Mergifyio backport branch-3.3

@github-actions github-actions bot removed the 3.3 label May 9, 2024
Copy link

github-actions bot commented May 9, 2024

@Mergifyio backport branch-3.2

@github-actions github-actions bot removed the 3.2 label May 9, 2024
Copy link

github-actions bot commented May 9, 2024

@Mergifyio backport branch-3.1

@github-actions github-actions bot removed the 3.1 label May 9, 2024
Copy link

github-actions bot commented May 9, 2024

@Mergifyio backport branch-3.0

Copy link

github-actions bot commented May 9, 2024

@Mergifyio backport branch-2.5

Copy link
Contributor

mergify bot commented May 9, 2024

backport branch-3.1

✅ Backports have been created

Copy link
Contributor

mergify bot commented May 9, 2024

backport branch-3.0

✅ Backports have been created

Copy link
Contributor

mergify bot commented May 9, 2024

backport branch-2.5

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request May 9, 2024
…hema.tables (#45351)

Signed-off-by: HangyuanLiu <460660596@qq.com>
(cherry picked from commit 948e48f)

# Conflicts:
#	be/src/exec/schema_scanner/schema_tables_scanner.cpp
mergify bot pushed a commit that referenced this pull request May 9, 2024
…hema.tables (#45351)

Signed-off-by: HangyuanLiu <460660596@qq.com>
(cherry picked from commit 948e48f)

# Conflicts:
#	be/src/exec/schema_scanner/schema_tables_scanner.cpp
#	fe/fe-core/src/main/java/com/starrocks/service/InformationSchemaDataSource.java
mergify bot pushed a commit that referenced this pull request May 9, 2024
…hema.tables (#45351)

Signed-off-by: HangyuanLiu <460660596@qq.com>
(cherry picked from commit 948e48f)

# Conflicts:
#	be/src/exec/schema_scanner/schema_tables_scanner.cpp
#	fe/fe-core/src/main/java/com/starrocks/service/InformationSchemaDataSource.java
mergify bot pushed a commit that referenced this pull request May 9, 2024
…hema.tables (#45351)

Signed-off-by: HangyuanLiu <460660596@qq.com>
(cherry picked from commit 948e48f)

# Conflicts:
#	be/src/exec/schema_scanner/schema_tables_scanner.cpp
#	fe/fe-core/src/main/java/com/starrocks/service/InformationSchemaDataSource.java
mergify bot pushed a commit that referenced this pull request May 9, 2024
…hema.tables (#45351)

Signed-off-by: HangyuanLiu <460660596@qq.com>
(cherry picked from commit 948e48f)

# Conflicts:
#	be/src/exec/vectorized/schema_scanner/schema_tables_scanner.cpp
#	fe/fe-core/src/main/java/com/starrocks/service/InformationSchemaDataSource.java
HangyuanLiu added a commit that referenced this pull request May 10, 2024
…hema.tables (#45351)

Signed-off-by: HangyuanLiu <460660596@qq.com>
(cherry picked from commit 948e48f)

# Conflicts:
#	be/src/exec/vectorized/schema_scanner/schema_tables_scanner.cpp
#	fe/fe-core/src/main/java/com/starrocks/service/InformationSchemaDataSource.java
HangyuanLiu added a commit that referenced this pull request May 10, 2024
…hema.tables (#45351)

Signed-off-by: HangyuanLiu <460660596@qq.com>
(cherry picked from commit 948e48f)

# Conflicts:
#	be/src/exec/vectorized/schema_scanner/schema_tables_scanner.cpp
#	fe/fe-core/src/main/java/com/starrocks/service/InformationSchemaDataSource.java
HangyuanLiu added a commit that referenced this pull request May 10, 2024
…hema.tables (#45351)

Signed-off-by: HangyuanLiu <460660596@qq.com>
(cherry picked from commit 948e48f)

# Conflicts:
#	be/src/exec/schema_scanner/schema_tables_scanner.cpp
wanpengfei-git pushed a commit that referenced this pull request May 10, 2024
…hema.tables (backport #45351) (#45388)

Co-authored-by: HangyuanLiu <460660596@qq.com>
wanpengfei-git pushed a commit that referenced this pull request May 10, 2024
…hema.tables (backport #45351) (#45392)

Co-authored-by: HangyuanLiu <460660596@qq.com>
HangyuanLiu added a commit that referenced this pull request May 10, 2024
…hema.tables (#45351)

Signed-off-by: HangyuanLiu <460660596@qq.com>
(cherry picked from commit 948e48f)

# Conflicts:
#	be/src/exec/schema_scanner/schema_tables_scanner.cpp
#	fe/fe-core/src/main/java/com/starrocks/service/InformationSchemaDataSource.java
wanpengfei-git pushed a commit that referenced this pull request May 10, 2024
…hema.tables (backport #45351) (#45391)

Co-authored-by: HangyuanLiu <460660596@qq.com>
HangyuanLiu added a commit that referenced this pull request May 10, 2024
…hema.tables (#45351)

Signed-off-by: HangyuanLiu <460660596@qq.com>
(cherry picked from commit 948e48f)

# Conflicts:
#	be/src/exec/schema_scanner/schema_tables_scanner.cpp
#	fe/fe-core/src/main/java/com/starrocks/service/InformationSchemaDataSource.java
wanpengfei-git pushed a commit that referenced this pull request May 10, 2024
…hema.tables (backport #45351) (#45390)

Co-authored-by: HangyuanLiu <460660596@qq.com>
HangyuanLiu added a commit that referenced this pull request May 11, 2024
…hema.tables (#45351)

Signed-off-by: HangyuanLiu <460660596@qq.com>
(cherry picked from commit 948e48f)

# Conflicts:
#	be/src/exec/schema_scanner/schema_tables_scanner.cpp
#	fe/fe-core/src/main/java/com/starrocks/service/InformationSchemaDataSource.java
wanpengfei-git pushed a commit that referenced this pull request May 11, 2024
…hema.tables (backport #45351) (#45389)

Co-authored-by: HangyuanLiu <460660596@qq.com>
node pushed a commit to vivo/starrocks that referenced this pull request May 17, 2024
…hema.tables (StarRocks#45351)

Signed-off-by: HangyuanLiu <460660596@qq.com>
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.

None yet

4 participants