-
Notifications
You must be signed in to change notification settings - Fork 15k
KAFKA-19434: Startup state stores initialization #20749
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
bbejeck
merged 27 commits into
apache:trunk
from
eduwercamacaro:refactor-startup-store-initialization
Feb 20, 2026
Merged
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
23ce8e8
refactor startup state stores initialization
eduwercamacaro 2bfc943
merge trunk
eduwercamacaro 8dc87f2
Remove rocksdb temp files
eduwercamacaro 2b1e77b
Merge branch 'trunk' into refactor-startup-store-initialization
eduwercamacaro 0e9e40b
Fix merge conflicts
eduwercamacaro 13c9e91
Replace RocksDBStore#openDB to StateStore#preInit
eduwercamacaro 050e725
Remove unused classes
eduwercamacaro a81eaed
Discover startup stores during topology initialization
eduwercamacaro 4ad6553
Allow closing state stores during preInit phase
eduwercamacaro fd93623
Add a new method that register startup stores in a ProcessorStateManager
eduwercamacaro 233dccf
Merge branch 'trunk' into refactor-startup-store-initialization
eduwercamacaro abac041
Merge branch 'trunk' into refactor-startup-store-initialization
eduwercamacaro f8febe7
Set a log prefix for startup stores during initialization
eduwercamacaro 49e786f
Properly assign a StreamThread to a ProcessorStateManager created dur…
eduwercamacaro b4cb0ff
Implement preInit method for InMemory stores
eduwercamacaro 7b614ea
Revert "Implement preInit method for InMemory stores"
eduwercamacaro cd0dc0a
wip
eduwercamacaro 6078803
Refactor: Open and close state stores during pre-existing stores init…
eduwercamacaro 97dea13
Refacttor: remove startup stores from state manager
eduwercamacaro cc8d4f1
Revert changes in StandbyTaskCreator
eduwercamacaro 60d8aa9
rename methods
eduwercamacaro 65ffd3f
Fix unit tests
eduwercamacaro 525b280
Remove unused method
eduwercamacaro 191e9de
Merge branch 'trunk' into refactor-startup-store-initialization
eduwercamacaro 2c0bb94
streams: simplify startup state handling and locking
eduwercamacaro a8efdea
Merge branch 'trunk' into refactor-startup-store-initialization
eduwercamacaro a395b3d
- Rename unit tests related to startup states
eduwercamacaro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -49,6 +49,7 @@ | |
| import java.util.Map; | ||
| import java.util.OptionalLong; | ||
| import java.util.Set; | ||
| import java.util.concurrent.atomic.AtomicBoolean; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| import static java.lang.String.format; | ||
|
|
@@ -176,6 +177,7 @@ public String toString() { | |
|
|
||
| // must be maintained in topological order | ||
| private final FixedOrderMap<String, StateStoreMetadata> stores = new FixedOrderMap<>(); | ||
| private final Map<String, StateStore> startupStores = new HashMap<>(); | ||
| private final FixedOrderMap<String, StateStore> globalStores = new FixedOrderMap<>(); | ||
|
|
||
| private final File baseDir; | ||
|
|
@@ -185,6 +187,7 @@ public String toString() { | |
| private TaskType taskType; | ||
| private Logger log; | ||
| private Task.State taskState; | ||
| private final AtomicBoolean startupState; | ||
|
|
||
| public static String storeChangelogTopic(final String prefix, final String storeName, final String namedTopology) { | ||
| if (namedTopology == null) { | ||
|
|
@@ -205,7 +208,8 @@ public ProcessorStateManager(final TaskId taskId, | |
| final ChangelogRegister changelogReader, | ||
| final Map<String, String> storeToChangelogTopic, | ||
| final Collection<TopicPartition> sourcePartitions, | ||
| final boolean stateUpdaterEnabled) throws ProcessorStateException { | ||
| final boolean stateUpdaterEnabled, | ||
| final boolean startupState) throws ProcessorStateException { | ||
bbejeck marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| this.storeToChangelogTopic = storeToChangelogTopic; | ||
| this.log = logContext.logger(ProcessorStateManager.class); | ||
| this.logPrefix = logContext.logPrefix(); | ||
|
|
@@ -220,6 +224,22 @@ public ProcessorStateManager(final TaskId taskId, | |
| this.checkpointFile = new OffsetCheckpoint(stateDirectory.checkpointFileFor(taskId)); | ||
|
|
||
| log.debug("Created state store manager for task {}", taskId); | ||
| this.startupState = new AtomicBoolean(startupState); | ||
|
||
| } | ||
|
|
||
| /** | ||
| * @throws ProcessorStateException if the task directory does not exist and could not be created | ||
| */ | ||
| public ProcessorStateManager(final TaskId taskId, | ||
| final TaskType taskType, | ||
| final boolean eosEnabled, | ||
| final LogContext logContext, | ||
| final StateDirectory stateDirectory, | ||
| final ChangelogRegister changelogReader, | ||
| final Map<String, String> storeToChangelogTopic, | ||
| final Collection<TopicPartition> sourcePartitions, | ||
| final boolean stateUpdaterEnabled) throws ProcessorStateException { | ||
| this(taskId, taskType, eosEnabled, logContext, stateDirectory, changelogReader, storeToChangelogTopic, sourcePartitions, stateUpdaterEnabled, false); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -234,7 +254,7 @@ static ProcessorStateManager createStartupTaskStateManager(final TaskId taskId, | |
| final Map<String, String> storeToChangelogTopic, | ||
| final Set<TopicPartition> sourcePartitions, | ||
| final boolean stateUpdaterEnabled) { | ||
| return new ProcessorStateManager(taskId, TaskType.STANDBY, eosEnabled, logContext, stateDirectory, null, storeToChangelogTopic, sourcePartitions, stateUpdaterEnabled); | ||
| return new ProcessorStateManager(taskId, TaskType.STANDBY, eosEnabled, logContext, stateDirectory, null, storeToChangelogTopic, sourcePartitions, stateUpdaterEnabled, true); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -255,6 +275,10 @@ void assignToStreamThread(final LogContext logContext, | |
| this.sourcePartitions.addAll(sourcePartitions); | ||
| } | ||
|
|
||
| void reuseState() { | ||
bbejeck marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| startupState.set(false); | ||
| } | ||
|
|
||
| void registerStateStores(final List<StateStore> allStores, final InternalProcessorContext<?, ?> processorContext) { | ||
| processorContext.uninitialize(); | ||
| for (final StateStore store : allStores) { | ||
|
|
@@ -263,7 +287,13 @@ void registerStateStores(final List<StateStore> allStores, final InternalProcess | |
| maybeRegisterStoreWithChangelogReader(store.name()); | ||
| } | ||
| } else { | ||
| store.init(processorContext, store); | ||
| if (startupState.get()) { | ||
| store.preInit(processorContext); | ||
| startupStores.put(store.name(), store); | ||
| } else { | ||
| store.init(processorContext, store); | ||
| startupStores.remove(store.name()); | ||
| } | ||
| } | ||
| log.trace("Registered state store {}", store.name()); | ||
| } | ||
|
|
@@ -649,9 +679,19 @@ else if (exception instanceof StreamsException) | |
| } | ||
| } | ||
|
|
||
|
|
||
| stores.clear(); | ||
| } | ||
|
|
||
| if (!startupStores.isEmpty()) { | ||
| for (final Map.Entry<String, StateStore> entry : startupStores.entrySet()) { | ||
| final StateStore store = entry.getValue(); | ||
| store.close(); | ||
| } | ||
| startupStores.clear(); | ||
| } | ||
|
|
||
|
|
||
| if (firstException != null) { | ||
| throw firstException; | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.