You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 15 Next »

Use of Locks

  • Locks in the JobScheduler prevent the execution of a job, as long as a particular lock has been acquired by one or more other jobs. Locks are available for individual jobs and for jobs in job chains. Should a job be waiting for a lock to be released (lock contention), then it will be automatically started as soon as the lock has been released.
  • For a lock you configure how many jobs could use the lock non-exclusively, i.e. in parallel.
  • A job can acquire multiple locks and can use them in exclusive or non-exclusive mode. 
    • If a lock is used non-exclusively then other jobs that use the same lock can start in parallel until the maximum number of non-exclusive jobs is reached.
    • If a job uses the lock in exclusive mode then other jobs with the same lock have to wait until the lock is released.
  • See also http://www.sos-berlin.com/doc/en/scheduler.doc/lock.xml

Example 1: Three jobs using the same lock, one of them exclusive

  • First you have to create a lock then it can be acquired by jobs.
  • For example open the folder ./live/lockExample/ in JOE.
  • We create the lock testLock


 

and three jobs job1, job2, job3 where job1 uses the testLock exclusive and the other lock non exclusive.


You can download this Example here.

We start the jobs in different orders to see what happens:

  1. job1 -> job2 -> job3
    In this case job1 holds the lock exclusively and job2 and job3 won't start until job1 is completed and will release the lock.
  2. job2 -> job3 -> job1
    In this case job2 and job3 start both because they can get hold of the lock non-exclusively. job1 wants to use the lock exclusively so it doesn't start until job2 and job3 are completed and will release the lock.
  3. job2 -> job1 -> job3
    Same behaviour as for case 2.

Example 2: Number of maximum non-exclusive jobs (useful for maintainance windows)

We assume a lock maintain with an unlimited number of non-exclusive jobs and we assume the jobs job1 and job2 to have acquired the lock maintain in non-exclusive mode.

See above how to create the lock in JOE and how to assign the lock to a job in non-exclusive mode.

Both jobs start in the same way as without the lock because they use it non-exclusively and the maximum number of non-exclusive jobs is unlimited as the lock is configured for unlimited non-exclusive use.

In this example a job chain is added with a job that modifies the maximum number of non-exclusive jobs. This job chain has two orders:

  • For one order the job sets the maximum number of non-exclusive locks to 0 (zero).
  • For the other order the job sets the maximum number of non-exclusive jobs to unlimited (2^31-1).

If the maximum number of non-exclusive jobs equals zero then no job will start that uses this lock.

Therefore with the sample you receive one order is used to to lock both jobs and another order is used to release the jobs.
If a job uses a schedule that is configured to start the job while it is locked then the job is moved to a task queue for later execution.
As soon as the job is released then all planned starts from the task queue are executed.

We assume that you have jobs that required the same resources, e.g. a database table or the same remote host for SSH jobs, and that you would assign them the same lock.
If this resource is not available for a specific time then this example shows a way how to lock these jobs.
This example is further a possible method for a planned maintainance.

You can download this Example here.

 

  • No labels