- 优化 连接池不可用、定时检查;

This commit is contained in:
2881099
2022-05-28 22:09:45 +08:00
parent 67b4e8fbe1
commit 4c7de1da8a
25 changed files with 222 additions and 372 deletions

View File

@ -44,7 +44,8 @@ namespace FreeSql.Sqlite
if (exception != null && exception is SQLiteException)
#endif
{
try { if (obj.Value.Ping() == false) obj.Value.OpenAndAttach(policy.Attaches); } catch { base.SetUnavailable(exception); }
if (obj.Value.Ping() == false)
base.SetUnavailable(exception, obj.LastGetTimeCopy);
}
base.Return(obj, isRecreate);
}
@ -63,7 +64,7 @@ namespace FreeSql.Sqlite
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;
public string[] Attaches = new string[0];
@ -158,9 +159,8 @@ namespace FreeSql.Sqlite
{
if (obj.Value == null)
{
if (_pool.SetUnavailable(new Exception("连接字符串错误,或者检查项目属性 > 生成 > 目标平台x86 | x64")) == true)
throw new Exception($"【{this.Name}】连接字符串错误,请检查。或者检查项目属性 > 生成 > 目标平台x86 | x64");
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)
@ -172,8 +172,9 @@ namespace FreeSql.Sqlite
}
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;
}
}
}
@ -188,9 +189,8 @@ namespace FreeSql.Sqlite
{
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)
@ -202,8 +202,9 @@ namespace FreeSql.Sqlite
}
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;
}
}
}