Class ElasticsearchLockProvider

java.lang.Object
net.javacrumbs.shedlock.provider.elasticsearch8.ElasticsearchLockProvider
All Implemented Interfaces:
LockProvider

public class ElasticsearchLockProvider extends Object implements LockProvider

It uses a collection that contains documents like this:

 {
    "name" : "lock name",
    "lockUntil" :  {
      "type":   "date",
      "format": "epoch_millis"
    },
    "lockedAt" : {
      "type":   "date",
      "format": "epoch_millis"
    }:
    "lockedBy" : "hostname"
 }
 

lockedAt and lockedBy are just for troubleshooting and are not read by the code

  1. Attempts to insert a new lock record. As an optimization, we keep in-memory track of created lock records. If the record has been inserted, returns lock.
  2. We will try to update lock record using filter _id == name AND lock_until <= now
  3. If the update succeeded (1 updated document), we have the lock. If the update failed (0 updated documents) somebody else holds the lock
  4. When unlocking, lock_until is set to now.
  • Constructor Details

    • ElasticsearchLockProvider

      public ElasticsearchLockProvider(co.elastic.clients.elasticsearch.ElasticsearchClient client)
  • Method Details