/// <summary> /// 原子计数器递增 /// </summary> /// <param name="tableName">表名</param> /// <param name="rowKey">rowKey</param> /// <param name="column">列名</param> /// <param name="iep">对应的Region的服务器地址</param> /// <param name="value">递增值</param> /// <returns>递增后的结果</returns> internal long AtomicIncrement(string tableName, byte[] rowKey, string column, IPEndPoint iep, long @value = 1) { if (string.IsNullOrEmpty(tableName)) { throw new ArgumentNullException("tableName"); } IThriftConnectionAgent agent = _connectionPool.GetChannel(iep, "RegionServer", _protocolStack, _transactionManager); if (agent == null) { throw new NoConnectionException(); } Exception ex = null; long result = 0; ThriftMessageTransaction transaction = agent.CreateTransaction(); AutoResetEvent autoResetEvent = new AutoResetEvent(false); transaction.ResponseArrived += delegate(object sender, LightSingleArgEventArgs <ThriftMessage> e) { AtomicIncrementResponseMessage rspMsg = (AtomicIncrementResponseMessage)e.Target; if (rspMsg.IOErrorMessage != null) { ex = new IOErrorException(rspMsg.IOErrorMessage.Reason); } else if (rspMsg.IllegalArgumentErrorMessage != null) { ex = new IOErrorException(rspMsg.IllegalArgumentErrorMessage.Reason); } result = rspMsg.Success; autoResetEvent.Set(); }; transaction.Timeout += delegate { ex = new CommunicationTimeoutException(transaction.SequenceId); autoResetEvent.Set(); }; transaction.Failed += delegate { ex = new CommunicationFailException(transaction.SequenceId); autoResetEvent.Set(); }; AtomicIncrementRequestMessage reqMsg = new AtomicIncrementRequestMessage { TableName = tableName, RowKey = rowKey, Column = column, Value = @value }; transaction.SendRequest(reqMsg); autoResetEvent.WaitOne(); if (ex != null) { throw ex; } return(result); }
/// <summary> /// 原子计数器递增 /// </summary> /// <param name="tableName">表名</param> /// <param name="rowKey">rowKey</param> /// <param name="column">列名</param> /// <param name="iep">对应的Region的服务器地址</param> /// <param name="value">递增值</param> /// <returns>递增后的结果</returns> internal long AtomicIncrement(string tableName, byte[] rowKey, string column, IPEndPoint iep, long @value = 1) { if (string.IsNullOrEmpty(tableName)) throw new ArgumentNullException("tableName"); IThriftConnectionAgent agent = _connectionPool.GetChannel(iep, "RegionServer", _protocolStack, _transactionManager); if (agent == null) throw new NoConnectionException(); Exception ex = null; long result = 0; ThriftMessageTransaction transaction = agent.CreateTransaction(); AutoResetEvent autoResetEvent = new AutoResetEvent(false); transaction.ResponseArrived += delegate(object sender, LightSingleArgEventArgs<ThriftMessage> e) { AtomicIncrementResponseMessage rspMsg = (AtomicIncrementResponseMessage)e.Target; if (rspMsg.IOErrorMessage != null) ex = new IOErrorException(rspMsg.IOErrorMessage.Reason); else if (rspMsg.IllegalArgumentErrorMessage != null) ex = new IOErrorException(rspMsg.IllegalArgumentErrorMessage.Reason); result = rspMsg.Success; autoResetEvent.Set(); }; transaction.Timeout += delegate { ex = new CommunicationTimeoutException(transaction.SequenceId); autoResetEvent.Set(); }; transaction.Failed += delegate { ex = new CommunicationFailException(transaction.SequenceId); autoResetEvent.Set(); }; AtomicIncrementRequestMessage reqMsg = new AtomicIncrementRequestMessage { TableName = tableName, RowKey = rowKey, Column = column, Value = @value}; transaction.SendRequest(reqMsg); autoResetEvent.WaitOne(); if (ex != null) throw ex; return result; }