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

feat(cleanVm): add recovery method for duplicated vhd uuid containing… #6314

Closed
wants to merge 2 commits into from

Conversation

fbeauchamp
Copy link
Collaborator

@fbeauchamp fbeauchamp commented Jul 4, 2022

… the same data

Check list

Check if done, if not relevant leave unchecked.

  • PR reference the relevant issue (e.g. Fixes #007 or See xoa-support#42)
  • if UI changes, a screenshot has been added to the PR
  • documentation updated
  • CHANGELOG.unreleased.md:
    • enhancement/bug fix entry added
    • list of packages to release updated (${name} v${new version})
  • I have tested added/updated features (and impacted code)

Process

  1. create a PR as soon as possible
  2. mark it as WiP: (Work in Progress) if not ready to be merged
  3. when you want a review, add a reviewer (and only one)
  4. if necessary, update your PR, and re- add a reviewer

From the Four Agreements:

  1. Be impeccable with your word.
  2. Don't take anything personally.
  3. Don't make assumptions.
  4. Always do your best.

@fbeauchamp fbeauchamp force-pushed the check_vhd_uniq_id branch from 6512d23 to 4a1c481 Compare July 4, 2022 07:40
@fbeauchamp fbeauchamp force-pushed the check_vhd_uniq_id branch from 4a1c481 to 64a6b62 Compare July 4, 2022 07:42
@fbeauchamp fbeauchamp requested a review from julien-f July 4, 2022 07:48
* check if all the data of a child are already contained in this vhd
*/

async contains(child) {
Copy link
Member

Choose a reason for hiding this comment

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

More explicit name, which make it more obvious that this is not a light operation:

Suggested change
async contains(child) {
async containsAllBlockOf(child) {

Comment on lines +343 to +344
await this.readBlockAllocationTable()
await child.readBlockAllocationTable()
Copy link
Member

Choose a reason for hiding this comment

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

I believe this method (and some others), are pitfalls, and should be implcitely called when necessary (e.g., when calling blocks).

If you agree, I'll do the change.

async contains(child) {
await this.readBlockAllocationTable()
await child.readBlockAllocationTable()
for await (const block of child.blocks()) {
Copy link
Member

Choose a reason for hiding this comment

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

Don't read blocks before checking the parent contains them.

Maybe we should add another iterator (blockIds())?

const duplicate = vhdIds.get(vhd.footer.uuid)
if (duplicate) {
logWarn('uuid is duplicated', { uuid: vhd.footer.uuid })
// uuid is already present
Copy link
Member

Choose a reason for hiding this comment

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

Is this comment really necessary?

It's obvious by the if (duplicate) or am I missing something?

@@ -208,6 +209,19 @@ exports.cleanVm = async function cleanVm(
}
vhdChildren[parent] = path
}
const duplicate = vhdIds.get(vhd.footer.uuid)
if (duplicate) {
Copy link
Member

Choose a reason for hiding this comment

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

As per current XO coding style: never rely on implicit boolean conversation, ie explicit comparison.

@@ -189,6 +189,7 @@ exports.cleanVm = async function cleanVm(
const vhdsToJSons = new Set()
const vhdParents = { __proto__: null }
const vhdChildren = { __proto__: null }
const vhdIds = new Map()
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const vhdIds = new Map()
const vhdById = new Map()

Copy link
Member

Choose a reason for hiding this comment

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

Otherwise I think it's a set when reading the code 🙂

Comment on lines +212 to +223
const duplicate = vhdById.get(vhd.footer.uuid)
if (duplicate !== undefined) {
logWarn('uuid is duplicated', { uuid: vhd.footer.uuid })
if (duplicate.containsAllDataOf(vhd)) {
logWarn(`should delete ${path}`)
} else if (vhd.containsAllDataOf(duplicate)) {
logWarn(`should delete ${duplicate._path}`)
} else {
logWarn(`same ids but different content`)
}
}
vhdById.set(vhd.footer.uuid, vhd)
Copy link
Member

Choose a reason for hiding this comment

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

Do we want to release this in prod?

- xo-web minor
- vhd-lib minor
Copy link
Member

Choose a reason for hiding this comment

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

Alphabetic order please 🙂

@fbeauchamp
Copy link
Collaborator Author

supeseed by #6317

@fbeauchamp fbeauchamp closed this Jul 7, 2022
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