Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix refresh listen #789

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions clients/config_client/config_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/nacos-group/nacos-sdk-go/v2/common/logger"
"github.com/nacos-group/nacos-sdk-go/v2/common/monitor"
"github.com/nacos-group/nacos-sdk-go/v2/common/nacos_error"
"github.com/nacos-group/nacos-sdk-go/v2/common/remote/rpc"
"github.com/nacos-group/nacos-sdk-go/v2/common/remote/rpc/rpc_request"
"github.com/nacos-group/nacos-sdk-go/v2/common/remote/rpc/rpc_response"
"github.com/nacos-group/nacos-sdk-go/v2/inner/uuid"
Expand Down Expand Up @@ -396,10 +397,12 @@ func (client *ConfigClient) startInternal() {
defer timer.Stop()
for {
select {
case <-rpc.ReconnectionChan:
client.executeConfigListen(true)
case <-client.listenExecute:
client.executeConfigListen()
client.executeConfigListen(false)
case <-timer.C:
client.executeConfigListen()
client.executeConfigListen(false)
case <-client.ctx.Done():
return
}
Expand All @@ -408,9 +411,9 @@ func (client *ConfigClient) startInternal() {
}()
}

func (client *ConfigClient) executeConfigListen() {
func (client *ConfigClient) executeConfigListen(immediatelySync bool) {
var (
needAllSync = time.Since(client.lastAllSyncTime) >= constant.ALL_SYNC_INTERNAL
needAllSync = time.Since(client.lastAllSyncTime) >= constant.ALL_SYNC_INTERNAL || immediatelySync
hasChangedKeys = false
)

Expand Down
6 changes: 4 additions & 2 deletions common/remote/rpc/rpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ const (
)

var (
cMux = new(sync.Mutex)
clientMap = make(map[string]IRpcClient)
cMux = new(sync.Mutex)
clientMap = make(map[string]IRpcClient)
ReconnectionChan = make(chan struct{})
)

type IRpcClient interface {
Expand Down Expand Up @@ -448,6 +449,7 @@ func (r *RpcClient) reconnect(serverInfo ServerInfo, onRequestFail bool) {
r.currentConnection = connectionNew
atomic.StoreInt32((*int32)(&r.rpcClientStatus), (int32)(RUNNING))
r.notifyConnectionChange(CONNECTED)
ReconnectionChan <- struct{}{}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

也许不需要ReconnectionChan,可以看下在notifyConnectionChange中实现IConnectionEventListener接口。

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IConnectionEventListener也是通过RpcClient.eventChan通知连接状态的变更,config订阅这边同样用了ReconnectionChan来触发ConfigClient的executeConfigListen,应该也可以吧?

return
}
if r.isShutdown() {
Expand Down
Loading