Skip to content

[#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

Merged
merged 6 commits into from
Apr 4, 2025

Conversation

yuqi1129
Copy link
Contributor

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.

@yuqi1129 yuqi1129 self-assigned this Mar 25, 2025
@yuqi1129
Copy link
Contributor Author

@jerqi

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);
Copy link
Contributor

Choose a reason for hiding this comment

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

columnIds or TableIds?

Copy link
Contributor Author

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>";
}
Copy link
Contributor

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?

Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

TagIT has tests tag.associatedObjects() to cover this changes and It should be work for H2 and PG as the IT has been run with backend H2 and PG.

image

Comment on lines +294 to +299
LOG.warn(
"The table '{}' of column '{}' may be deleted",
columnPO.getTableId(),
columnPO.getColumnId());
columnIdAndNameMap.put(columnPO.getColumnId(), null);
return;
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 be happened if table name is null? Shall we throw an exception here?

Copy link
Contributor Author

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:

// 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));
}
});
});
Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

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>>>
Copy link
Contributor

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?

Copy link
Contributor Author

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?

Copy link
Contributor

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

Copy link
Contributor Author

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);
Copy link
Contributor

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?

Copy link
Contributor Author

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>>>
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed

Copy link
Contributor

@jerryshao jerryshao left a comment

Choose a reason for hiding this comment

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

LGTM.

@jerryshao jerryshao merged commit fbdb14f into apache:main Apr 4, 2025
28 checks passed
Abyss-lord pushed a commit to Abyss-lord/gravitino that referenced this pull request Apr 15, 2025
…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.
Abyss-lord pushed a commit to Abyss-lord/gravitino that referenced this pull request Apr 27, 2025
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Improvement] batch listing objects in TagMetaManager
3 participants