Skip to content

Commit 8292549

Browse files
authored
xdsclient: schedule serializer callback from the authority instead of from the xdsChannel (#8498)
This is a small code change that simplifies how a callback is scheduled. The `xdsChannel` will no longer directly access the serializer inside the `authority` type. Instead, the authority type will now handle the scheduling itself. This makes the code cleaner and moves the scheduling logic to where it belongs. RELEASE NOTES: none
1 parent 18ee309 commit 8292549

File tree

2 files changed

+23
-25
lines changed

2 files changed

+23
-25
lines changed

xds/internal/clients/xdsclient/authority.go

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -908,36 +908,36 @@ func (a *authority) close() {
908908
// after sending a discovery request to ensure that resources that were
909909
// unsubscribed (and thus have no watchers) are eventually removed from the
910910
// authority's cache.
911-
//
912-
// This method is only executed in the context of a serializer callback.
913911
func (a *authority) removeUnsubscribedCacheEntries(rType ResourceType) {
914-
resources := a.resources[rType]
915-
if resources == nil {
916-
return
917-
}
912+
a.xdsClientSerializer.TrySchedule(func(context.Context) {
913+
resources := a.resources[rType]
914+
if resources == nil {
915+
return
916+
}
918917

919-
for name, state := range resources {
920-
if len(state.watchers) == 0 {
921-
if a.logger.V(2) {
922-
a.logger.Infof("Removing resource state for %q of type %q as it has no watchers", name, rType.TypeName)
918+
for name, state := range resources {
919+
if len(state.watchers) == 0 {
920+
if a.logger.V(2) {
921+
a.logger.Infof("Removing resource state for %q of type %q as it has no watchers", name, rType.TypeName)
922+
}
923+
delete(resources, name)
923924
}
924-
delete(resources, name)
925925
}
926-
}
927926

928-
if len(resources) == 0 {
929-
if a.logger.V(2) {
930-
a.logger.Infof("Removing resource type %q from cache as it has no more resources", rType.TypeName)
927+
if len(resources) == 0 {
928+
if a.logger.V(2) {
929+
a.logger.Infof("Removing resource type %q from cache as it has no more resources", rType.TypeName)
930+
}
931+
delete(a.resources, rType)
931932
}
932-
delete(a.resources, rType)
933-
}
934933

935-
if len(a.resources) == 0 {
936-
if a.logger.V(2) {
937-
a.logger.Infof("Removing last watch for any resource type, releasing reference to the xdsChannels")
934+
if len(a.resources) == 0 {
935+
if a.logger.V(2) {
936+
a.logger.Infof("Removing last watch for any resource type, releasing reference to the xdsChannels")
937+
}
938+
a.closeXDSChannels()
938939
}
939-
a.closeXDSChannels()
940-
}
940+
})
941941
}
942942

943943
func serviceStatusToProto(serviceStatus xdsresource.ServiceStatus) v3adminpb.ClientResourceStatus {

xds/internal/clients/xdsclient/xdsclient.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -446,9 +446,7 @@ func (cs *channelState) adsResourceRemoveUnsubscribedCacheEntries(rType Resource
446446
defer cs.parent.channelsMu.Unlock()
447447

448448
for authority := range cs.interestedAuthorities {
449-
authority.xdsClientSerializer.TrySchedule(func(context.Context) {
450-
authority.removeUnsubscribedCacheEntries(rType)
451-
})
449+
authority.removeUnsubscribedCacheEntries(rType)
452450
}
453451
}
454452

0 commit comments

Comments
 (0)