ARTIFACTORY: How to resolve metadata migration issues after upgrade due to sha256 values missing for artifacts

Shivani Budhodi
2022-09-14 15:34

Overview:

Artifactory natively supports sha-256 and when a file is deployed to any repository, the sha-256 checksum is calculated by Artifactory and it is maintained in the database. Artifactory 5.5 implements a database schema change to natively support SHA-256 checksums. 

There may be some situations where Artifactory was been upgraded multiple times to different 6.x versions which have sha-256 compatibility, however, in certain cases, there could be a few artifacts that still has no sha-256 calculated as it was deployed on Artifactory when running on a version below 5.5

When using Artifactory from below 5.5 versions, while upgrading to the latest versions of 7.x, there is a possibility that there could be some artifacts that might not be having a sha-256 associated with it. This indicates that the sha-256 were not calculated for the specific artifacts nor the migration for sha-256 is performed 

Hence, after upgrading to the 7.x version, it is possible to encounter the below error which indicates that sha-256 entry is not available for this specific artifact in the database.java.lang.IllegalStateException: Failed executing api/v1/packages/gav%3A%2F%2Forg.maven.testr%3Ajunit, with response code: HTTP/1.1 500 Internal Server Error and response message: {"cause":"Internal error while processing request","message":"Error patching package with id: (gav://org.maven.test:junit): did not find matching file in db after insert attempt"}
Due to this uncalculated SHA-256 checksum following warning can be observed in the UI during migration:
 

User-added image
Steps to debug the error:

Step 1: Firstly, check if any artifacts are present in the database without SHA-256 value.

For this run the following query in the database in order to know how many artifacts are present without SHA-256 value.

Queries:

$ select count(*) as “Nodes: No-SHA256” from nodes where node_type=1 and sha256 is NULL;
$ select count(*) as “Binaries: No-SHA256" from binaries where sha256 is NULL; 

If the output is not zero, that means there are artifacts without SHA-256 checksum calculated in the database.

Step 2: Hence, we need to perform a sha-256 migration by adding the below parameters mentioned in the JFROG_HOME/artifactory/var/etc/artifactory/artifactory.system.properties 
file on each node of your Artifactory instance.            
       ##SHA2 Migration block
artifactory.sha2.migration.job.enabled=true
artifactory.sha2.migration.job.queue.workers=5

Perform rolling restart of Artifactory after updating the artifactory.system.properties file.

By adding the above attributes to artifactory.system.properties, SHA-256 value will be generated for each artifact for which it is currently not having an entry on the database. 

Once the migration is completed, we will be able to view the packages page on the UI without any warnings and the error message observed on the logs should be eliminated.

Note: Post SHA256 Migration, it is recommended to remove all SHA256 related system properties after the migration has completed and perform a restart.