Skip to content

KAFKA-8324: Add close() method to RocksDBConfigSetter#6697

Merged
bbejeck merged 9 commits intoapache:trunkfrom
ableegoldman:CloseRocksObjects
May 9, 2019
Merged

KAFKA-8324: Add close() method to RocksDBConfigSetter#6697
bbejeck merged 9 commits intoapache:trunkfrom
ableegoldman:CloseRocksObjects

Conversation

@ableegoldman
Copy link
Copy Markdown
Member

Following KIP-453, this PR adds a default close() method to the RocksDBConfigSetter interface and calls it when closing a store.

@ableegoldman
Copy link
Copy Markdown
Member Author

Copy link
Copy Markdown
Member

@cadonna cadonna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ableegoldman
LGTM, mainly JavaDocs comments.

*
* @param storeName the name of the store being configured
* @param options the Rocks DB options
\ */
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a \ too much, isn't it?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack

* here to avoid leaking off-heap memory.
* Objects to be closed can be saved by the user or retrieved back from options using its getter methods.
*
* Example objects needing to be closed include Filter and Cache
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use the full qualified name of Filter and Cache. If anybody wants to look them up it is easier. Additionally, I would enclose it into {@code ...}.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same... @link > @close for this case.

* @param storeName the name of the store being configured
* @param options the Rocks DB options
\ */
default void close(final String storeName, final Options options) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there plans to remove the default implementation in the next major release?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a tricky question... The problem is that there's no way to signal ahead of time that you should override the method to avoid breakage when we remove default (unlike when you deprecate a method, which indicates you should make a change ahead of the breakage).

So, whenever we do make the change, it will be a breaking one.

If we think it's very likely that implementers would have some objects that need to be closed, and thus are leaking memory today, maybe we should actually just not default it at all, so they fix their memory leaks asap.

Conversely, if we think it's unlikely that the average implementer is going to leak memory, there's no reason we shouldn't just leave it defaulted forever.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need the default implementation in any case until the next major release not to break existing code. Afterwards, I would be in favour of removing the default implementation, because then there is a bigger chance that existing memory leakages are found and future leakages are avoided.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm. On the one hand I'd guess not that many users in total are leaking memory here, but suspect that those who are advanced enough to be implementing ConfigSetter may likely be...

I'd agree we should remove the default in the next major release though, especially once we upgrade Rocks as some of the API changes since our current version effectively force creating more/new RocksObjects when setting options.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth to add a WARN log in the default implementation, telling users, that the default will be removed in 3.0.0 and they should overwrite it?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call


/**
* This method will be called when the store is closed and should be used to close any user-constructed objects
* that inherit from RocksObject. Any such object created with new in setConfig should have close called on it
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RocksObject -> {@code RocksObject}
setConfig -> {@link #setConfig}
close -> {@code close}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Actually, I think @link would be preferable in all three cases, but they need to be properly qualified.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At first, I also thought links would be good, but then I thought that we also need to maintain those links to JavaDocs outside of Kafka? Do we have any policy about that?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea. I would assume that Gradle would take care of downloading the docs jar of the dependency and linking to the class appropriately. I think we'd actually have to build the javadoc to see if it works or not.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack, updated the javadocs -- can you take a quick look and see if everything seems reasonable?

*/
void setConfig(final String storeName, final Options options, final Map<String, Object> configs);

/**
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a short one line description that will be shown in the Method Summary section of the JavaDocs?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack

Copy link
Copy Markdown
Contributor

@vvcephei vvcephei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, pending ongoing discussions. Thanks!


/**
* This method will be called when the store is closed and should be used to close any user-constructed objects
* that inherit from RocksObject. Any such object created with new in setConfig should have close called on it
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Actually, I think @link would be preferable in all three cases, but they need to be properly qualified.

* here to avoid leaking off-heap memory.
* Objects to be closed can be saved by the user or retrieved back from options using its getter methods.
*
* Example objects needing to be closed include Filter and Cache
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same... @link > @close for this case.

* @param storeName the name of the store being configured
* @param options the Rocks DB options
\ */
default void close(final String storeName, final Options options) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a tricky question... The problem is that there's no way to signal ahead of time that you should override the method to avoid breakage when we remove default (unlike when you deprecate a method, which indicates you should make a change ahead of the breakage).

