code: public int tryAcquireReplicaSyncPermits(int requestedPermits) {
          assert requestedPermits > 0 : "Invalid permits: " + requestedPermits;
  
          int permits = requestedPermits;
          while (permits > 0 && !replicaSyncSemaphore.tryAcquire(permits)) {
              permits--;
          }
  
          if (permits > 0 && logger.isFinestEnabled()) {
              logger.finest("Acquired " + permits + " replica sync permits, requested permits was " + requestedPermits
                      + ". Remaining permits: " + replicaSyncSemaphore.availablePermits());
          }
          return permits;
      }
docs: Tries to acquire requested permits. Less than requested permits may be acquired,
  if insufficient permits are available. Number of actually acquired permits will be
  returned to the caller. Acquired permits will be in the range of {@code [0, requestedPermits]}.
  
  @param requestedPermits number of requested permits
  @return number of actually acquired permits.