KAFKA-20287 : Fix CF handle leaks#21751
Open
muralibasani wants to merge 1 commit intoapache:trunkfrom
Open
Conversation
muralibasani
commented
Mar 13, 2026
| throw new ProcessorStateException(fatalMessage, fatal); | ||
| } catch (final RocksDBException e) { | ||
| throw new ProcessorStateException("Error opening store " + name, e); | ||
| openRocksDB(dbOptions, columnFamilyOptions); |
Contributor
Author
There was a problem hiding this comment.
This method internally calls createColumnFamilies() or mergeColumnFamilyHandleLists() which might fail
muralibasani
commented
Mar 13, 2026
| success = true; | ||
| } finally { | ||
| if (!success) { | ||
| closeNativeResources(); |
Contributor
Author
There was a problem hiding this comment.
if openRocksDB() or cfAccessor.open() fail
muralibasani
commented
Mar 13, 2026
| noTimestampColumnFamily.close(); | ||
| boolean success = false; | ||
| try { | ||
| try (final RocksIterator noTimestampsIter = db.newIterator(noTimestampColumnFamily)) { |
Contributor
Author
There was a problem hiding this comment.
updating with try-resources
muralibasani
commented
Mar 13, 2026
| boolean success = false; | ||
| try { | ||
| // Check if default CF has data (plain store upgrade) | ||
| try (final RocksIterator defaultIter = db.newIterator(defaultCf)) { |
Contributor
Author
There was a problem hiding this comment.
also updating with try-with resources
muralibasani
commented
Mar 13, 2026
| boolean success = false; | ||
| try { | ||
| // verify and close empty Default ColumnFamily | ||
| try (final RocksIterator defaultIter = db.newIterator(columnFamilies.get(0))) { |
Contributor
Author
There was a problem hiding this comment.
updating here as well in the same way try with resources
muralibasani
commented
Mar 13, 2026
| noHeadersColumnFamily.close(); | ||
| boolean success = false; | ||
| try { | ||
| try (final RocksIterator noHeadersIter = db.newIterator(noHeadersColumnFamily)) { |
Contributor
Author
There was a problem hiding this comment.
updating here with try-with resources
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
RocksDBStore.java — openRocksDB() base method: Added finally block after RocksDB.open() to close all CF handles and db if createColumnFamilies() or mergeColumnFamilyHandleLists() fails.
RocksDBStore.java — openDB(): Added finally block with closeNativeResources() to close all partially-initialized native resources if openRocksDB() or cfAccessor.open() fails.
RocksDBTimestampedStore.java: Changed RocksIterator from manual close() to try-with-resources, and added finally block to close all CF handles if an exception occurs before the accessor takes ownership.
RocksDBMigratingSessionStoreWithHeaders.java: Same as above — try-with-resources for RocksIterator and finally block for CF handle cleanup on failure.
RocksDBTimestampedStoreWithHeaders.java — openFromDefaultStore(): Added finally block to close all CF handles if an exception occurs before the accessor takes ownership.
RocksDBTimestampedStoreWithHeaders.java — openFromTimestampedStore(): Replaced manual per-handle close() calls (which missed columnFamilies.get(3)) with a single finally block that loops over all handles on failure.