So, whenever we do make the change, it will be a breaking one.

If we think it's very likely that implementers would have some objects that need to be closed, and thus are leaking memory today, maybe we should actually just not default it at all, so they fix their memory leaks asap.

Conversely, if we think it's unlikely that the average implementer is going to leak memory, there's no reason we shouldn't just leave it defaulted forever.

Comment thread streams/src/main/java/org/apache/kafka/streams/state/RocksDBConfigSetter.java Outdated
void setConfig(final String storeName, final Options options, final Map<String, Object> configs);

/**
* This method should close any user-constructed objects that inherit from {@code org.rocksdb.RocksObject}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather write the one line description in imperative.

Close any user-constructed objects that inherit from {@code org.rocksdb.RocksObject}.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack

/**
* This method should close any user-constructed objects that inherit from {@code org.rocksdb.RocksObject}
*
* Any such object created with @{code new} in {@link #setConfig} should have {@code close} called on it here to
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And then here

Any object created with @{code new} in {@link #setConfig} and that inherits from {@code org.rocksdb.RocksObject} should have {@code close()} called on it here to

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good to me. Thanks for reviewing @cadonna !

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use @link and also link to should have {@link RocksObject#close() close()} called

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack

cadonna and others added 2 commits May 8, 2019 13:59
Co-Authored-By: ableegoldman <ableegoldman@gmail.com>
@mjsax mjsax added the streams label May 8, 2019

/**
* This method should close any user-constructed objects that inherit from {@code org.rocksdb.RocksObject}
*
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: insert <p>

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need a closing

right? My IDE is inserting it automatically

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. My IDE does it, too... But single <p> is sufficient -- it's not strict HTML, but JavaDoc markup that looks like HTML

/**
* This method should close any user-constructed objects that inherit from {@code org.rocksdb.RocksObject}
*
* Any such object created with @{code new} in {@link #setConfig} should have {@code close} called on it here to
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use @link and also link to should have {@link RocksObject#close() close()} called

* Any such object created with @{code new} in {@link #setConfig} should have {@code close} called on it here to
* avoid leaking off-heap memory. Objects to be closed can be saved by the user or retrieved back from
* {@code options} using its getter methods.
*
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: insert <p>

* avoid leaking off-heap memory. Objects to be closed can be saved by the user or retrieved back from
* {@code options} using its getter methods.
*
* Example objects needing to be closed include {@code org.rocksdb.Filter} and {@code org.rocksdb.Cache}.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: as above, use @link

* Example objects needing to be closed include {@code org.rocksdb.Filter} and {@code org.rocksdb.Cache}.
*
* @param storeName the name of the store being configured
* @param options the Rocks DB options
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit RocksDB without space

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whoops, that was just copied from above. I'll fix it in #setConfig too

* @param storeName the name of the store being configured
* @param options the Rocks DB options
\ */
default void close(final String storeName, final Options options) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth to add a WARN log in the default implementation, telling users, that the default will be removed in 3.0.0 and they should overwrite it?

