Skip to content

Commit

Permalink
[xds_client_lock] rename locked
Browse files Browse the repository at this point in the history
  • Loading branch information
menghanl committed Apr 29, 2022
1 parent a428cd3 commit 8a36f55
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
18 changes: 9 additions & 9 deletions xds/internal/xdsclient/authority.go
Expand Up @@ -27,7 +27,7 @@ import (
"google.golang.org/grpc/xds/internal/xdsclient/xdsresource"
)

// findAuthority returns the authority for this name. If it doesn't already
// findAuthorityLocked returns the authority for this name. If it doesn't already
// exist, one will be created.
//
// Note that this doesn't always create new authority. authorities with the same
Expand All @@ -37,7 +37,7 @@ import (
// authority, without holding c.authorityMu.
//
// Caller must not hold c.authorityMu.
func (c *clientImpl) findAuthority(n *xdsresource.Name) (_ *authority, unref func(), _ error) {
func (c *clientImpl) findAuthorityLocked(n *xdsresource.Name) (_ *authority, unref func(), _ error) {
scheme, authority := n.Scheme, n.Authority

c.authorityMu.Lock()
Expand All @@ -55,7 +55,7 @@ func (c *clientImpl) findAuthority(n *xdsresource.Name) (_ *authority, unref fun
config = cfg.XDSServer
}

a, err := c.newAuthority(config)
a, err := c.newAuthorityLocked(config)
if err != nil {
return nil, nil, fmt.Errorf("xds: failed to connect to the control plane for authority %q: %v", authority, err)
}
Expand All @@ -70,17 +70,17 @@ func (c *clientImpl) findAuthority(n *xdsresource.Name) (_ *authority, unref fun
//
// unref() will be done when the watch is canceled.
a.ref()
return a, func() { c.unrefAuthority(a) }, nil
return a, func() { c.unrefAuthorityLocked(a) }, nil
}

// newAuthority creates a new authority for the config. But before that, it
// newAuthorityLocked creates a new authority for the config. But before that, it
// checks the cache to see if an authority for this config already exists.
//
// The caller must take a reference of the returned authority before using, and
// unref afterwards.
//
// caller must hold c.authorityMu
func (c *clientImpl) newAuthority(config *bootstrap.ServerConfig) (_ *authority, retErr error) {
func (c *clientImpl) newAuthorityLocked(config *bootstrap.ServerConfig) (_ *authority, retErr error) {
// First check if there's already an authority for this config. If found, it
// means this authority is used by other watches (could be the same
// authority name, or a different authority name but the same server
Expand Down Expand Up @@ -118,14 +118,14 @@ func (c *clientImpl) newAuthority(config *bootstrap.ServerConfig) (_ *authority,
return ret, nil
}

// unrefAuthority unrefs the authority. It also moves the authority to idle
// unrefAuthorityLocked unrefs the authority. It also moves the authority to idle
// cache if it's ref count is 0.
//
// This function doesn't need to called explicitly. It's called by the returned
// unref from findAuthority().
// unref from findAuthorityLocked().
//
// Caller must not hold c.authorityMu.
func (c *clientImpl) unrefAuthority(a *authority) {
func (c *clientImpl) unrefAuthorityLocked(a *authority) {
c.authorityMu.Lock()
defer c.authorityMu.Unlock()
if a.unref() > 0 {
Expand Down
4 changes: 2 additions & 2 deletions xds/internal/xdsclient/loadreport.go
Expand Up @@ -29,7 +29,7 @@ import (
// load reporting stream.
func (c *clientImpl) ReportLoad(server *bootstrap.ServerConfig) (*load.Store, func()) {
c.authorityMu.Lock()
a, err := c.newAuthority(server)
a, err := c.newAuthorityLocked(server)
c.authorityMu.Unlock()
if err != nil {
c.logger.Infof("xds: failed to connect to the control plane to do load reporting for authority %q: %v", server, err)
Expand All @@ -40,6 +40,6 @@ func (c *clientImpl) ReportLoad(server *bootstrap.ServerConfig) (*load.Store, fu
store, cancelF := a.reportLoad()
return store, func() {
cancelF()
c.unrefAuthority(a)
c.unrefAuthorityLocked(a)
}
}
8 changes: 4 additions & 4 deletions xds/internal/xdsclient/watchers.go
Expand Up @@ -28,7 +28,7 @@ import (
// after the watcher is canceled. The caller needs to handle this case.
func (c *clientImpl) WatchListener(serviceName string, cb func(xdsresource.ListenerUpdate, error)) (cancel func()) {
n := xdsresource.ParseName(serviceName)
a, unref, err := c.findAuthority(n)
a, unref, err := c.findAuthorityLocked(n)
if err != nil {
cb(xdsresource.ListenerUpdate{}, err)
return func() {}
Expand All @@ -47,7 +47,7 @@ func (c *clientImpl) WatchListener(serviceName string, cb func(xdsresource.Liste
// after the watcher is canceled. The caller needs to handle this case.
func (c *clientImpl) WatchRouteConfig(routeName string, cb func(xdsresource.RouteConfigUpdate, error)) (cancel func()) {
n := xdsresource.ParseName(routeName)
a, unref, err := c.findAuthority(n)
a, unref, err := c.findAuthorityLocked(n)
if err != nil {
cb(xdsresource.RouteConfigUpdate{}, err)
return func() {}
Expand All @@ -70,7 +70,7 @@ func (c *clientImpl) WatchRouteConfig(routeName string, cb func(xdsresource.Rout
// after the watcher is canceled. The caller needs to handle this case.
func (c *clientImpl) WatchCluster(clusterName string, cb func(xdsresource.ClusterUpdate, error)) (cancel func()) {
n := xdsresource.ParseName(clusterName)
a, unref, err := c.findAuthority(n)
a, unref, err := c.findAuthorityLocked(n)
if err != nil {
cb(xdsresource.ClusterUpdate{}, err)
return func() {}
Expand All @@ -92,7 +92,7 @@ func (c *clientImpl) WatchCluster(clusterName string, cb func(xdsresource.Cluste
// after the watcher is canceled. The caller needs to handle this case.
func (c *clientImpl) WatchEndpoints(clusterName string, cb func(xdsresource.EndpointsUpdate, error)) (cancel func()) {
n := xdsresource.ParseName(clusterName)
a, unref, err := c.findAuthority(n)
a, unref, err := c.findAuthorityLocked(n)
if err != nil {
cb(xdsresource.EndpointsUpdate{}, err)
return func() {}
Expand Down

0 comments on commit 8a36f55

Please sign in to comment.