[infinispan-issues] [JBoss JIRA] Commented: (ISPN-809) CassandraCacheStore needs special handling of array type keys

Jonas Lasson (JIRA) jira-events at lists.jboss.org
Tue Nov 30 09:58:11 EST 2010


    [ https://jira.jboss.org/browse/ISPN-809?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12566228#comment-12566228 ] 

Jonas Lasson commented on ISPN-809:
-----------------------------------

Ideally it would be good to get an extendable way of determining identities for different types of objects instead of just defaulting to .toString() (which works excellently for string based keys).

I'd suggest creating an interface like ICassandraIdentityProvider { String getIdentityKey( Object o ) } which would return null if it did not know how to produce an identity.

Then configure the cache store with a list of classnames that implements the above interface which will consulted in order until a provider returns a non null value. If all returns null, do toString.

Config:
<property name="identityProviders" value="com.awesome.CompanySpecificKeyProviders,com.awesome.ThirdPartyKeyProviders" />

Alternative /MEFA-INF/services/ lookup.

> CassandraCacheStore needs special handling of array type keys
> -------------------------------------------------------------
>
>                 Key: ISPN-809
>                 URL: https://jira.jboss.org/browse/ISPN-809
>             Project: Infinispan
>          Issue Type: Bug
>          Components: Loaders and Stores
>    Affects Versions: 4.2.0.CR2
>            Reporter: Jonas Lasson
>            Assignee: Tristan Tarrant
>            Priority: Critical
>             Fix For: 4.2.0.CR3
>
>
> Currently the Cassandra store is creating CassandraKeys based on the keys .toString method, see below:
> 	private String hashKey(Object key) {
> 		return entryKeyPrefix + key.toString();
> 	}
> When HotRod server is used the key will be a ByteArrayKey, which has a toString that is non deterministic and outputs (3 examples with the same byte array):
> ByteArrayKey{data=ByteArray{size=8, hashCode=33d626a4, array=[2, 62, 5, 74, 79, 78, 65, 83, ..]}}
> ByteArrayKey{data=ByteArray{size=8, hashCode=2ada52a1, array=[2, 62, 5, 74, 79, 78, 65, 83, ..]}}
> ByteArrayKey{data=ByteArray{size=8, hashCode=5576b9ea, array=[2, 62, 5, 74, 79, 78, 65, 83, ..]}}
> As you can see the hashCode is differing even though the byte array is the same.
> This is because ByteArrayKey.toString is using Util.printArray(byte[],true) where true means that a hashCode should be printed as well.
> Unfortenaly, the hashcode is calculated with byte[].hashCode() which is not considering the data in the byte array.
> There are several solutions to the problem:
>  * Have another mechanism to export unique ids from the key instead of toString (with a possible toString fallback)
>  * Fix so that ByteArrayKey.toString returns deterministic data. (Still bad solution as the keys will be very long and not make sense).
>  * Special handling for ByteArrayKey to calculate the key based on the bytes in the byte array.

-- 
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the infinispan-issues mailing list