Skip to content

Commit

Permalink
apply comments
Browse files Browse the repository at this point in the history
  • Loading branch information
aloyszhang committed Jul 26, 2022
1 parent a006c70 commit b1ea7d8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,6 @@ public class ManagedLedgerFactoryConfig {
private int numManagedLedgerWorkerThreads = Runtime.getRuntime().availableProcessors();
private int numManagedLedgerSchedulerThreads = Runtime.getRuntime().availableProcessors();

/**
* Frequency of cache eviction triggering. Default is 100 times per second.
* @Deprecated Use {@link #cacheEvictionIntervalMs} instead.
*/
@Deprecated
private double cacheEvictionFrequency = 100;

/**
* Interval of cache eviction triggering. Default is 10 ms times.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
import org.apache.pulsar.common.policies.data.EnsemblePlacementPolicyConfig;
import org.apache.pulsar.common.util.DateFormatter;
import org.apache.pulsar.common.util.FutureUtil;
import org.apache.pulsar.common.util.Runnables;
import org.apache.pulsar.metadata.api.MetadataStore;
import org.apache.pulsar.metadata.api.Stat;
import org.apache.pulsar.metadata.api.extended.MetadataStoreExtended;
Expand Down Expand Up @@ -203,13 +204,8 @@ private ManagedLedgerFactoryImpl(MetadataStoreExtended metadataStore,
.toNanos(config.getCacheEvictionTimeThresholdMillis());

long evictionTaskInterval = config.getCacheEvictionIntervalMs();
cacheEvictionExecutor.scheduleWithFixedDelay(() -> {
try {
doCacheEviction();
} catch (Throwable t) {
log.warn("Exception while performing cache eviction: {}", t.getMessage(), t);
}
}, evictionTaskInterval, evictionTaskInterval, TimeUnit.MILLISECONDS);
cacheEvictionExecutor.scheduleWithFixedDelay(Runnables.catchingAndLoggingThrowables(this::doCacheEviction),
evictionTaskInterval, evictionTaskInterval, TimeUnit.MILLISECONDS);
closed = false;

metadataStore.registerSessionListener(this::handleMetadataStoreNotification);
Expand Down Expand Up @@ -263,24 +259,6 @@ private synchronized void refreshStats() {
lastStatTimestamp = now;
}

private void cacheEvictionTask() {
double evictionFrequency = Math.max(Math.min(config.getCacheEvictionFrequency(), 1000.0), 0.001);
long waitTimeMillis = (long) (1000 / evictionFrequency);

while (!closed) {
try {
doCacheEviction();

Thread.sleep(waitTimeMillis);
} catch (InterruptedException e) {
// Factory is shutting down
return;
} catch (Throwable t) {
log.warn("Exception while performing cache eviction: {}", t.getMessage(), t);
}
}
}

private synchronized void doCacheEviction() {
long maxTimestamp = System.nanoTime() - cacheEvictionTimeThresholdNanos;

Expand Down

0 comments on commit b1ea7d8

Please sign in to comment.