[
https://issues.apache.org/jira/browse/KAFKA-3499?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15243852#comment-15243852
]
ASF GitHub Bot commented on KAFKA-3499:
---------------------------------------
GitHub user guozhangwang opened a pull request:
https://github.com/apache/kafka/pull/1229
KAFKA-3499: prevent array typed keys in KeyValueStore
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/guozhangwang/kafka K3499
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/kafka/pull/1229.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #1229
----
commit 718b8f1423d885c5bee32bacbcacf4fb78598372
Author: Guozhang Wang <[email protected]>
Date: 2016-04-15T00:26:57Z
wrap segments keys with ByteBuffer
commit 9302bc18c8fa400b1fb7d4b36f29c8f0c812785c
Author: Guozhang Wang <[email protected]>
Date: 2016-04-15T23:35:36Z
prevent array keys in key value store
----
> byte[] should not be used as Map key nor Set member
> ---------------------------------------------------
>
> Key: KAFKA-3499
> URL: https://issues.apache.org/jira/browse/KAFKA-3499
> Project: Kafka
> Issue Type: Sub-task
> Components: streams
> Reporter: josh gruenberg
> Assignee: Guozhang Wang
> Labels: user-experience
> Fix For: 0.10.0.0
>
>
> On the JVM, Array.equals and Array.hashCode do not incorporate array
> contents; they inherit Object.equals/hashCode. This implies that Collections
> that rely upon equals/hashCode (eg, HashMap/HashSet and variants) treat two
> arrays with equal contents as distinct elements.
> Many of the Kafka Streams internal classes currently use generic HashMaps and
> Sets to manage caches and invalidation status. For example,
> RocksDBStore.cacheDirtyKeys is a HashSet<K>. Then, in RocksDBWindowStore, the
> Elements are constructed as RocksDBStore<byte[], byte[]>.
> Similarly, the MemoryLRUCache<K, RocksDBCacheEntry> internally holds a
> LinkedHashMap<K,V> map, and a HashSet<K> keys, and these end up holding
> byte[] keys. Finally, user-code may attempt to use any of these provided
> types with byte[], with undesirable results.
> Keys that are byte-arrays should be wrapped in a type that incorporates the
> content in their computation of equals/hashCode. java.nio.ByteBuffer is one
> such type that could be used, but a purpose-built immutable class would
> likely be a better solution.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)