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

[#5029] improvement(storage): Delete the related relations about the metadata object when it is deleted. #5426

Merged
merged 11 commits into from
Nov 6, 2024

Conversation

jerqi
Copy link
Contributor

@jerqi jerqi commented Nov 1, 2024

What changes were proposed in this pull request?

Delete the related relations about the metadata object when it is deleted.

Why are the changes needed?

Fix: #5029

Does this PR introduce any user-facing change?

No.

How was this patch tested?

Add UTs.

@jerqi jerqi self-assigned this Nov 1, 2024
@jerqi jerqi force-pushed the ISSUE-5029 branch 7 times, most recently from eb7235d to df6e04d Compare November 1, 2024 11:13
@jerqi jerqi requested a review from yuqi1129 November 1, 2024 11:15
public String softDeleteObjectRelsByCatalogId(@Param("catalogId") Long catalogId) {
return "UPDATE "
+ SECURABLE_OBJECT_TABLE_NAME
+ " sect SET deleted_at = (UNIX_TIMESTAMP() * 1000.0)"
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we simply use this SQL as "

update SECURABLE_OBJECT_TABLE_NAME c set xxxxx

where sect.deleted_at = 0 and sec.type in ('catalog', 'schema'....) and exist (



.....
)
 

Copy link
Contributor Author

@jerqi jerqi Nov 4, 2024

Choose a reason for hiding this comment

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

sec.type are different for sub-sentences. deleted_atis ok.

Comment on lines 260 to 275
() ->
SessionUtils.doWithoutCommit(
SecurableObjectMapper.class,
mapper ->
mapper.softDeleteObjectRelsByMetadataObject(
catalogId, MetadataObject.Type.CATALOG.name())),
() ->
SessionUtils.doWithoutCommit(
TagMetadataObjectRelMapper.class,
mapper ->
mapper.softDeleteTagMetadataObjectRelsByMetadataObject(
catalogId, MetadataObject.Type.CATALOG.name())),
() ->
SessionUtils.doWithoutCommit(
CatalogMetaMapper.class,
mapper -> mapper.softDeleteCatalogMetasByCatalogId(catalogId)));
Copy link
Contributor

@yuqi1129 yuqi1129 Nov 4, 2024

Choose a reason for hiding this comment

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

Does the deletion sequence of securableobject, tag and catalog matters in this transaction? why do you change the sequence of them?

Copy link
Contributor Author

@jerqi jerqi Nov 4, 2024

Choose a reason for hiding this comment

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

My fault. I shouldn't change the order.

@@ -229,6 +231,31 @@ public boolean deleteTable(NameIdentifier identifier) {
if (deleteResult.get() > 0) {
TableColumnMetaService.getInstance().deleteColumnsByTableId(tableId);
}
},
() -> {
if (deleteResult.get() > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a problem unrelated to this PR. please see L218, Since it uses doWithCommitAndFetchResult, so it's will use two transactions in the deleteTable if I'm not wrong.

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, we should change this.

@@ -231,7 +231,7 @@ public boolean deleteMetalake(NameIdentifier ident, boolean cascade) {
() ->
SessionUtils.doWithoutCommit(
SecurableObjectMapper.class,
mapper -> mapper.softDeleteRoleMetasByMetalakeId(metalakeId)),
mapper -> mapper.softDeleteSecurableObjectsByMetalakeId(metalakeId)),
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this just a fix to a problem that existed before? I reviewed the code, L230 has the same code if it's not modified.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

One is deleting role meta data, another is deleting role's securable object metadata.

Comment on lines 238 to 258
SecurableObjectMapper.class,
mapper ->
mapper.softDeleteObjectRelsByMetadataObject(
tableId, MetadataObject.Type.TABLE.name()));
}
},
() -> {
if (deleteResult.get() > 0) {
SessionUtils.doWithoutCommit(
TagMetadataObjectRelMapper.class,
mapper ->
mapper.softDeleteTagMetadataObjectRelsByMetadataObject(
tableId, MetadataObject.Type.TABLE.name()));
}
},
() -> {
if (deleteResult.get() > 0) {
SessionUtils.doWithoutCommit(
TagMetadataObjectRelMapper.class,
mapper -> mapper.softDeleteTagMetadataObjectRelsByTableId(tableId));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we merge this operation into one like

if (deleteResult.get() > 0) {

// one
SessionUtils.doWithoutCommit()

// two
SessionUtils.doWithoutCommit()

...
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK.

@yuqi1129
Copy link
Contributor

yuqi1129 commented Nov 6, 2024

The code looks good to me.

yuqi1129
yuqi1129 previously approved these changes Nov 6, 2024
This reverts commit b4106dc.
@jerryshao jerryshao merged commit facfe83 into apache:main Nov 6, 2024
26 checks passed
@jerryshao jerryshao added the 0.8.0 Release v0.8.0 label Nov 6, 2024
@jerqi jerqi deleted the ISSUE-5029 branch November 6, 2024 09:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.8.0 Release v0.8.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Improvement] When we delete the entity, we should delete the relation between entity and tag or role
3 participants