Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
import java.util.concurrent.atomic.AtomicLongFieldUpdater;
import java.util.concurrent.atomic.LongAdder;
import java.util.concurrent.locks.ReentrantReadWriteLock;
Expand Down Expand Up @@ -131,7 +132,11 @@ public abstract class AbstractTopic implements Topic, TopicPolicyListener<TopicP

private static final AtomicLongFieldUpdater<AbstractTopic> RATE_LIMITED_UPDATER =
AtomicLongFieldUpdater.newUpdater(AbstractTopic.class, "publishRateLimitedTimes");
protected volatile long publishRateLimitedTimes = 0;
protected volatile long publishRateLimitedTimes = 0L;

private static final AtomicIntegerFieldUpdater<AbstractTopic> USER_CREATED_PRODUCER_COUNTER_UPDATER =
AtomicIntegerFieldUpdater.newUpdater(AbstractTopic.class, "userCreatedProducerCount");
private volatile int userCreatedProducerCount = 0;

protected volatile Optional<Long> topicEpoch = Optional.empty();
private volatile boolean hasExclusiveProducer;
Expand Down Expand Up @@ -447,14 +452,8 @@ protected boolean isProducersExceeded(Producer producer) {
return false;
}
Integer maxProducers = topicPolicies.getMaxProducersPerTopic().get();
if (maxProducers != null && maxProducers > 0 && maxProducers <= getUserCreatedProducersSize()) {
return true;
}
return false;
}

private long getUserCreatedProducersSize() {
return producers.values().stream().filter(p -> !p.isRemote()).count();
return maxProducers != null && maxProducers > 0
&& maxProducers <= USER_CREATED_PRODUCER_COUNTER_UPDATER.get(this);
}

protected void registerTopicPolicyListener() {
Expand Down Expand Up @@ -988,6 +987,8 @@ protected void internalAddProducer(Producer producer) throws BrokerServiceExcept
Producer existProducer = producers.putIfAbsent(producer.getProducerName(), producer);
if (existProducer != null) {
tryOverwriteOldProducer(existProducer, producer);
} else if (!producer.isRemote()) {
USER_CREATED_PRODUCER_COUNTER_UPDATER.incrementAndGet(this);
}
}

Expand Down Expand Up @@ -1020,6 +1021,9 @@ public void removeProducer(Producer producer) {
checkArgument(producer.getTopic() == this);

if (producers.remove(producer.getProducerName(), producer)) {
if (!producer.isRemote()) {
USER_CREATED_PRODUCER_COUNTER_UPDATER.decrementAndGet(this);
}
handleProducerRemoved(producer);
}
}
Expand Down