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:初始加载失败依旧加入懒加载列表,异步检查流程优化 #309

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
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 client.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,10 @@ func (c *internalClient) GetConfigAndInit(namespace string) *storage.Config {
if cfg == nil {
//sync config
apolloConfig := syncApolloConfig.SyncWithNamespace(namespace, c.getAppConfig)
if apolloConfig != nil {
c.SyncAndUpdate(namespace, apolloConfig)
if apolloConfig == nil {
log.Warnf("apolloConfig is nil: %s, but it's be added notification", namespace)
}
c.SyncAndUpdate(namespace, apolloConfig)
}

cfg = c.cache.GetConfig(namespace)
Expand All @@ -189,10 +190,12 @@ func (c *internalClient) SyncAndUpdate(namespace string, apolloConfig *config.Ap
}

// update notification
c.appConfig.GetNotificationsMap().UpdateNotify(namespace, 0)
c.appConfig.GetNotificationsMap().UpdateNotify(namespace, -1)

// update cache
c.cache.UpdateApolloConfig(apolloConfig, c.getAppConfig)
if apolloConfig != nil {
c.cache.UpdateApolloConfig(apolloConfig, c.getAppConfig)
}
}

// GetConfigCache 根据namespace获取apollo配置的缓存
Expand Down
3 changes: 2 additions & 1 deletion client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ func TestGetConfigAndInitValNotNil(t *testing.T) {
Assert(t, cf, NotNilVal())

// appConfig notificationsMap appConfig should be updated
Assert(t, client.appConfig.GetNotificationsMap().GetNotify("testNotFound"), Equal(int64(0)))
Assert(t, client.appConfig.GetNotificationsMap().GetNotify("testNotFound"), Equal(int64(-1)))

// cache should be updated with new configuration
Assert(t, client.cache.GetConfig("testNotFound"), NotNilVal())
Expand Down Expand Up @@ -412,4 +412,5 @@ func TestGetConfigAndInitValNil(t *testing.T) {
cf := client.GetConfig("testNotFound")
Assert(t, cf, NilVal())
Assert(t, client.cache.GetConfig("testNotFound"), NilVal())
Assert(t, client.appConfig.GetNotificationsMap().GetNotify("testNotFound"), Equal(int64(-1)))
}
4 changes: 3 additions & 1 deletion component/remote/async.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ func (a *asyncApolloConfig) Sync(appConfigFunc func() config.AppConfig) []*confi
//只是拉去有变化的配置, 并更新拉取成功的namespace的notify ID
for _, notifyConfig := range remoteConfigs {
apolloConfig := a.SyncWithNamespace(notifyConfig.NamespaceName, appConfigFunc)
if apolloConfig != nil {
// update valid apolloConfig
// if apolloConfig.Configurations are empty, async should ignore it
if apolloConfig != nil && len(apolloConfig.Configurations) > 0 {
appConfig.GetNotificationsMap().UpdateNotify(notifyConfig.NamespaceName, notifyConfig.NotificationID)
apolloConfigs = append(apolloConfigs, apolloConfig)
}
Expand Down
7 changes: 6 additions & 1 deletion protocol/http/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,12 @@ func RequestRecovery(appConfig config.AppConfig,
return response, nil
}

server.SetDownNode(appConfig.GetHost(), host)
// can use node length > 1, should be down node
if server.GetServersLen(appConfig.GetHost()) > 1 {
server.SetDownNode(appConfig.GetHost(), host)
} else {
return nil, err
}
}
}

Expand Down
Loading