Ejemplo n.º 1
0
    def get(self, user_id, create_if_missing=False, **_private_kw):
        """
        Get state for the specified user, but don't acquire a lock.
        Returns None if the state was not found.

        Note: _private_kw should never be used as part of the public API.
        It is a private interface which allows open() to acquire a lock
        and is UNSAFE for external use.
        """
        log.debug("uuss.UserState.get %r", user_id)
        user_id = str(user_id)

        if not user_id:
            raise UserstateException("user_id is empty... %r" % user_id)
        if user_id[0] == "{":
            raise UserstateException("user_id appears to be json... %r" % user_id)

        req = proto.GetRequest()
        req.game = self.game
        req.user_id = user_id
        req.create_if_missing = create_if_missing
        req.lock = _private_kw.get('_lock', False)
        req.lock_label = _private_kw.get('_lock_label', 'generic')
        req.lock_timeout = _private_kw.get('_lock_timeout', 60)
        req.lock_max_wait = _private_kw.get('_lock_max_wait', 30)
        self._protocol_send_message(req)
        resp = self._recv_expected_message(proto.GetResponse, self.game, user_id)

        if resp.state == "":
            state = None
        else:
            state = chunking.reconstitute_chunks(resp.state, self._lazy_load_chunks)
            check_user_id(user_id, state, game=self.game)

        return state
Ejemplo n.º 2
0
    def save(self, user_id, state):
        """
        Save the state for the specified user (but don't release the lock).
        user_id: string
        state: dict (not a json string)
        """
        log.debug("uuss.UserState.save %r", user_id)
        user_id = str(user_id)
        # Debugging for FB20021
        if user_id == 'null':
            raise Exception('"null" user_id in userstate.save')
        if not isinstance(state, dict):
            raise Exception('state not a dict for user_id %s' % user_id)

        check_user_id(user_id, state, game=self.game)

        req = proto.SaveRequest()
        req.game = self.game
        req.user_id = user_id
        req.state = chunking.blow_chunks(state, self.chunk_config)
        self._protocol_send_message(req)
        resp = self._recv_expected_message(proto.SaveResponse, self.game, user_id)
Ejemplo n.º 3
0
        print "Wrong user_id in state for %r" % uid
        
        user_state = model.dane.UserState.get(uid)
        try:
            state = chunking.reconstitute_chunks(user_state.state, True)
        except:
            chunking_exc = sys.exc_info()
            try:
                state = simplejson.loads(zlib.decompress(user_state.state))
            except Exception, e:
                print "Chunking and original formats failed"
                print e
                print chunking_exc

        try:
            uuss.check_user_id(uid, state)
        except:
            print "User ID for %r incorrect in DB\n%r" % (uid, state)

        state = userstate._mc.get(userstate._make_key(uid), lazy_load_chunks=True)
        try:
            uuss.check_user_id(uid, state)
        except:
            print "UserID for %r incorrect in Memcache\n%r" % (uid, state)
            
        if uid in fixed_userstates:
            print "WARNING: uid %r has been fixed %r times before" % (uid, fixed_userstates[uid])
        else:
            fixed_userstates[uid] = 0
        fixed_userstates[uid] += 1
        userstate.save(uid, {'user_id': uid})