MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / cl_set_state

Function cl_set_state

modules/clusterer/clusterer.c:142–233  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

140}
141
142int cl_set_state(int cluster_id, int node_id, enum cl_node_state state)
143{
144 cluster_info_t *cluster = NULL;
145 node_info_t *node;
146 int ev_actions_required = 1;
147 int new_link_states = 0;
148
149 lock_start_read(cl_list_lock);
150
151 cluster = get_cluster_by_id(cluster_id);
152 if (!cluster) {
153 lock_stop_read(cl_list_lock);
154 LM_ERR("Cluster id [%d] not found\n", cluster_id);
155 return -1;
156 }
157
158 if (node_id != current_id) {
159 node = get_node_by_id(cluster, node_id);
160 if (!node) {
161 lock_stop_read(cl_list_lock);
162 LM_ERR("Node id [%d] not found\n", node_id);
163 return 1;
164 }
165
166 lock_get(node->lock);
167
168 if (state == STATE_DISABLED && node->flags & NODE_STATE_ENABLED)
169 new_link_states = LS_DOWN;
170 else if (state == STATE_ENABLED && !(node->flags & NODE_STATE_ENABLED))
171 new_link_states = LS_RESTART_PINGING;
172
173 if (state == STATE_DISABLED)
174 node->flags &= ~NODE_STATE_ENABLED;
175 else
176 node->flags |= NODE_STATE_ENABLED;
177
178 lock_release(node->lock);
179
180 if (new_link_states == LS_DOWN) {
181 set_link_w_neigh_adv(-1, LS_DOWN, node);
182
183 do_actions_node_ev(cluster, &ev_actions_required, 1);
184 } else if (new_link_states == LS_RESTART_PINGING) {
185 set_link_w_neigh(LS_RESTART_PINGING, node);
186 }
187
188 lock_stop_read(cl_list_lock);
189
190 LM_INFO("Set state: %s for node: %d in cluster: %d\n",
191 state ? "enabled" : "disabled", node_id, cluster_id);
192
193 if (db_mode && update_db_state(cluster_id, node_id, state) < 0)
194 LM_ERR("Failed to update state in clusterer DB for node [%d] cluster [%d]\n",
195 node_id, cluster_id);
196
197 return 0;
198 }
199

Callers 1

clusterer_set_statusFunction · 0.85

Calls 8

get_cluster_by_idFunction · 0.85
get_node_by_idFunction · 0.85
lock_getFunction · 0.85
lock_releaseFunction · 0.85
set_link_w_neigh_advFunction · 0.85
do_actions_node_evFunction · 0.85
set_link_w_neighFunction · 0.85
update_db_stateFunction · 0.85

Tested by

no test coverage detected