mirror of
				https://github.com/nsnail/FreeSql.git
				synced 2025-11-04 09:15:27 +08:00 
			
		
		
		
	- 优化 连接池不可用、定时检查;
This commit is contained in:
		@@ -33,18 +33,8 @@ namespace FreeSql.ShenTong
 | 
			
		||||
        {
 | 
			
		||||
            if (exception != null && exception is OscarException)
 | 
			
		||||
            {
 | 
			
		||||
 | 
			
		||||
                if (exception is System.IO.IOException)
 | 
			
		||||
                {
 | 
			
		||||
 | 
			
		||||
                    base.SetUnavailable(exception);
 | 
			
		||||
 | 
			
		||||
                }
 | 
			
		||||
                else if (obj.Value.Ping() == false)
 | 
			
		||||
                {
 | 
			
		||||
 | 
			
		||||
                    base.SetUnavailable(exception);
 | 
			
		||||
                }
 | 
			
		||||
                if (obj.Value.Ping() == false)
 | 
			
		||||
                    base.SetUnavailable(exception, obj.LastGetTimeCopy);
 | 
			
		||||
            }
 | 
			
		||||
            base.Return(obj, isRecreate);
 | 
			
		||||
        }
 | 
			
		||||
@@ -61,7 +51,7 @@ namespace FreeSql.ShenTong
 | 
			
		||||
        public int AsyncGetCapacity { get; set; } = 10000;
 | 
			
		||||
        public bool IsThrowGetTimeoutException { get; set; } = true;
 | 
			
		||||
        public bool IsAutoDisposeWithSystem { get; set; } = true;
 | 
			
		||||
        public int CheckAvailableInterval { get; set; } = 5;
 | 
			
		||||
        public int CheckAvailableInterval { get; set; } = 2;
 | 
			
		||||
        public int Weight { get; set; } = 1;
 | 
			
		||||
 | 
			
		||||
        static ConcurrentDictionary<string, int> dicConnStrIncr = new ConcurrentDictionary<string, int>(StringComparer.CurrentCultureIgnoreCase);
 | 
			
		||||
@@ -129,9 +119,8 @@ namespace FreeSql.ShenTong
 | 
			
		||||
            {
 | 
			
		||||
                if (obj.Value == null)
 | 
			
		||||
                {
 | 
			
		||||
                    if (_pool.SetUnavailable(new Exception("连接字符串错误")) == true)
 | 
			
		||||
                        throw new Exception($"【{this.Name}】连接字符串错误,请检查。");
 | 
			
		||||
                    return;
 | 
			
		||||
                    _pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy);
 | 
			
		||||
                    throw new Exception($"【{this.Name}】连接字符串错误,请检查。");
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && obj.Value.Ping() == false)
 | 
			
		||||
@@ -143,8 +132,9 @@ namespace FreeSql.ShenTong
 | 
			
		||||
                    }
 | 
			
		||||
                    catch (Exception ex)
 | 
			
		||||
                    {
 | 
			
		||||
                        if (_pool.SetUnavailable(ex) == true)
 | 
			
		||||
                        if (_pool.SetUnavailable(ex, obj.LastGetTimeCopy) == true)
 | 
			
		||||
                            throw new Exception($"【{this.Name}】Block access and wait for recovery: {ex.Message}");
 | 
			
		||||
                        throw ex;
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
@@ -159,9 +149,8 @@ namespace FreeSql.ShenTong
 | 
			
		||||
            {
 | 
			
		||||
                if (obj.Value == null)
 | 
			
		||||
                {
 | 
			
		||||
                    if (_pool.SetUnavailable(new Exception("连接字符串错误")) == true)
 | 
			
		||||
                        throw new Exception($"【{this.Name}】连接字符串错误,请检查。");
 | 
			
		||||
                    return;
 | 
			
		||||
                    _pool.SetUnavailable(new Exception("连接字符串错误"), obj.LastGetTimeCopy);
 | 
			
		||||
                    throw new Exception($"【{this.Name}】连接字符串错误,请检查。");
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && (await obj.Value.PingAsync()) == false)
 | 
			
		||||
@@ -173,8 +162,9 @@ namespace FreeSql.ShenTong
 | 
			
		||||
                    }
 | 
			
		||||
                    catch (Exception ex)
 | 
			
		||||
                    {
 | 
			
		||||
                        if (_pool.SetUnavailable(ex) == true)
 | 
			
		||||
                        if (_pool.SetUnavailable(ex, obj.LastGetTimeCopy) == true)
 | 
			
		||||
                            throw new Exception($"【{this.Name}】Block access and wait for recovery: {ex.Message}");
 | 
			
		||||
                        throw ex;
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user