示例#1
0
        private int ProcessAcquireRequest(Zeze.Net.Protocol p)
        {
            Acquire rpc = (Acquire)p;

            if (rpc.Sender.UserState == null)
            {
                rpc.SendResultCode(AcquireNotLogin);
                return(0);
            }
            switch (rpc.Argument.State)
            {
            case StateInvalid:     // realease
                Release(rpc.Sender.UserState as CacheHolder, rpc.Argument.GlobalTableKey);
                rpc.Result = rpc.Argument;
                rpc.SendResult();
                return(0);

            case StateShare:
                return(AcquireShare(rpc));

            case StateModify:
                return(AcquireModify(rpc));

            default:
                rpc.Result = rpc.Argument;
                rpc.SendResultCode(AcquireErrorState);
                return(0);
            }
        }
示例#2
0
        private int ProcessReLogin(Zeze.Net.Protocol p)
        {
            var rpc     = p as ReLogin;
            var session = Sessions.GetOrAdd(rpc.Argument.AutoKeyLocalId, (_) => new CacheHolder());

            if (false == session.TryBindSocket(p.Sender, rpc.Argument.GlobalCacheManagerHashIndex))
            {
                rpc.SendResultCode(ReLoginBindSocketFail);
                return(0);
            }
            rpc.SendResultCode(0);
            return(0);
        }
示例#3
0
        public int ProcessReduceRequest(Zeze.Net.Protocol p)
        {
            GlobalCacheManager.Reduce rpc = (GlobalCacheManager.Reduce)p;
            switch (rpc.Argument.State)
            {
            case GlobalCacheManager.StateInvalid:
                return(Zeze.GetTable(rpc.Argument.GlobalTableKey.TableName).ReduceInvalid(rpc));

            case GlobalCacheManager.StateShare:
                return(Zeze.GetTable(rpc.Argument.GlobalTableKey.TableName).ReduceShare(rpc));

            default:
                rpc.Result = rpc.Argument;
                rpc.SendResultCode(GlobalCacheManager.ReduceErrorState);
                return(0);
            }
        }
示例#4
0
        /// <summary>
        /// 报告错误的时候带上相关信息(包括GlobalCacheManager和LogicServer等等)
        /// 手动Cleanup时,连接正确的服务器执行。
        /// </summary>
        /// <param name="p"></param>
        /// <returns></returns>
        private int ProcessCleanup(Zeze.Net.Protocol p)
        {
            var rpc = p as Cleanup;

            // 安全性以后加强。
            if (false == rpc.Argument.SecureKey.Equals("Ok! verify secure."))
            {
                rpc.SendResultCode(CleanupErrorSecureKey);
                return(0);
            }

            var session = Sessions.GetOrAdd(rpc.Argument.AutoKeyLocalId, (key) => new CacheHolder());

            if (session.GlobalCacheManagerHashIndex != rpc.Argument.GlobalCacheManagerHashIndex)
            {
                // 多点验证
                rpc.SendResultCode(CleanupErrorGlobalCacheManagerHashIndex);
                return(0);
            }

            if (this.Server.GetSocket(session.SessionId) != null)
            {
                // 连接存在,禁止cleanup。
                rpc.SendResultCode(CleanupErrorHasConnection);
                return(0);
            }

            // 还有更多的防止出错的手段吗?

            // XXX verify danger
            Zeze.Util.Scheduler.Instance.Schedule(
                (ThisTask) =>
            {
                foreach (var gkey in session.Acquired.Keys)
                {
                    // ConcurrentDictionary 可以在循环中删除。这样虽然效率低些,但是能处理更多情况。
                    Release(session, gkey);
                }
                rpc.SendResultCode(0);
            },
                5 * 60 * 1000); // delay 5 mins

            return(0);
        }
示例#5
0
        private int ProcessLogin(Zeze.Net.Protocol p)
        {
            var rpc     = p as Login;
            var session = Sessions.GetOrAdd(rpc.Argument.AutoKeyLocalId, (_) => new CacheHolder());

            if (false == session.TryBindSocket(p.Sender, rpc.Argument.GlobalCacheManagerHashIndex))
            {
                rpc.SendResultCode(LoginBindSocketFail);
                return(0);
            }
            // new login, 比如逻辑服务器重启。release old acquired.
            foreach (var gkey in session.Acquired.Keys)
            {
                // ConcurrentDictionary 可以在循环中删除。这样虽然效率低些,但是能处理更多情况。
                Release(session, gkey);
            }
            rpc.SendResultCode(0);
            return(0);
        }
示例#6
0
        private int ProcessNormalClose(Zeze.Net.Protocol p)
        {
            var rpc     = p as NormalClose;
            var session = rpc.Sender.UserState as CacheHolder;

            if (null == session)
            {
                rpc.SendResultCode(AcquireNotLogin);
                return(0); // not login
            }
            if (false == session.TryUnBindSocket(p.Sender))
            {
                rpc.SendResultCode(NormalCloseUnbindFail);
                return(0);
            }
            foreach (var gkey in session.Acquired.Keys)
            {
                // ConcurrentDictionary 可以在循环中删除。这样虽然效率低些,但是能处理更多情况。
                Release(session, gkey);
            }
            rpc.SendResultCode(0);
            logger.Debug("After NormalClose global.Count={0}", global.Count);
            return(0);
        }