-->
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.  [ 7 posts ] 
Author Message
 Post subject: Shards: How to determine to which Shard an Entity belongs
PostPosted: Tue Apr 17, 2007 6:48 am 
Beginner
Beginner

Joined: Thu Sep 01, 2005 10:09 am
Posts: 39
Im getting started with shards and I'm very excited. But I have multiple Databases where an Id can exist many times (in each db). So this is ok as for now I need only read access to these tables. But how can I find out from which shard an object originated ? I need to tell my user from which database the object he sees is coming. Any ideas ?
Thank you
Thomas


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 18, 2007 1:57 am 
Contributor
Contributor

Joined: Fri Feb 11, 2005 8:15 pm
Posts: 31
Hi Thomas, thanks for posting your question. There's a method available on the ShardedSession interface that will return the id of the shard on which an object resides:

ShardId getShardIdForObject(Object obj);

This will only work for objects that you've already loaded from the database, and you'll of course need to downcast your Session to a ShardedSession, but it should give you what you need.

Hope this helps. Please post back if it doesn't.

Max


Top
 Profile  
 
 Post subject: Session Access in Event or Interceptor
PostPosted: Mon Apr 23, 2007 11:04 am 
Beginner
Beginner

Joined: Thu Sep 01, 2005 10:09 am
Posts: 39
Thanks Max this is useful. Now I have another question. I have a client server architecture and the client doesnt have access to the session. Therefore I want to embed the ShardId as a transient field in my domain objects. I thought of setting the value with an Interceptor or an EventListener but then I don't have access to the session object. Any Ideas ?
Thomas


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 23, 2007 9:46 pm 
Contributor
Contributor

Joined: Fri Feb 11, 2005 8:15 pm
Posts: 31
Interesting. Why does the client need to know the id of the shard on which the object resides? I'm sure you have a good reason, I'm just curious.

There's a method available on ShardedSession that will, given an object that is known to some Shard, return the ShardId: ShardedSession.getShardIdForObject(). You can call this on the serverside and set its return value as a transient property on the objects that you ship to the client. The trick for you, I suspect, will be putting the code to do this in a centralized location so that you don't need to remember to populate this value every time. An Interceptor sounds like a fine idea. It's true that the Interceptor methods don't give you access to the Session (and even if they did it would probably be the real Session, not the ShardedSession). Do you store your ShardedSession in a ThreadLocal that you could access from within the Interceptor? You might also take a look at this feature request that was filed: http://opensource.atlassian.com/project ... /HSHARDS-9

The filer proposed adding a ShardAware interface and having an ExitStrategy that then adds the id of the shard on which the object was found to all objects that implement this interface. I'm not sure how I feel about this but maybe it will inspire you.

Max


Top
 Profile  
 
 Post subject: Parallel Access ?
PostPosted: Wed Apr 25, 2007 3:48 am 
Beginner
Beginner

Joined: Thu Sep 01, 2005 10:09 am
Posts: 39
HI Max. Thank you for the hint. My Client needs to show from which database the record is, thats a requirement :) The user can derive certain things from that information. I tried it with a ThreadLocal but that only works with a sequential access, because in Parallel access we have a new thread. Di you have any ideas for that ? would be nice id I could do parallel access. But if not i will live with that. So long & thanks Thomas


Top
 Profile  
 
 Post subject: ShardAware
PostPosted: Wed Apr 25, 2007 3:52 am 
Beginner
Beginner

Joined: Thu Sep 01, 2005 10:09 am
Posts: 39
Once again, I had a look at the ShardAware topic. I think it is useful to decorate the model objects withs the shard ID if someone wants to do so. In my case this is exactly what i need.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 26, 2007 1:23 am 
Contributor
Contributor

Joined: Fri Feb 11, 2005 8:15 pm
Posts: 31
Very well then. For now I guess you'll need to set this on your objects manually, but we should certainly be able to accomnodate this request using something similar to the proposal in the bug.

Thanks,
Max


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.