gortiz commented on code in PR #14847:
URL: https://github.com/apache/pinot/pull/14847#discussion_r1927167343
##########
pinot-common/src/main/java/org/apache/pinot/common/concurrency/AdjustableSemaphore.java:
##########
@@ -20,32 +20,44 @@
import com.google.common.base.Preconditions;
import java.util.concurrent.Semaphore;
+import java.util.concurrent.atomic.AtomicInteger;
/**
* A semaphore that allows adjusting the number of permits in a non-blocking
way.
*/
public class AdjustableSemaphore extends Semaphore {
- private int _totalPermits;
+ private final AtomicInteger _totalPermits;
public AdjustableSemaphore(int permits) {
super(permits);
- _totalPermits = permits;
+ _totalPermits = new AtomicInteger(permits);
}
public AdjustableSemaphore(int permits, boolean fair) {
super(permits, fair);
- _totalPermits = permits;
+ _totalPermits = new AtomicInteger(permits);
}
+ /**
+ * Sets the total number of permits to the given value without blocking.
+ */
public void setPermits(int permits) {
Preconditions.checkArgument(permits > 0, "Permits must be a positive
integer");
- if (permits < _totalPermits) {
- reducePermits(_totalPermits - permits);
- } else if (permits > _totalPermits) {
- release(permits - _totalPermits);
+ if (permits < _totalPermits.get()) {
+ reducePermits(_totalPermits.get() - permits);
+ } else if (permits > _totalPermits.get()) {
+ release(permits - _totalPermits.get());
Review Comment:
I was wrong. The issue is when a frequently written volatile is in the same
cache as a non-volatile frequently read attribute. Each writes into the
volatile will evict the cache line, so other threads reading the non-volatile
will need to read the line again
(https://medium.com/@ali.gelenler/cache-trashing-and-false-sharing-ce044d131fc0)
--
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]