Marcosrico commented on code in PR #2515:
URL: https://github.com/apache/helix/pull/2515#discussion_r1228631420
##########
meta-client/src/main/java/org/apache/helix/metaclient/recipes/lock/DistributedSemaphore.java:
##########
@@ -75,8 +133,19 @@ public Permit acquire() {
* @param count number of permits to acquire
* @return a collection of permits
*/
- public Collection<Permit> acquire(int count) {
- throw new NotImplementedException("Not implemented yet.");
+ public synchronized Collection<Permit> acquire(int count) {
+ if (getRemainingCapacity() < count) {
+ LOG.warn("No sufficient permits available. Attempt to acquire {}
permits, but only {} permits available", count,
+ getRemainingCapacity());
+ return null;
+ } else {
+ updateAcquirePermit(count);
Review Comment:
After an offline discussion we agreed that it was necessary to implement
some sort of anti race condition that prevents two clients from modifying a
semaphore at the same time / in between processes. We came up with multiple
solutions but ultimately agreed that we would check for the available capacity
in the update call rather than having it separately.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]