-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: OSCache & Query Cache
PostPosted: Fri Mar 26, 2004 1:05 am 
Beginner
Beginner

Joined: Wed Nov 19, 2003 10:29 pm
Posts: 27
According to the docs, the query cache works properly with OSCache. I'm trying to switch from EHCache to OSCache due to a very difficult to track down bug that I'm encountering. I don't know if it's due to EHCache, or some other factor, so for now, I'm going to try to switch caches to see if the problem goes away.

I'm having trouble using OSCache with the query cache. It seems when I have a query with parameters in it, the cache always returns the result of the first query, regardless of which query parameters I pass to it.

EHCache does not exhibit this behavior.

A quick dig through the L2 cache system shows that Hibernate uses QueryKey as the key to store the caches. While QueryKey does not implement toString, it does have a hashCode implementation which seems incorrect, since it simply returns the hashCode of the SQL query string, which does NOT include parameters of any type. While I haven't dug through OSCache's implementation, I think it's safe to say that it probably uses hash-codes to compare key values and this is why it is failing.

While I can't do it right this moment, I will attempt to see if replacing the hashCode method with a working one will help. I'll attempt to use Apache commons-lang's HashCodeBuilder to build a working hash code.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 26, 2004 2:23 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Yes, you correctly identified the bug. It is fixed now. I was not aware of this nasty behavior of OSCache, and we don't really regularly test with OSCache.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 26, 2004 2:24 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Forgot to say: the bug was already fixed a while ago. In CVS, both branches.


Top
 Profile  
 
 Post subject: Hmm...
PostPosted: Wed Mar 31, 2004 9:43 pm 
Beginner
Beginner

Joined: Wed Nov 19, 2003 10:29 pm
Posts: 27
I've been digging around the CVS tree, on the assumption that this fix would be in here. It seems that the fix that you're referring to is actually the implementation of toString() rather than hashCode(). hashCode() is still broken.

The current v21branch version (1.1.2.6) reads:
Code:
public int hashCode() {
      return sqlQueryString.hashCode(); //TODO: VERY inefficient!!!!
   }


I've coded the following replacement method:
Code:
import org.apache.commons.lang.builder.HashCodeBuilder;
(**snip**)
public int hashCode() {
   return new HashCodeBuilder(59,15).
      append(sqlQueryString).
      append(firstRow).
      append(types).
      append(values).
      append(namedParameters).
      append(firstRow).
      append(maxRows).
      toHashCode();

}


The 'magic numbers' 59 and 15 are just two random, non-zero, non-even numbers, as specified in the HashCodeBuilder docs.

This has only been lighty tested, but since it matches all of the fields touched in the QueryKey constructor, it seems solid. It certainly fixes the bug I was referring to and the queries that are supposed to be cached are being properly cached,.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 31, 2004 10:33 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Actually OSCache provider uses toString() to compare keys, so the inefficient (but perfectly correct) hashCode() implementation is irrelevant. Anyway, I just now improved the hashCode() method, to eliminate the inefficiency.


Top
 Profile  
 
 Post subject: Query cache key still not distinct
PostPosted: Thu Aug 26, 2004 12:35 pm 
OSCache Developer
OSCache Developer

Joined: Fri Jun 11, 2004 1:20 pm
Posts: 12
Using 2.1.6 so let me know if I have to build CVS head to get the fix but it does not appear any parameters are part of my query cache keys. For example,
sql__select_this_PAGE_ID_as_PAGE_ID0_,_this_NAME_as_NAME0__from_guilds_admin_PAGES_this_where_1=1_order_by_this_NAME_asc__parameters___net_sf_hibernate_cache_StandardQueryCache.cache

Furthermore, another troubling aspect is that the key is too long to have as a filename for many filesystems. Is there anyway I can override the toString on the query caches?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.