mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-19 20:38:16 +08:00
- 修复 UseSlaveWeight 异步下可能无效的问题;#1382
This commit is contained in:
@ -33,7 +33,6 @@ namespace FreeSql.Internal.CommonProvider
|
||||
public CommonUtils _util { get; set; }
|
||||
protected int slaveUnavailables = 0;
|
||||
private object slaveLock = new object();
|
||||
private Random slaveRandom = new Random();
|
||||
protected Func<DbTransaction> ResolveTransaction;
|
||||
|
||||
public AdoProvider(DataType dataType, string connectionString, string[] slaveConnectionStrings)
|
||||
@ -584,7 +583,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
if (availables.Count == 1) pool = availables[0];
|
||||
else
|
||||
{
|
||||
var rnd = slaveRandom.Next(availables.Sum(a => a.Policy.Weight));
|
||||
var rnd = FreeUtil.rnd.Value.Next(availables.Sum(a => a.Policy.Weight));
|
||||
for(var a = 0; a < availables.Count; a++)
|
||||
{
|
||||
rnd -= availables[a].Policy.Weight;
|
||||
|
@ -501,7 +501,20 @@ namespace FreeSql.Internal.CommonProvider
|
||||
if (availables.Any())
|
||||
{
|
||||
isSlave = true;
|
||||
pool = availables.Count == 1 ? this.SlavePools[0] : availables[slaveRandom.Next(availables.Count)];
|
||||
if (availables.Count == 1) pool = availables[0];
|
||||
else
|
||||
{
|
||||
var rnd = FreeUtil.rnd.Value.Next(availables.Sum(a => a.Policy.Weight));
|
||||
for (var a = 0; a < availables.Count; a++)
|
||||
{
|
||||
rnd -= availables[a].Policy.Weight;
|
||||
if (rnd < 0)
|
||||
{
|
||||
pool = availables[a];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user