Skip to content

Clear pool id if volume allocation fails#8202

Merged
harikrishna-patnala merged 3 commits into
apache:4.18from
anniejili:clear_pool_id_if_volume_allocation_fails
Nov 21, 2023
Merged

Clear pool id if volume allocation fails#8202
harikrishna-patnala merged 3 commits into
apache:4.18from
anniejili:clear_pool_id_if_volume_allocation_fails

Conversation

@anniejili

Copy link
Copy Markdown
Contributor

Description

When there is outage in storage API coincides with a VM start, the volume could be stuck in "Allocated" state but with a pool Id assigned in DB. It blocked the ability to start the VM during planDeployment process, in the method storagePoolCompatibleWithVolumePool() shown below when validating a volume with a storage pool, if the volume's pool Id is not null and state is Allocated, it would always return false for any storage pools. As a result, the allocator cannot find a suitable pool and it blocks the VM start process.

@Override
    public boolean storagePoolCompatibleWithVolumePool(StoragePool pool, Volume volume) {
        if (pool == null || volume == null) {
            return false;
        }

        if (volume.getPoolId() == null) {
            // Volume is not allocated to any pool. Not possible to check compatibility with other pool, let it try
            return true;
        }

        StoragePool volumePool = _storagePoolDao.findById(volume.getPoolId());
        if (volumePool == null) {
            // Volume pool doesn't exist. Not possible to check compatibility with other pool, let it try
            return true;
        }

        if (volume.getState() == Volume.State.Ready) {
            if (volumePool.getPoolType() == Storage.StoragePoolType.PowerFlex && pool.getPoolType() != Storage.StoragePoolType.PowerFlex) {
                return false;
            } else if (volumePool.getPoolType() != Storage.StoragePoolType.PowerFlex && pool.getPoolType() == Storage.StoragePoolType.PowerFlex) {
                return false;
            }
        } else {
            return false;
        }

        return true;
    }

This PR fixed the issue above by validating volumes's state and pool id before the deployment in DeploymentPlanningManagerImpl.java's findSuitablePoolsForVolumes() method. Before DeploymentPlanningManager is trying to find suitable storage pools for volumes, if any volume is in Allocated state with a pool ID, the pool id will be cleared.
Testing
For a stopped VM, manually updated its root volume state to "Allocated" with a pool ID. Then restart the VM.

Before the change

