func (p *namespace) refresh(changed bool) { // trigger refresh of this pool logging.Infof("Refreshing pool %s", p.name) newpool, err := p.site.client.GetPool(p.name) if err != nil { var client cb.Client logging.Errorf("Error updating pool name %s: Error %v", p.name, err) url := p.site.URL() /* transport := cbauth.WrapHTTPTransport(cb.HTTPTransport, nil) cb.HTTPClient.Transport = transport */ if p.site.CbAuthInit == true { client, err = cb.ConnectWithAuth(url, cbauth.NewAuthHandler(nil)) } else { client, err = cb.Connect(url) } if err != nil { logging.Errorf("Error connecting to URL %s", url) return } // check if the default pool exists newpool, err = client.GetPool(p.name) if err != nil { logging.Errorf("Retry Failed Error updating pool name %s: Error %v", p.name, err) return } p.site.client = client } p.lock.Lock() defer p.lock.Unlock() for name, ks := range p.keyspaceCache { logging.Infof(" Checking keyspace %s", name) _, err := newpool.GetBucket(name) if err != nil { changed = true ks.(*keyspace).deleted = true logging.Errorf(" Error retrieving bucket %s", name) delete(p.keyspaceCache, name) } // Not deleted. Check if GSI indexer is available if ks.(*keyspace).gsiIndexer == nil { ks.(*keyspace).refreshIndexer(p.site.URL(), p.Name()) } } if changed == true { p.setPool(newpool) } }
func initCbAuth(url string) (*cb.Client, error) { transport := cbauth.WrapHTTPTransport(cb.HTTPTransport, nil) cb.HTTPClient.Transport = transport client, err := cb.ConnectWithAuth(url, cbauth.NewAuthHandler(nil)) if err != nil { return nil, err } logging.Infof(" Initialization of cbauth succeeded ") return &client, nil }
func loadNamespace(s *site, name string) (*namespace, errors.Error) { cbpool, err := s.client.GetPool(name) if err != nil { if name == "default" { // if default pool is not available, try reconnecting to the server url := s.URL() var client cb.Client if s.CbAuthInit == true { client, err = cb.ConnectWithAuth(url, cbauth.NewAuthHandler(nil)) } else { client, err = cb.Connect(url) } if err != nil { return nil, errors.NewCbNamespaceNotFoundError(err, "Namespace "+name) } // check if the default pool exists cbpool, err = client.GetPool(name) if err != nil { return nil, errors.NewCbNamespaceNotFoundError(err, "Namespace "+name) } s.client = client } } rv := namespace{ site: s, name: name, cbNamespace: cbpool, keyspaceCache: make(map[string]datastore.Keyspace), } go keepPoolFresh(&rv) return &rv, nil }