mirror of
https://github.com/alibaba/higress.git
synced 2026-06-09 12:47:28 +08:00
refactor registry & add direct service discovery through staticIP or DNS (#261)
This commit is contained in:
@@ -50,8 +50,6 @@ type watcher struct {
|
||||
RegistryType provider.ServiceRegistryType `json:"registry_type"`
|
||||
Status provider.WatcherStatus `json:"status"`
|
||||
serviceRemaind *atomic.Int32
|
||||
updateHandler provider.ServiceUpdateHandler
|
||||
readyHandler provider.ReadyHandler
|
||||
cache memory.Cache
|
||||
mutex *sync.Mutex
|
||||
stop chan struct{}
|
||||
@@ -339,7 +337,7 @@ func (w *watcher) DataChange(eventType Event) bool {
|
||||
Suffix: "zookeeper",
|
||||
RegistryType: w.Type,
|
||||
})
|
||||
w.updateHandler()
|
||||
w.UpdateService()
|
||||
} else if eventType.Action == EventTypeDel {
|
||||
w.seMux.Lock()
|
||||
value, ok := w.serviceEntry[host]
|
||||
@@ -370,7 +368,7 @@ func (w *watcher) DataChange(eventType Event) bool {
|
||||
RegistryType: w.Type,
|
||||
})
|
||||
}
|
||||
w.updateHandler()
|
||||
w.UpdateService()
|
||||
}
|
||||
return true
|
||||
}
|
||||
@@ -580,7 +578,7 @@ func (w *watcher) ChildToServiceEntry(children []string, interfaceName, zkPath s
|
||||
}
|
||||
}
|
||||
w.seMux.Unlock()
|
||||
w.updateHandler()
|
||||
w.UpdateService()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -681,7 +679,7 @@ func (w *watcher) Run() {
|
||||
case <-ticker.C:
|
||||
var needNewFetch bool
|
||||
if w.IsReady() {
|
||||
w.readyHandler(true)
|
||||
w.Ready(true)
|
||||
needNewFetch = true
|
||||
}
|
||||
if firstFetchErr != nil || needNewFetch {
|
||||
@@ -712,15 +710,13 @@ func (w *watcher) Stop() {
|
||||
for key := range w.serviceEntry {
|
||||
w.cache.DeleteServiceEntryWrapper(key)
|
||||
}
|
||||
w.updateHandler()
|
||||
w.UpdateService()
|
||||
w.seMux.Unlock()
|
||||
|
||||
w.stop <- struct{}{}
|
||||
w.Done <- struct{}{}
|
||||
close(w.stop)
|
||||
close(w.Done)
|
||||
w.zkClient.Close()
|
||||
w.readyHandler(false)
|
||||
w.Ready(false)
|
||||
}
|
||||
|
||||
func (w *watcher) IsHealthy() bool {
|
||||
@@ -731,14 +727,6 @@ func (w *watcher) GetRegistryType() string {
|
||||
return w.RegistryType.String()
|
||||
}
|
||||
|
||||
func (w *watcher) AppendServiceUpdateHandler(f func()) {
|
||||
w.updateHandler = f
|
||||
}
|
||||
|
||||
func (w *watcher) ReadyHandler(f func(bool)) {
|
||||
w.readyHandler = f
|
||||
}
|
||||
|
||||
func (w *watcher) IsReady() bool {
|
||||
if w.serviceRemaind == nil {
|
||||
return true
|
||||
|
||||
Reference in New Issue
Block a user