2023-08-22 23:40:00,948 INFO [o.a.c.a.c.u.v.StartVMCmd] (API-Job-Executor-70:ctx-xxxx job-xxxx ctx-xxxx) (logid:xxxx) No destination found for a deployment for VM instance {id: "xxxx", name: "xxxx, uuid: "xxxx", type="User"}

After the change

The VM is started successfully.

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (improves an existing feature and functionality)
  • Cleanup (Code refactoring and cleanup, that may add test cases)

Feature/Enhancement Scale or Bug Severity

Feature/Enhancement Scale

  • Major
  • Minor

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

Screenshots (if appropriate):

How Has This Been Tested?

The change is tested via added junit test cases. The change is also tested and verified in Cloud Stack development environment.

@boring-cyborg

boring-cyborg Bot commented Nov 8, 2023

Copy link
Copy Markdown

Congratulations on your first Pull Request and welcome to the Apache CloudStack community! If you have any issues or are unsure about any anything please check our Contribution Guide (https://github.com/apache/cloudstack/blob/main/CONTRIBUTING.md)
Here are some useful points:

@codecov

codecov Bot commented Nov 9, 2023

Copy link
Copy Markdown

Codecov Report

Attention: 4 lines in your changes are missing coverage. Please review.

Comparison is base (1a2dbeb) 13.10% compared to head (91896cd) 13.12%.

Files Patch % Lines
...om/cloud/deploy/DeploymentPlanningManagerImpl.java 42.85% 1 Missing and 3 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               4.18    #8202      +/-   ##
============================================
+ Coverage     13.10%   13.12%   +0.01%     
- Complexity     9122     9135      +13     
============================================
  Files          2720     2720              
  Lines        257638   257645       +7     
  Branches      40168    40171       +3     
============================================
+ Hits          33753    33805      +52     
+ Misses       219619   219548      -71     
- Partials       4266     4292      +26     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@yadvr

yadvr commented Nov 9, 2023

Copy link
Copy Markdown
Member

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@rohityadavcloud a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

@blueorangutan

Copy link
Copy Markdown

Packaging result [SF]: ✔️ el7 ✔️ el8 ✔️ el9 ✔️ debian ✔️ suse15. SL-JID 7690

@harikrishna-patnala

Copy link
Copy Markdown
Member

@blueorangutan test

@blueorangutan

Copy link
Copy Markdown

@harikrishna-patnala a [SL] Trillian-Jenkins test job (centos7 mgmt + kvm-centos7) has been kicked to run smoke tests

@harikrishna-patnala harikrishna-patnala left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, Tested both root and data disks, VM started fine.

@DaanHoogland DaanHoogland left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

clgtm, one worry though; @anniejili Do we need to check if the volume is actually present on the pool? I.E. if the volume has been allocated before it might actually exist (even though it has the state of Allocated)

@yadvr yadvr added this to the 4.18.2.0 milestone Nov 9, 2023
@harikrishna-patnala

Copy link
Copy Markdown
Member

clgtm, one worry though; @anniejili Do we need to check if the volume is actually present on the pool? I.E. if the volume has been allocated before it might actually exist (even though it has the state of Allocated)

@DaanHoogland according to the volume state machine, volume will be in allocated state either as the starting state or when the operation is failed. So I dont think volume will actually present. I feel this code check is good enough.

@DaanHoogland

Copy link
Copy Markdown
Contributor

clgtm, one worry though; @anniejili Do we need to check if the volume is actually present on the pool? I.E. if the volume has been allocated before it might actually exist (even though it has the state of Allocated)

@DaanHoogland according to the volume state machine, volume will be in allocated state either as the starting state or when the operation is failed. So I dont think volume will actually present. I feel this code check is good enough.

ok @harikrishna-patnala.

@harikrishna-patnala
harikrishna-patnala requested review from DaanHoogland, nvazquez and weizhouapache and removed request for shwstppr November 14, 2023 03:58

@DaanHoogland DaanHoogland left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

CLGTM, simpel principle.

However I accept @harikrishna-patnala 's argument, it won't hurt to try if they can break it, as per the discussion here: #8202 (comment)

Comment on lines +1654 to +1663
if (toBeCreated.getState() == Volume.State.Allocated && toBeCreated.getPoolId() != null) {
toBeCreated.setPoolId(null);
if (!_volsDao.update(toBeCreated.getId(), toBeCreated)) {
throw new CloudRuntimeException(String.format("Error updating volume [%s] to clear pool Id.", toBeCreated.getId()));
}
if (s_logger.isDebugEnabled()) {
String msg = String.format("Setting pool_id to NULL for volume id=%s as it is in Allocated state", toBeCreated.getId());
s_logger.debug(msg);
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this can be moved to a separate method and tested (separately)

@yadvr

yadvr commented Nov 14, 2023

Copy link
Copy Markdown
Member

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@rohityadavcloud a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

@blueorangutan

Copy link
Copy Markdown

Packaging result [SF]: ✔️ el7 ✔️ el8 ✔️ el9 ✔️ debian ✔️ suse15. SL-JID 7755

@DaanHoogland

Copy link
Copy Markdown
Contributor

@blueorangutan test

@blueorangutan

Copy link
Copy Markdown

@DaanHoogland a [SL] Trillian-Jenkins test job (centos7 mgmt + kvm-centos7) has been kicked to run smoke tests

@anniejili

Copy link
Copy Markdown
Contributor Author

Rebased with the latest 4.18 branch.

@blueorangutan

Copy link
Copy Markdown

[SF] Trillian test result (tid-8352)
Environment: kvm-centos7 (x2), Advanced Networking with Mgmt server 7
Total time taken: 43413 seconds
Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr8202-t8352-kvm-centos7.zip
Smoke tests completed. 109 look OK, 0 have errors, 0 did not run
Only failed and skipped tests results shown below:

Test Result Time (s) Test File

@DaanHoogland

Copy link
Copy Markdown
Contributor

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@DaanHoogland a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

@blueorangutan

Copy link
Copy Markdown

Packaging result [SF]: ✔️ el7 ✔️ el8 ✔️ el9 ✔️ debian ✔️ suse15. SL-JID 7794

@DaanHoogland

Copy link
Copy Markdown
Contributor

@blueorangutan test

@blueorangutan

Copy link
Copy Markdown

@DaanHoogland a [SL] Trillian-Jenkins test job (centos7 mgmt + kvm-centos7) has been kicked to run smoke tests

@blueorangutan

Copy link
Copy Markdown

[SF] Trillian test result (tid-8373)
Environment: kvm-centos7 (x2), Advanced Networking with Mgmt server 7
Total time taken: 47393 seconds
Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr8202-t8373-kvm-centos7.zip
Smoke tests completed. 106 look OK, 3 have errors, 0 did not run
Only failed and skipped tests results shown below:

Test Result Time (s) Test File
test_02_upgrade_kubernetes_cluster Failure 560.57 test_kubernetes_clusters.py
test_08_migrate_vm Error 43.88 test_vm_life_cycle.py
test_02_redundant_VPC_default_routes Failure 370.05 test_vpc_redundant.py
test_05_rvpc_multi_tiers Failure 572.56 test_vpc_redundant.py
test_05_rvpc_multi_tiers Error 572.58 test_vpc_redundant.py

@harikrishna-patnala
harikrishna-patnala merged commit 3c7c75b into apache:4.18 Nov 21, 2023
@boring-cyborg

boring-cyborg Bot commented Nov 21, 2023

Copy link
Copy Markdown

Awesome work, congrats on your first merged pull request!

@anniejili

Copy link
Copy Markdown
Contributor Author

Thanks everyone!

@anniejili
anniejili deleted the clear_pool_id_if_volume_allocation_fails branch November 28, 2023 18:13
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.

5 participants