Skip to content

Commit b5e1ea8

Browse files
committed
1
1 parent a8dce7b commit b5e1ea8

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

src/OpenTask.Application/Core/DiscoveryFromDb.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ private void discoveryTimerElapsed(object? sender, ElapsedEventArgs e)
9696
[Obsolete]
9797
private async Task updateSubscriber(IEnumerable<Domain.Servers.OpenTaskServer> latestNodes)
9898
{
99+
logger.LogDebug($"[updateSubscriber] 节点数:{latestNodes.Count()}");
99100
foreach (Domain.Servers.OpenTaskServer item in latestNodes)
100101
{
101102
// 新增的节点
@@ -188,24 +189,24 @@ private async Task TryReslot()
188189

189190
logger.LogInformation($"当前监听节点列表:{String.Join(",", clusterSubscribers.Select(x => x.Key))}");
190191

191-
// 1分钟内最多只有一个节点执行一次
192-
if (!lockerService.TryLock(LOCK_KEY, myMqttServer.Identifier, 60, out Locker? locker))
193-
{
194-
logger.LogDebug($"[获取锁失败]:{locker?.Version}@{locker?.LockedAt}");
195-
return;
196-
}
197-
198192
// 服务发现
199193
IEnumerable<Domain.Servers.OpenTaskServer> latestNodes = FindAllOnlineServer();
200194
await updateSubscriber(latestNodes);
201195

202-
if (IsWholeSlot(latestNodes))
196+
// 1分钟内最多只有一个节点执行一次
197+
if (!lockerService.TryLock(LOCK_KEY, myMqttServer.Identifier, 60, out Locker? locker))
203198
{
199+
logger.LogDebug($"[获取锁失败]:{locker?.Version}@{locker?.LockedAt}");
204200
return;
205201
}
206202

207203
try
208204
{
205+
if (IsWholeSlot(latestNodes))
206+
{
207+
return;
208+
}
209+
209210
logger.LogInformation($"[集群节点分配不均] 开始重新分配slot,当前节点数:{latestNodes.Count()}");
210211

211212
// TODO: 存在通知失败的可能,要比对连接到当前server的其他的server,

src/OpenTask.Application/Core/OpenTaskServer.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ public class OpenTaskServer : Disposable, ITaskServer
3131

3232
public string ExternalUrl => options.ExternalUrl ?? $"{options.Ip}:{options.Port}";
3333

34+
[Obsolete("通过数据库维护", true)]
3435
public ConcurrentDictionary<string, ExecutorClient> CurrentNodeOnlineUsers { private set; get; } = new ConcurrentDictionary<string, ExecutorClient>();
3536

37+
[Obsolete("通过数据库维护", true)]
3638
public ConcurrentDictionary<string, ExecutorClient> CurrentNodeOnlineServer { private set; get; } = new ConcurrentDictionary<string, ExecutorClient>();
3739

3840
public ConcurrentDictionary<string, IEnumerable<ExecutorClient>> OtherNodeOlineUsers { get; private set; } = new ConcurrentDictionary<string, IEnumerable<ExecutorClient>>();

0 commit comments

Comments
 (0)