[infinispan-dev] Creating ByteArrayKey to solve client/server hashing differences in HotRod

galder at redhat.com galder at redhat.com
Thu Jun 10 07:08:40 EDT 2010


Hi all,

Re: https://jira.jboss.org/browse/ISPN-491

It's apparent that client and server were not calculating hashcode on the same thing. We don't want to force clients to do hash on Java classes cos that would make clients language independent and we can't use byte[] keys in the cache due to equality issues (array equality is based on reference, not Arrays.equals). So, we're forced to create a ByteArrayKey class in core/ to basically mimic what HotRod's CacheKey does in a more generic way. Diablo-D3 suggested using nio.ByteBuffer to wrap the key around, but this sounds like a heavy handed approach for simply having byte array keys that compare as expected, i.e. BB class brings in extra information such as position, limit...etc that has no use and would only take memory space.

We'll modify MurmurHash2.hash(Object o) so that if a ByteArrayKey is passed, it takes the underlying byte[] and calculates the hash on that. This way we'll make sure that both clients and servers hash on the same thing.

However, I think the long term goal should be https://jira.jboss.org/browse/ISPN-492. If we had underlying maps that did array equality based on contents, we would not have these problems and would not need for auxiliary classes.

Cheers,
--
Galder Zamarreño
Sr. Software Engineer
Infinispan, JBoss Cache



More information about the infinispan-dev mailing list