Skip to content

Commit

Permalink
MB-39144 Use clusterInfoClient for updating cinfo cache in lifecycle mgr
Browse files Browse the repository at this point in the history
BP of MB-38119 to 6.6.0

Change-Id: I861007be16231f650e3c28bbe787cb3459470ea9
  • Loading branch information
varunv-cb committed May 22, 2020
1 parent 0499862 commit c39f4bd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
22 changes: 15 additions & 7 deletions secondary/manager/lifecycle.go
Expand Up @@ -39,6 +39,7 @@ import (
type LifecycleMgr struct {
repo *MetadataRepo
cinfo *common.ClusterInfoCache
cinfoClient *common.ClusterInfoClient
notifier MetadataNotifier
clusterURL string
incomings chan *requestHolder
Expand Down Expand Up @@ -138,7 +139,8 @@ type updator struct {
// Lifecycle Mgr - event processing
//////////////////////////////////////////////////////////////

func NewLifecycleMgr(notifier MetadataNotifier, clusterURL string) (*LifecycleMgr, error) {
func NewLifecycleMgr(notifier MetadataNotifier, clusterURL string,
cinfoClient *common.ClusterInfoClient) (*LifecycleMgr, error) {

cinfo, err := common.FetchNewClusterInfoCache(clusterURL, common.DEFAULT_POOL)
if err != nil {
Expand All @@ -147,6 +149,7 @@ func NewLifecycleMgr(notifier MetadataNotifier, clusterURL string) (*LifecycleMg

mgr := &LifecycleMgr{repo: nil,
cinfo: cinfo,
cinfoClient: cinfoClient,
notifier: notifier,
clusterURL: clusterURL,
incomings: make(chan *requestHolder, 100000),
Expand Down Expand Up @@ -3102,17 +3105,22 @@ func (m *LifecycleMgr) getServiceMap() (*client.ServiceMap, error) {
func (m *LifecycleMgr) getBucketUUID(bucket string) (string, error) {
count := 0
RETRY:
uuid, err := common.GetBucketUUID(m.clusterURL, bucket)
if err != nil && count < 5 {
cinfo := m.cinfoClient.GetClusterInfoCache()
cinfo.RLock()
uuid := cinfo.GetBucketUUID(bucket)
if uuid == common.BUCKET_UUID_NIL && count < 5 {
count++
cinfo.RUnlock()
time.Sleep(time.Duration(100) * time.Millisecond)
// Refresh cluster info cache
err := cinfo.FetchWithLock()
if err != nil {
return common.BUCKET_UUID_NIL, err
}
goto RETRY
}

if err != nil {
return common.BUCKET_UUID_NIL, err
}

defer cinfo.RUnlock()
return uuid, nil
}

Expand Down
18 changes: 9 additions & 9 deletions secondary/manager/manager.go
Expand Up @@ -143,9 +143,16 @@ func NewIndexManagerInternal(config common.Config, storageMode common.StorageMod
return nil, err
}

// Initialize LifecycleMgr.
mgr.clusterURL = config["clusterAddr"].String()
lifecycleMgr, err := NewLifecycleMgr(nil, mgr.clusterURL)
cic, err := common.NewClusterInfoClient(mgr.clusterURL, common.DEFAULT_POOL, config)
if err != nil {
mgr.Close()
return nil, err
}
mgr.cinfoClient = cic

// Initialize LifecycleMgr.
lifecycleMgr, err := NewLifecycleMgr(nil, mgr.clusterURL, mgr.cinfoClient)
if err != nil {
mgr.Close()
return nil, err
Expand All @@ -160,13 +167,6 @@ func NewIndexManagerInternal(config common.Config, storageMode common.StorageMod
os.Mkdir(mgr.basepath, 0755)
mgr.repoName = filepath.Join(mgr.basepath, gometaC.REPOSITORY_NAME)

cic, err := common.NewClusterInfoClient(mgr.clusterURL, common.DEFAULT_POOL, config)
if err != nil {
mgr.Close()
return nil, err
}
mgr.cinfoClient = cic

cinfo := cic.GetClusterInfoCache()
cinfo.RLock()
defer cinfo.RUnlock()
Expand Down

0 comments on commit c39f4bd

Please sign in to comment.