On Jan 4, 9:08 pm, Andy <[email protected]> wrote:
> I'm new to sharding and am a little stuck on how to implement the toy
> problem below.  Basically I have a many-to-one relationship between a
> Company and Employees, and I want shards which are partitioned
> according to company name.  My naive approach is to replicate and
> rename the tables.
>
>    (1) Is there a better approach?
>    (2) How do I switch context effectively to use the correct
>           my request handlers?

I think you do not need multiple model definitions. Reading through
this thread
http://www.google.com/url?sa=D&q=http://groups.google.com/group/google-appengine-python/browse_thread/thread/80a44f96c623c964&usg=AFQjCNEqRJtgWyb32OaD2rZXSgpb7AtSqA
i think the solution to your problem could be to use named sharding
counters. Take a look at the article
http://code.google.com/intl/de-DE/appengine/articles/sharding_counters.html
especially the GeneralCounterShard code. Basically you can shard any
instance of your model separately.

If you are familiar with Django i will post about how to use sharding
counters on App Engine using native Django on 
http://allbuttonspressed.blogspot.com/
today. Maybe this can help you too.

Bye,
Thomas

----------
http://allbuttonspressed.blogspot.com/
http://bitbucket.org/wkornewald/djangoappengine/
http://bitbucket.org/wkornewald/django-nonrel/wiki/Home

> Thanks!
> Andy
>
> # (from my models.py)
> #  # I start with these two models, then shard by company
> #  class Company(db.Model):
> #     name=db.StringProperty(required=True)
> #
> #  class Employee(db.Model):
> #     lastname=db.StringProperty(required=True)
> #     company=db.ReferenceProperty(Company,
> collection_name='employees')
>
> # Company 'Foo' and it's employees
> class Company_Foo(db.Model):
>    name=db.StringProperty(required=True)
>
> class Employee_Foo(db.Model):
>    lastname=db.StringProperty(required=True)
>    company=db.ReferenceProperty(Company_Foo,
> collection_name='employees')
>
> # company 'Bar' and it's employees
> class Company_Bar(db.Model):
>    name=db.StringProperty(required=True)
>
> class Employee_Bar(db.Model):
>    lastname=db.StringProperty(required=True)
>    company=db.ReferenceProperty(Company_Bar,
> collection_name='employees')
>
> # (from my handlers.py)
> # other imports here
> from models import *      # potentially hundreds of model shards!?
>
> def MyHandler(webpp.RequestHandler):
>    def post(self):
>       company_id=get_from_request(self)
>       if company_id == 'Foo':
>            my_emp=Employee_Foo.gql(...)
>       else:
>            my_emp=Employee_Bar.gql(...)
-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.


Reply via email to