MCPcopy Create free account
hub / github.com/couchbase/cbft / handleServerGroupUpdates

Method handleServerGroupUpdates

server_groups.go:82–208  ·  view source on GitHub ↗

handleServerGroupUpdates listens to the server group updates and debounces the updates to minimise the config writes. It reuses the cfg debounce configuration values.

()

Source from the content-addressed store, hash-verified

80// and debounces the updates to minimise the config writes.
81// It reuses the cfg debounce configuration values.
82func (st *serverGroupTracker) handleServerGroupUpdates() {
83 if st.mgr.Cfg() == nil {
84 return
85 }
86
87 // get the config debounce offset and node offset multiplier.
88 offset, nm := st.mgr.GetCfgDeBounceOffsetAndMultiplier()
89
90 // compute the node specific offset from the node index.
91 pos := 1
92 nodeDefs, _ := st.mgr.GetNodeDefs(cbgt.NODE_DEFS_KNOWN, false)
93 if nodeDefs != nil {
94 for _, nodeDef := range nodeDefs.NodeDefs {
95 if nodeDef.UUID == st.mgr.UUID() {
96 break
97 }
98 pos++
99 }
100 }
101
102 dbinterval := nm * pos * offset
103 log.Printf("server_groups: debounce duration: %d MS", dbinterval)
104
105 var resp *streamingPoolResponse
106
107 go func() {
108
109 for {
110
111 resp = <-st.notifCh
112
113 debounceTimeCh := time.After(time.Millisecond * time.Duration(dbinterval))
114 DEBOUNCE_LOOP:
115 for {
116
117 select {
118 case resp = <-st.notifCh:
119 // NOOP upon more updates.
120 case <-debounceTimeCh:
121 break DEBOUNCE_LOOP
122 }
123 }
124
125 if !strings.Contains(resp.ServerGroupsUri, "v=") {
126 log.Printf("server_groups: no rev found %s",
127 resp.ServerGroupsUri)
128 continue
129 }
130
131 // parse the server group revision number.
132 var msgs []string
133 rev := resp.ServerGroupsUri[strings.Index(
134 resp.ServerGroupsUri, "v=")+2:]
135
136 // skip if there is no change in the server group rev numbers.
137 if rev == st.prevRev {
138 continue
139 }

Callers 1

listenMethod · 0.95

Calls 3

getNodeUUIDsFunction · 0.85
fetchServerGroupDetailsFunction · 0.85
IndexMethod · 0.45

Tested by

no test coverage detected