From d27bee2952dc7d1e9f5701e7983def5c88432101 Mon Sep 17 00:00:00 2001 From: Armstrong Date: Sat, 17 Aug 2024 15:42:29 +0800 Subject: [PATCH] =?UTF-8?q?fix:[=E5=8A=A8=E6=80=81=E9=85=8D=E7=BD=AE]?= =?UTF-8?q?=E4=BF=AE=E5=A4=8Dconfig=5Fflow=E9=80=92=E5=BD=92=E5=8A=A0?= =?UTF-8?q?=E8=AF=BB=E9=94=81=E5=AF=BC=E8=87=B4=E7=9A=84=E6=AD=BB=E9=94=81?= =?UTF-8?q?=E9=97=AE=E9=A2=98=20(#212)=20(#215)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: ArmstrongCN --- pkg/flow/configuration/config_flow.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/pkg/flow/configuration/config_flow.go b/pkg/flow/configuration/config_flow.go index b1f92af8..84774a1e 100644 --- a/pkg/flow/configuration/config_flow.go +++ b/pkg/flow/configuration/config_flow.go @@ -336,7 +336,7 @@ func (c *ConfigFileFlow) mainLoop(ctx context.Context) { changedConfigFile.GetFileName()) newNotifiedVersion := changedConfigFile.GetVersion() - oldNotifiedVersion := c.getConfigFileNotifiedVersion(cacheKey) + oldNotifiedVersion := c.getConfigFileNotifiedVersion(cacheKey, true) maxVersion := oldNotifiedVersion if newNotifiedVersion > oldNotifiedVersion { @@ -382,7 +382,7 @@ func (c *ConfigFileFlow) assembleWatchConfigFiles() []*configconnector.ConfigFil Namespace: configFileMetadata.GetNamespace(), FileGroup: configFileMetadata.GetFileGroup(), FileName: configFileMetadata.GetFileName(), - Version: c.getConfigFileNotifiedVersion(cacheKey), + Version: c.getConfigFileNotifiedVersion(cacheKey, false), }) } @@ -395,9 +395,11 @@ func (c *ConfigFileFlow) updateNotifiedVersion(cacheKey string, version uint64) c.notifiedVersion[cacheKey] = version } -func (c *ConfigFileFlow) getConfigFileNotifiedVersion(cacheKey string) uint64 { - c.fclock.RLock() - defer c.fclock.RUnlock() +func (c *ConfigFileFlow) getConfigFileNotifiedVersion(cacheKey string, locking bool) uint64 { + if locking { + c.fclock.RLock() + defer c.fclock.RUnlock() + } version, ok := c.notifiedVersion[cacheKey] if !ok { version = initVersion