user3019299
user3019299

Reputation: 199

Apache Curator lock path

We know how to create a distributed shared lock using Apache Curator:

InterProcessMutex lock = new InterProcessMutex(client,"/my/lock");

For the above code, I have two questions:

1: The second parameter is the path to lock(znode), so is this lock znode created by this period of code automatically, or we need to create it manually before?

2: If it is created by "InterProcessMutex", what if this lock znode has been created by other instances already? Does it throw any "znode exsting" exception? If it doesn't throw any exception, what happened, create a duplicate znode?

Upvotes: 0

Views: 941

Answers (1)

Randgalt
Randgalt

Reputation: 2956

For 1 - yes, Curator creates the path (and parents if needed) for you.

For 2 - If other instances allocate an InterProcessMutex with that path there is no issue. It's all handled internally. Curator creates the paths if needed. Think of the path as a "lock id".

Dislaimer: I'm the main author of Curator

Upvotes: 3

Related Questions