Skip to content
Merged
Show file tree
Hide file tree
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 @@ -41,6 +41,7 @@
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicLong;

import static org.apache.kafka.streams.processor.internals.GlobalStreamThread.State.CREATED;
import static org.apache.kafka.streams.processor.internals.GlobalStreamThread.State.DEAD;
Expand All @@ -62,6 +63,7 @@ public class GlobalStreamThread extends Thread {
private final ThreadCache cache;
private final StreamsMetricsImpl streamsMetrics;
private final ProcessorTopology topology;
private final AtomicLong cacheSize;
private volatile StreamsException startupException;
private java.util.function.Consumer<Throwable> streamsUncaughtExceptionHandler;

Expand Down Expand Up @@ -215,6 +217,7 @@ public GlobalStreamThread(final ProcessorTopology topology,
this.cache = new ThreadCache(logContext, cacheSizeBytes, this.streamsMetrics);
this.stateRestoreListener = stateRestoreListener;
this.streamsUncaughtExceptionHandler = streamsUncaughtExceptionHandler;
this.cacheSize = new AtomicLong(-1L);
}

static class StateConsumer {
Expand Down Expand Up @@ -302,6 +305,10 @@ public void run() {
boolean wipeStateStore = false;
try {
while (stillRunning()) {
final long size = cacheSize.getAndSet(-1L);
if (size != -1L) {
cache.resize(size);
}
stateConsumer.pollAndUpdate();
}
} catch (final InvalidOffsetException recoverableException) {
Expand Down Expand Up @@ -344,7 +351,7 @@ public void setUncaughtExceptionHandler(final java.util.function.Consumer<Throwa
}

public void resize(final long cacheSize) {
cache.resize(cacheSize);
this.cacheSize.set(cacheSize);
}

private StateConsumer initialize() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,11 @@ public boolean isRunning() {
private java.util.function.Consumer<Throwable> streamsUncaughtExceptionHandler;
private Runnable shutdownErrorHook;
private AtomicInteger assignmentErrorCode;
private AtomicLong cacheResizeSize;
private final ProcessingMode processingMode;
private AtomicBoolean leaveGroupRequested;


public static StreamThread create(final InternalTopologyBuilder builder,
final StreamsConfig config,
final KafkaClientSupplier clientSupplier,
Expand Down Expand Up @@ -490,6 +492,7 @@ public StreamThread(final Time time,
this.commitRatioSensor = ThreadMetrics.commitRatioSensor(threadId, streamsMetrics);
this.failedStreamThreadSensor = ClientMetrics.failedStreamThreadSensor(streamsMetrics);
this.assignmentErrorCode = assignmentErrorCode;
this.cacheResizeSize = new AtomicLong(-1L);
this.shutdownErrorHook = shutdownErrorHook;
this.streamsUncaughtExceptionHandler = streamsUncaughtExceptionHandler;
this.cacheResizer = cacheResizer;
Expand Down Expand Up @@ -575,6 +578,10 @@ boolean runLoop() {
"All clients in this app will now begin to shutdown");
mainConsumer.enforceRebalance();
}
final Long size = cacheResizeSize.getAndSet(-1L);
if (size != -1L) {
cacheResizer.accept(size);
}
runOnce();
if (nextProbingRebalanceMs.get() < time.milliseconds()) {
log.info("Triggering the followup rebalance scheduled for {} ms.", nextProbingRebalanceMs.get());
Expand Down Expand Up @@ -686,7 +693,7 @@ private void subscribeConsumer() {
}

public void resizeCache(final long size) {
cacheResizer.accept(size);
cacheResizeSize.set(size);
}

/**
Expand Down