ARTIFACTORY: How to solve the problem of ” Failed to acquire lock for…” errors after replication failed

Yunzong Guo
2023-03-15 10:38

Artifactory supports Repository Replication between two Artifactory instances to support development by different teams distributed over distant geographical sites.
During the artifacts synchronization process, Artifactory will first "lock" the artifact in the database and record this "lock" information into the table distributed_locks of the database. When the operation on the artifact is completed, the "lock" information will be automatically deleted.
But at this time, if the database crashes or some table locking operations occur during the running of replication, these "lock" data will be left in the table distributed_locks and can not be automatically deleted. At the same time, the log will continue to output ERROR messages such as the following:2022-11-04T01:10:12.8422 [jfrt ] [ERROR] [982710cc9799d78f] [s.d.l.s.DbLocksServiceImpl:180] [ents-event-sweeper-1] - Failed to acquire lock for: LockInfo{category='node-event-task-manager', key='maven-remote-cache/aopalliance/aopalliance/1.0/aopalliance-1.0.jar', owner='jf-001', threadId=3587, startedTime=1667524212841, threadName='metadata-operator-events-event-sweeper-1'}

2022-11-04T01:10:12.8422 [jfrt ] [ERROR] [982710cc9799d78f] [s.d.l.s.DbLocksServiceImpl:180] [ents-event-sweeper-1] - Failed to acquire lock for: LockInfo{category='node-event-task-manager', key='79fb80e7228486521156eae510de998264e6620c',

How to deal with it?

We need to delete the incorrect data in the database. 
First, we query the database by using the "key" in the logs, such as "maven-remote-cache/aopalliance/aopalliance/1.0/aopalliance-1.0.jar", "79fb80e7228486521156eae510de99826620c":select * from distributed_locks where lock_key in ('maven-remote-cache/aopalliance/aopalliance/1.0/aopalliance-1.0.jar', '79fb80e7228486521156eae510de998264e6620c');
Response, such as:

User-added image

Then delete them:delete from distributed_locks where lock_key in ('maven-remote-cache/aopalliance/aopalliance/1.0/aopalliance-1.0.jar', '79fb80e7228486521156eae510de998264e6620c');
After that, the log ERROR messages will disappear.