3 创建了watcher,但谁来接收并缓存etcd的数据呢?Apiserver使用cacher来接收etcd的事件,cacher也是Storage类型,这里cacher可以理解为是监听etcd的一个实例,cacher针对于某个类型的数据,其cacher通过ListAndWatch()这个方法,向etcd发送watch请求。etcd会将某一类型的数据同步到watchCache这个结构,也就是说,ListAndWatch()将远端数据源源不断同步到cacher结构中来。Cacher的结构如下所示:
- type Cacher struct {
- incomingHWM storage.HighWaterMark
- incoming chan watchCacheEvent
- sync.RWMutex
- // Before accessing the cacher's cache, wait for the ready to be ok.
- // This is necessary to prevent users from accessing structures that are
- // uninitialized or are being repopulated right now.
- // ready needs to be set to false when the cacher is paused or stopped.
- // ready needs to be set to true when the cacher is ready to use after
- // initialization.
- ready *ready
- // Underlying storage.Interface.
- storage storage.Interface
- // Expected type of objects in the underlying cache.
- objectType reflect.Type
- // "sliding window" of recent changes of objects and the current state.
- watchCache *watchCache
- reflector *cache.Reflector
- // Versioner is used to handle resource versions.
- versioner storage.Versioner
- // newFunc is a function that creates new empty object storing a object of type Type.
- newFunc func() runtime.Object
- // indexedTrigger is used for optimizing amount of watchers that needs to process
- // an incoming event.
- indexedTrigger *indexedTriggerFunc
- // watchers is mapping from the value of trigger function that a
- // watcher is interested into the watchers
- watcherIdx int
- watchers indexedWatchers
- // Defines a time budget that can be spend on waiting for not-ready watchers
- // while dispatching event before shutting them down.
- dispatchTimeoutBudget *timeBudget
- // Handling graceful termination.
- stopLock sync.RWMutex
- stopped bool
- stopCh chan struct{}
- stopWg sync.WaitGroup
- clock clock.Clock
- // timer is used to avoid unnecessary allocations in underlying watchers.
- timer *time.Timer
- // dispatching determines whether there is currently dispatching of
- // any event in flight.
- dispatching bool
- // watchersBuffer is a list of watchers potentially interested in currently
- // dispatched event.
- watchersBuffer []*cacheWatcher
- // blockedWatchers is a list of watchers whose buffer is currently full.
- blockedWatchers []*cacheWatcher
- // watchersToStop is a list of watchers that were supposed to be stopped
- // during current dispatching, but stopping was deferred to the end of
- // dispatching that event to avoid race with closing channels in watchers.
- watchersToStop []*cacheWatcher
- // Maintain a timeout queue to send the bookmark event before the watcher times out.
- bookmarkWatchers *watcherBookmarkTimeBuckets
- // watchBookmark feature-gate
- watchBookmarkEnabled bool
- }
(编辑:好传媒网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|