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

Add orphan node check #90

Merged
merged 3 commits into from
May 31, 2021
Merged

Add orphan node check #90

merged 3 commits into from
May 31, 2021

Conversation

yichen88
Copy link
Contributor

@yichen88 yichen88 commented May 25, 2021

Signed-off-by: yichen88 [email protected]

Please check if the PR fulfills these requirements (please use '[x]' to check the checkboxes, or submit the PR and then click the checkboxes)

  • The commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

Does this PR already have an issue describing the problem ? If so, link to this issue using '#XXX' and skip the rest

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
#87

What is the current behavior? (You can also link to an open issue here)

What is the new behavior (if this is a feature change)?

Does this PR introduce a breaking change or deprecate an API? If yes, check the following:

  • The Breaking Change or Deprecated label has been added
  • The migration guide has been updated in the github wiki (What changes might users need to make in their application due to this PR?)

Other information:

(if any of the questions/checkboxes don't apply, please delete them entirely)

Signed-off-by: yichen88 <[email protected]>
@yichen88 yichen88 force-pushed the fsck_orphan_child branch from e6c83d4 to 155edac Compare May 26, 2021 07:22
Copy link
Contributor

@sylvlecl sylvlecl left a comment

Choose a reason for hiding this comment

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

Good but we also need to handle associated data when deleting the oprhan node!

statements.add(delete().from(CHILDREN_BY_NAME_AND_CLASS)
.where(eq(ID, fakeParentId)));
issue.setRepaired(true);
issue.setResolutionDescription("Delete row and its parent row");
Copy link
Contributor

Choose a reason for hiding this comment

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

We can provide a more explicit message like "Deleted node [name=, id=] and reference to absent node [id=]"

.setDescription(nodeName + "(" + nodeId + ") is an orphan node. Its fake parent id:" + fakeParentId);
if (options.isRepair()) {
statements.add(delete().from(CHILDREN_BY_NAME_AND_CLASS)
.where(eq(ID, nodeId)));
Copy link
Contributor

Choose a reason for hiding this comment

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

This will not be enough, because we need to also delete all associated date, like for a normal node delete:

  • delete its children
  • delete the associated data
  • etc.

Signed-off-by: yichen88 <[email protected]>
@yichen88
Copy link
Contributor Author

yichen88 commented May 27, 2021

An example table which contains an orphan node.

 id                                   | name         | child_id                             | child_name  | child_consistent | consistent
--------------------------------------+--------------+--------------------------------------+-------------+------------------+------------
 e9c5f260-bec9-11eb-a512-43cfd22f4fca |         root | e9c8d890-bec9-11eb-a512-43cfd22f4fca |      bar_wa |             True |       True
 a0cfdb60-beca-11eb-8d4f-8f9836277e08 |  orphanNodes | a0d5a7c0-beca-11eb-8d4f-8f9836277e08 | orphanChild |             True |       True
 e9c8d890-bec9-11eb-a512-43cfd22f4fca |       bar_wa |                                 null |        null |             null |       True
 a0cfb450-beca-11eb-8d4f-8f9836277e08 |         null | a0cfdb60-beca-11eb-8d4f-8f9836277e08 | orphanNodes |             True |       null
 a0d5a7c0-beca-11eb-8d4f-8f9836277e08 |  orphanChild |                                 null |        null |             null |       True

Created by code like

        final NodeInfo orphanNodes = storage.createNode(UUIDs.timeBased().toString(), "orphanNodes", FOLDER_PSEUDO_CLASS, "", 0, new NodeGenericMetadata());
        storage.setConsistent(orphanNodes.getId());
        NodeInfo orphanChild = storage.createNode(orphanNodes.getId(), "orphanChild", FOLDER_PSEUDO_CLASS, "", 0, new NodeGenericMetadata());
        storage.setConsistent(orphanChild.getId());

The fix processing is to find all node's name are null, then use deleteNode() method to delete its children and use statement to delete the parent node(null name node) row.

@sylvlecl sylvlecl self-requested a review May 31, 2021 08:32
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!

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

94.9% 94.9% Coverage
0.0% 0.0% Duplication

@sylvlecl sylvlecl merged commit 60b808a into master May 31, 2021
@sylvlecl sylvlecl deleted the fsck_orphan_child branch May 31, 2021 09:00
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.

2 participants