Skip to content

Commit

Permalink
feat(configcache): add ReadAll method
Browse files Browse the repository at this point in the history
It's going to be useful when fixing #3892.

Ref #3892
  • Loading branch information
Michal-Leszczynski committed Dec 13, 2024
1 parent 96be35a commit c6a71a5
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions pkg/service/configcache/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ type ConfigCacher interface {
// or ErrNoHostConfig if config of the particular host doesn't exist.
Read(clusterID uuid.UUID, host string) (NodeConfig, error)

// ReadAll calls Read on all AvailableHosts.
ReadAll(clusterID uuid.UUID) (map[string]NodeConfig, error)

// AvailableHosts returns list of hosts of given cluster that keep their configuration in cache.
AvailableHosts(ctx context.Context, clusterID uuid.UUID) ([]string, error)

Expand Down Expand Up @@ -88,6 +91,23 @@ func (svc *Service) Read(clusterID uuid.UUID, host string) (NodeConfig, error) {
return hostConfig, nil
}

// ReadAll calls Read on AvailableHosts.
func (svc *Service) ReadAll(clusterID uuid.UUID) (map[string]NodeConfig, error) {
clusterConfig, err := svc.readClusterConfig(clusterID)
if err != nil {
return nil, err
}

out := make(map[string]NodeConfig)
clusterConfig.Range(func(key, value any) bool {
host := key.(string)
cfg := value.(NodeConfig)
out[host] = cfg
return true
})
return out, nil
}

// Run starts the infinity loop responsible for updating the clusters configuration periodically.
func (svc *Service) Run(ctx context.Context) {
freq := time.NewTicker(svc.svcConfig.UpdateFrequency)
Expand Down

0 comments on commit c6a71a5

Please sign in to comment.