Best way to handle curator SUSPEND state from ConnectionStateListener

2.7k views Asked by At

I want to ask a question about handling SUSPEND state.

Here is the background:

I am using curator/zk to as a task coordinator for a list of concurrent running jobs. For every minute, every worker (each work run on a separate VM) try to acquire a task (lock) from zk by calling:

lock = new InterProcessSemaphoreMutex(zkClient, task); 
boolean hasLock = false;
hasLock = lock.acquire(1, TimeUnit.SECONDS);

If the work get the lock, it will do the task.

The class which is responsible for retriever lock/task implement ConnectionStateListener interface. And below is the currently implementation:

  • RECONNECT: do nothing, since worker will try to acquire lock regardless the ZK connection status.

  • LOST: release the lock, since the connect is lost.

  • SUSPEND: ??????

My question is about SUSPEND state, should I release the lock when enter SUSPEND (basically, treat as lost) or do something else?

What is the best practice to handle SUSPEND state?

Thanks,

1

There are 1 answers

0
David Brabant On

I guess you have seen the comment at the end of this page.

It is strongly recommended that you add a ConnectionStateListener and watch for SUSPENDED and LOST state changes. If a SUSPENDED state is reported you cannot be certain that you still hold the lock unless you subsequently receive a RECONNECTED state. If a LOST state is reported it is certain that you no longer hold the lock.

I interpret this as: you hold the lock until you receive a RECONNECTED state, unless your connection is LOST and the lock is released.