Skip to content

Commit

Permalink
Merge pull request #321 from nacos-group/naming-redo
Browse files Browse the repository at this point in the history
align java sdk for naming redo
  • Loading branch information
catcherwong authored Sep 21, 2024
2 parents a3a8022 + 237bddc commit ded6426
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/Nacos/V2/Naming/Remote/Grpc/Redo/NamingGrpcRedoService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public void InstanceDeregister(string serviceName, string groupName)
if (_registeredInstances.TryGetValue(key, out var data))
{
data.Unregistering = true;
data.ExpectedRegistered = false;
}
}

Expand All @@ -125,7 +126,10 @@ public void RemoveInstanceForRedo(string serviceName, string groupName)
{
string key = NamingUtils.GetGroupedName(serviceName, groupName);

_registeredInstances.TryRemove(key, out _);
if (_registeredInstances.TryGetValue(key, out var data) && data != null && !data.ExpectedRegistered)
{
_registeredInstances.TryRemove(key, out _);
}
}

/// <summary>
Expand Down Expand Up @@ -190,6 +194,7 @@ public void SubscriberDeregister(string serviceName, string groupName, string cl
if (_subscribes.TryGetValue(key, out var data))
{
data.Unregistering = true;
data.ExpectedRegistered = false;
}
}

Expand All @@ -203,7 +208,10 @@ public void RemoveSubscriberForRedo(string serviceName, string groupName, string
{
string key = ServiceInfo.GetKey(NamingUtils.GetGroupedName(serviceName, groupName), cluster);

_subscribes.TryRemove(key, out _);
if (_subscribes.TryGetValue(key, out var data) && data != null && !data.ExpectedRegistered)
{
_subscribes.TryRemove(key, out _);
}
}

/// <summary>
Expand Down
3 changes: 3 additions & 0 deletions src/Nacos/V2/Naming/Remote/Grpc/Redo/RedoData{T}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ protected RedoData(string serviceName, string groupName)
{
this.ServiceName = serviceName;
this.GroupName = groupName;
this.ExpectedRegistered = true;
}

public string ServiceName { get; private set; }

public string GroupName { get; private set; }

public bool ExpectedRegistered { get; set; }

public T Data { get; set; }

public bool Registered { get; set; }
Expand Down
5 changes: 5 additions & 0 deletions src/Nacos/V2/Naming/Remote/Grpc/Redo/RedoScheduledTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ private async Task RedoForInstance(InstanceRedoData redoData)
case RedoType.REGISTER:
if (IsClientDisabled()) return;

if (redoData is BatchInstanceRedoData batchInstanceRedoData)
{
await _clientProxy.BatchRegisterServiceAsync(serviceName, groupName, batchInstanceRedoData.Instances).ConfigureAwait(false);
}

await _clientProxy.DoRegisterService(serviceName, groupName, redoData.Data).ConfigureAwait(false);
break;
case RedoType.UNREGISTER:
Expand Down

0 comments on commit ded6426

Please sign in to comment.