Comment thread streams/src/main/java/org/apache/kafka/streams/state/RocksDBConfigSetter.java Outdated
* Close any user-constructed objects that inherit from {@link org.rocksdb.RocksObject RocksObject}.
* <p>
* Any object created with @{code new} in {@link RocksDBConfigSetter#setConfig setConfig()} and that inherits
* from {@link org.rocksdb.RocksObject RocksObject} should have {@link org.rocksdb.RocksObject#close() close()}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for bringing this up again. I generated the JavaDocs with ./gradlew aggregatedJavadoc and there are no links generated for RocksObject and any other class outside Kafka. What we get is a non-fully qualified name in @code font, i.e., RocksObject. I would at least ensure that the fully-qualified name is displayed. See also the other occurrences of links to classes outside Kafka.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, thanks for actually checking here...I meant to but "it worked in my IDE"...

Agreed that a fully qualified name here is important if we can't properly link though, I'll change these up yet again

ableegoldman and others added 2 commits May 9, 2019 11:25
Co-Authored-By: cadonna <bruno@confluent.io>
Copy link
Copy Markdown
Member

@cadonna cadonna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ableegoldman

@ableegoldman
Copy link
Copy Markdown
Member Author

Thanks everyone for helping to straighten out the javadocs -- the KIP is now accepted so if everything looks sorted we can merge this when the build passes

Copy link
Copy Markdown
Contributor

@guozhangwang guozhangwang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. We can merge it once builds are green.

@bbejeck bbejeck merged commit b2826c6 into apache:trunk May 9, 2019
@bbejeck
Copy link
Copy Markdown
Member

bbejeck commented May 9, 2019

Merged #6697 into trunk.

@bbejeck
Copy link
Copy Markdown
Member

bbejeck commented May 9, 2019

Thanks @ableegoldman!

omkreddy added a commit to confluentinc/kafka that referenced this pull request May 13, 2019
…es-14-May

* AK_REPO/trunk: (24 commits)
  KAFKA-7321: Add a Maximum Log Compaction Lag (KIP-354) (apache#6009)
  KAFKA-8335; Clean empty batches when sequence numbers are reused (apache#6715)
  KAFKA-6455: Session Aggregation should use window-end-time as record timestamp (apache#6645)
  KAFKA-6521: Use timestamped stores for KTables (apache#6667)
  [MINOR] Consolidate in-memory/rocksdb unit tests for window & session store (apache#6677)
  MINOR: Include StickyAssignor in system tests (apache#5223)
  KAFKA-7633: Allow Kafka Connect to access internal topics without cluster ACLs (apache#5918)
  MINOR: Align KTableAgg and KTableReduce (apache#6712)
  MINOR: Fix code section formatting in TROGDOR.md (apache#6720)
  MINOR: Remove unnecessary OptionParser#accepts method call from PreferredReplicaLeaderElectionCommand (apache#6710)
  KAFKA-8352 : Fix Connect System test failure 404 Not Found (apache#6713)
  KAFKA-8348: Fix KafkaStreams JavaDocs (apache#6707)
  MINOR: Add missing option for running vagrant-up.sh with AWS to vagrant/README.md
  KAFKA-8344; Fix vagrant-up.sh to work with AWS properly
  MINOR: docs typo in '--zookeeper myhost:2181--execute'
  MINOR: Remove header and key/value converter config value logging (apache#6660)
  KAFKA-8231: Expansion of ConnectClusterState interface (apache#6584)
  KAFKA-8324: Add close() method to RocksDBConfigSetter (apache#6697)
  KAFKA-6789; Handle retriable group errors in AdminClient API (apache#5578)
  KAFKA-8332: Refactor ImplicitLinkedHashSet to avoid losing ordering when converting to Scala
  ...
pengxiaolong pushed a commit to pengxiaolong/kafka that referenced this pull request Jun 14, 2019
Following KIP-453, this PR adds a default close() method to the RocksDBConfigSetter interface and calls it when closing a store.

Guozhang Wang <wangguoz@gmail.com>, Matthias J. Sax <mjsax@apache.org>,  John Roesler <john@confluent.io>, Bruno Cadonna <bruno@confluent.io>
@mjsax mjsax added the kip Requires or implements a KIP label Jun 12, 2020
@ableegoldman ableegoldman deleted the CloseRocksObjects branch June 26, 2020 22:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kip Requires or implements a KIP streams

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants