ARTIFACTORY: How does the “Max Unique Snapshots” parameter work in Artifactory?

Fadi Rouhana
2022-09-12 09:58

Working with snapshots is a standard development practice, however, depending on the number of snapshots that are saved, this can use up large quantities of disk space.

To specify the maximum number of snapshots that may be stored, in the Administration module, select the Repositories and click the repository whose settings you want to edit.

In the Basic settings, check Handle Snapshots and then set the Max Unique Snapshots field. This value is zero by default, which means that all snapshots are saved.

User-added imagePackage Types Supported for Max Unique Snapshots

Artifactory supports the "Max Unique Snapshots" tag for the following package types:

  • Maven
  • NuGet
  • Gradle
  • Ivy
  • Docker (“Max Unique Tags”)
  • SBT

How does this feature work?

To demonstrate how this feature works, let’s take an example Maven snapshots repository with "Max Unique Snapshots" set to 2. In this repository, we have already deployed 2 Maven snapshots, which has resulted in the following structure under the Maven snapshots repository:
 
User-added image

As seen above, when you deploy a snapshot, for example, a timestamp of the deployment will be appended to the file name in addition to the version number.

At this point, we have reached the "Max Unique Snapshots" limit so for any new snapshot deployed, the cleanup should be triggered. Therefore, we have redeployed another snapshot of the artifact that was deployed according to the previous naming, with "-3" applied to its name to indicate that this is the third version of the artifact:
 
User-added image
 

This is where "Max Unique Snapshots" comes into the picture, as the first version of the artifact was deleted as part of the cleanup process, resulting in the following:

User-added image

Finally, we can see that the repository contains only the second and third versions of the snapshot as the first version was removed due to the "Max Unique Snapshots" policy set for the repository.

This can also be monitored via the
$JFROG_HOME/artifactory/var/log/artifactory-service.log file, as seen below:2022-08-15T06:03:33.495Z [jfrt ] [INFO ] [69f57c5982eefe5d] [egrationCleanupServiceImpl:214] [art-exec-42829      ] - Removed old unique snapshot 'org/eclipse/jetty/jetty-ajp/3.1-SNAPSHOT/jetty-ajp-3.1-20220815.055110-1.jar'.
2022-08-15T06:03:33.504Z [jfrt ] [INFO ] [69f57c5982eefe5d] [egrationCleanupServiceImpl:214] [art-exec-42829      ] - Removed old unique snapshot 'org/eclipse/jetty/jetty-ajp/3.1-SNAPSHOT/jetty-ajp-3.1-20220815.055110-1.pom'.

Note:
To avoid issues of concurrency, Artifactory requires that you store a minimum of 2 unique snapshots.

Redundant snapshots are not deleted immediately:

Every time you deploy a snapshot, Artifactory will check the value Max Unique Snapshots for the repository, and if exceeded will mark any excess old snapshots for deletion. Then, every 5 minutes, Artifactory runs a background process that deletes those oldest snapshots that have been marked. For example, if you set Max Unique Snapshots to 5 and deploy a sixth and seventh snapshot to the repository, then the next time the background process runs, it will delete the two oldest snapshots.