/// <summary> /// 返回null表示发生了网络错误,或者应用服务器已经关闭。 /// </summary> /// <param name="gkey"></param> /// <param name="state"></param> /// <returns></returns> public Reduce ReduceWaitLater(GlobalTableKey gkey, int state) { try { lock (this) { if (global::Zeze.Util.Time.NowUnixMillis - LastErrorTime < ForbitPeriod) { return(null); } } AsyncSocket peer = GlobalCacheManager.Instance.Server.GetSocket(SessionId); if (null != peer) { Reduce reduce = new Reduce(gkey, state); reduce.SendForWait(peer, 10000); return(reduce); } } catch (Exception ex) { // 这里的异常只应该是网络发送异常。 logger.Error(ex, "ReduceWaitLater Exception {0}", gkey); } SetError(); return(null); }
public int Reduce(GlobalTableKey gkey, int state) { try { Reduce reduce = ReduceWaitLater(gkey, state); if (null != reduce) { reduce.Future.Task.Wait(); // 如果rpc返回错误的值,外面能处理。 return(reduce.Result.State); } return(GlobalCacheManager.StateReduceNetError); } catch (RpcTimeoutException timeoutex) { // 等待超时,应该报告错误。 logger.Error(timeoutex, "Reduce RpcTimeoutException {0} target={1}", state, SessionId); return(GlobalCacheManager.StateReduceRpcTimeout); } catch (Exception ex) { logger.Error(ex, "Reduce Exception {0} target={1}", state, SessionId); return(GlobalCacheManager.StateReduceException); } }
public override void Decode(ByteBuffer bb) { if (null == GlobalTableKey) { GlobalTableKey = new GlobalTableKey(); } GlobalTableKey.Decode(bb); State = bb.ReadInt(); }
private void Release(CacheHolder holder, GlobalTableKey gkey) { CacheState cs = global.GetOrAdd(gkey, (tabkeKeyNotUsed) => new CacheState()); lock (cs) { if (cs.Modify == holder) { cs.Modify = null; } cs.Share.Remove(holder); // always try remove if (cs.Modify == null && cs.Share.Count == 0 && cs.AcquireStatePending == StateInvalid) { // 安全的从global中删除,没有并发问题。 cs.AcquireStatePending = StateRemoved; global.TryRemove(gkey, out var _); } holder.Acquired.TryRemove(gkey, out var _); } }
public Reduce(GlobalTableKey gkey, int state) { Argument.GlobalTableKey = gkey; Argument.State = state; }
public Acquire(GlobalTableKey gkey, int state) { Argument.GlobalTableKey = gkey; Argument.State = state; }
public override string ToString() { return(GlobalTableKey.ToString() + ":" + State); }
public override void Encode(ByteBuffer bb) { GlobalTableKey.Encode(bb); bb.WriteInt(State); }