HDP upgrade failed on Finalize Upgrade step - Error Finalizing HDP upgrade Failed on: Save Cluster State
Issue: While performing HDP upgrade it failed on last step.
Error Finalizing HDP upgrade Failed on: Save Cluster State
Sample screenshot is attached below -

Many times error might change, and in my case below was the error -
Begin finalizing the upgrade of cluster TEST_DEV to version 2.5.0.0-1245
The following 7 host(s) have not been upgraded to version 2.5.0.0-1245. Please install and upgrade the Stack Version on those hosts and try again.
Hosts: host1.example.com, host2.example.com, host3.example.com, host4.example.com, host5.example.com, host6.example.com, host7.example.com
Root Cause: When check in ambari DB for "host_version" table we were able to see the 7 hosts were pointing to state as INSTALLED as shown below -

The repo_version_id=151 should be in "CURRENT" state which was not the case. It was in INSTALLED state.
Solution:
1. First set the previous repo_version_id ie 101 to INSTALLED state using below command -
mysql> update host_version set state='INSTALLED' where repo_version_id='101';

2. Now modify the hosts which was having latest repo_version_id [ie. 151] to CURRENT state -
mysql> update host_version set state='CURRENT' where repo_version_id='151';

3. Restarted ambari server and click on "Retry" on host upgrade screen after which upgrade was successfully completed.




