My router.py file is as below:-

class shard_data:
    id = 0

class AppRouter(object):
    """A router to control all database operations on models in
    that belongs to a app in APPS_WITH_DB"""

    def db_for_read(self, model, **hints):
        "Point all operations on myapp models to 'other'"
        shardval = (int(shard_data.id) % 6 #  6 shards
        logging.debug('ROUTER: id:'+ str(shard_data.id)+ ': Shard:'+
str(shardval))
        if shardval == 1:
            return 'default'
        elif shardval == 0:
            return 'shard6
        else:
            return "shard"+str(int(shardval))

    def db_for_write(self, model, **hints):
        "Point all operations on myapp models to 'other'"
        shardval = (int(shard_data.iw_uid) %
int(settings.SHARD_COUNT))
        if shardval == 1:
            return 'default'
        elif shardval == 0:
            return 'shard'+str(settings.SHARD_COUNT)
        else:
            return "shard"+str(int(shardval))

    def allow_relation(self, obj1, obj2, **hints):
        "Allow any relation if a model in myapp is involved"
        if obj1._meta.app_label == 'app' or obj2._meta.app_label ==
'app':
            return True
        return None

    def allow_syncdb(self, db, model):
        "Make sure the myapp app only appears on the 'other' db"
        if db == 'other':
            return model._meta.app_label == 'app'
        elif model._meta.app_label == 'app':
            return False
        return None

    def _insert(self, values, **kwargs):
        return self.insert_query(self.model, values, **kwargs)


my_restapi.py file

def reqaccess(request, id, sessionkey, desc):

    shard_data.id = int(id)
    user = user_service_api.load_sessionkey(id, session_key)
    if user is not None:
        user.desc = desc
        player = user_service_api.save_player(player)
        xmlstr = "<?xml version='1.0' encoding='utf-8'?>"
        xmlstr += "<response>"
        xmlstr += "<result>ACCESS_REQUESTED</result>"
        xmlstr += "</response>"
        return HttpResponse(xmlstr,'application/xml')
    else:
        xmlstr = "<?xml version='1.0' encoding='utf-8'?>"
        xmlstr += "<response>"
        xmlstr += "<result>false</result>"
        xmlstr += "</response>"
        return HttpResponse(xmlstr,'application/xml')


urlpatterns = patterns('',
    url(r'^RequestAccess/(?P<id>.+)/(?P<sessionkey>.+)/(?P<desc>.+)/
$', req_access),
)


Request to please check the above code "router.py" and "my_restapi.py"
file.
This code is running perfect, but I want to cross check if
"RequestAccess" REST API invoked by the users more then 100 to 1000 of
users at a time then how the request will be handled in the django
using above code.
Do I need to modify anything in the router.py? or is there is any
wrong I'm doing in "reqaccess" definition for getting shard value?
I'm I missing any important point for handling shard_data.id in the
case of 1000 of users invoking RequestAccess REST API?

My very concern is I'm identifying shard using "id" (which is user
primary key, if at a time 1000 of users invoked "RequestAccess" REST
API then they should not get other users response by chance.
I have some other API's same for storing users information and I don't
want other user's information to be stored in any other user's
profile.
Because of which I want to make sure whether above code is correct or
need any further modifications for data protection, so that the data
to be stored in correct Shard even-though if there are 1000's of
request at a time.

Please provide your comments

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to