Ejemplo n.º 1
0
        internal int Acquire(GlobalCacheManager.GlobalTableKey gkey, int state)
        {
            if (null != Client)
            {
                var agent  = Agents[GetGlobalCacheManagerHashIndex(gkey)]; // hash
                var socket = agent.Connect(Client);

                // 请求处理错误抛出异常(比如网络或者GlobalCacheManager已经不存在了),打断外面的事务。
                // 一个请求异常不关闭连接,尝试继续工作。
                GlobalCacheManager.Acquire rpc = new GlobalCacheManager.Acquire(gkey, state);
                rpc.SendForWait(socket, 12000).Task.Wait();

                /*
                 * if (rpc.ResultCode != 0) // 这个用来跟踪调试,正常流程使用Result.State检查结果。
                 * {
                 *  logger.Warn("Acquire ResultCode={0} {1}", rpc.ResultCode, rpc.Result);
                 * }
                 */
                switch (rpc.ResultCode)
                {
                case GlobalCacheManager.AcquireModifyFaild:
                case GlobalCacheManager.AcquireShareFaild:
                    throw new AbortException("GlobalAgent.Acquire Faild");
                }
                return(rpc.Result.State);
            }
            logger.Debug("Acquire local ++++++");
            return(state);
        }
Ejemplo n.º 2
0
 internal int GetGlobalCacheManagerHashIndex(GlobalCacheManager.GlobalTableKey gkey)
 {
     return(gkey.GetHashCode() % Agents.Length);
 }