-
Notifications
You must be signed in to change notification settings - Fork 540
[#6744] improvment(core): Batch get metadata objects for TagMetaService #6752
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
Conversation
Could you please take some time to review this PR? |
@@ -71,4 +71,7 @@ Long selectColumnIdByTableIdAndName( | |||
|
|||
@SelectProvider(type = TableColumnSQLProviderFactory.class, method = "selectColumnPOById") | |||
ColumnPO selectColumnPOById(@Param("columnId") Long columnId); | |||
|
|||
@SelectProvider(type = TableColumnSQLProviderFactory.class, method = "listColumnPOsByColumnIds") | |||
List<ColumnPO> listColumnPOsByTableIds(@Param("columnIds") List<Long> columnIds); |
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.
columnIds or TableIds?
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.
It's columnIds and I will modify it.
+ ") " | ||
+ " AND c.deleted_at = 0" | ||
+ "</script>"; | ||
} |
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.
Does this SQL work for H2 and PG?
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.
Can you add a test to cover this?
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.
LOG.warn( | ||
"The table '{}' of column '{}' may be deleted", | ||
columnPO.getTableId(), | ||
columnPO.getColumnId()); | ||
columnIdAndNameMap.put(columnPO.getColumnId(), null); | ||
return; |
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.
What will be happened if table name is null? Shall we throw an exception here?
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.
According to the comment and code logic, the table can be deleted when when query the columns, we should ingore it. please see:
gravitino/core/src/main/java/org/apache/gravitino/storage/relational/service/TagMetaService.java
Lines 238 to 242 in 2668aaf
// Metadata object may be deleted asynchronously when we query the name, so it will return | |
// null. We should skip this metadata object. | |
if (fullName == null) { | |
continue; | |
} |
metadataObjects.add(MetadataObjects.parse(fullName, type)); | ||
} | ||
}); | ||
}); |
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.
Do we have a test to cover this, if not please add a test.
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.
There exists UT that can covert it and I have checked several problems during developing process through it, please see TestTagMetaService#testListAssociatedMetadataObjectsForTag
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.
I would suggest changing to use for..loop here instead of using stream, it is very hard to read the code.
@@ -55,6 +58,18 @@ public static TagMetaService getInstance() { | |||
return INSTANCE; | |||
} | |||
|
|||
private static final Map<MetadataObject.Type, Function<List<Long>, Map<Long, String>>> |
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.
Shall RoleService replace the code with similar logic?
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.
Yes, the code in RoleService
uses a temporary value in a method to solve it. They are mostly the same and have minor differences.
Do you mean we may need to try to merge them?
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.
Yes, we should merge them. I guess
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.
fix
@@ -90,4 +90,8 @@ public static String selectColumnIdByTableIdAndName( | |||
public static String selectColumnPOById(@Param("columnId") Long columnId) { | |||
return getProvider().selectColumnPOById(columnId); | |||
} | |||
|
|||
public static String listColumnPOsByColumnIds(@Param("columnIds") List<Long> columnIds) { | |||
return getProvider().listColumnPOsByTableIds(columnIds); |
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.
Is it "columnIds" or tableIds
?
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
@@ -57,6 +59,18 @@ public class MetadataObjectService { | |||
|
|||
private static final Logger LOG = LoggerFactory.getLogger(MetadataObjectService.class); | |||
|
|||
public static final Map<MetadataObject.Type, Function<List<Long>, Map<Long, String>>> |
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.
Why do you make it public?
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.
RoleMetaService
also uses it. I can lower the access level and use the package level.
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.
Changed
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.
LGTM.
…aService (apache#6752) ### What changes were proposed in this pull request? Group by metadata object by metadata type and batch get all metadata with the same type. ### Why are the changes needed? To return the times to access databases and improve performance. Fix: apache#6744 ### Does this PR introduce _any_ user-facing change? N/A ### How was this patch tested? Test locally and existing tests.
…aService (apache#6752) ### What changes were proposed in this pull request? Group by metadata object by metadata type and batch get all metadata with the same type. ### Why are the changes needed? To return the times to access databases and improve performance. Fix: apache#6744 ### Does this PR introduce _any_ user-facing change? N/A ### How was this patch tested? Test locally and existing tests.
What changes were proposed in this pull request?
Group by metadata object by metadata type and batch get all metadata with the same type.
Why are the changes needed?
To return the times to access databases and improve performance.
Fix: #6744
Does this PR introduce any user-facing change?
N/A
How was this patch tested?
Test locally and existing tests.