mirror of
https://github.com/emqx/neuron.git
synced 2026-10-29 15:09:11 +08:00
fix conflicts when multiple threads access group config
This commit is contained in:
@@ -104,10 +104,6 @@ static void start_periodic_read(neu_plugin_t * plugin,
|
||||
neu_datatag_id_t *id = (neu_datatag_id_t *) iterator_get(&iter);
|
||||
neu_datatag_t * tag = neu_datatag_tbl_get(plugin->tag_table, *id);
|
||||
|
||||
if (tag == NULL) {
|
||||
// The tag had been deleted by other node
|
||||
continue;
|
||||
}
|
||||
if ((tag->attribute & NEU_ATTRIBUTE_READ) == NEU_ATTRIBUTE_READ) {
|
||||
switch (tag->type) {
|
||||
case NEU_DTYPE_UINT16:
|
||||
@@ -207,11 +203,6 @@ setup_read_resp_data_value(neu_datatag_table_t * tag_table,
|
||||
int result = 0;
|
||||
neu_int_val_t int_val = { 0 };
|
||||
|
||||
if (tag == NULL) {
|
||||
// The tag had been deleted by other node
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((tag->attribute & NEU_ATTRIBUTE_READ) == NEU_ATTRIBUTE_READ) {
|
||||
switch (tag->type) {
|
||||
case NEU_DTYPE_UINT32:
|
||||
@@ -462,7 +453,6 @@ static void tags_periodic_read(nng_aio *aio, void *arg, int code)
|
||||
|
||||
stop_periodic_read(sub_inst->plugin, sub_inst->grp_configs);
|
||||
|
||||
neu_taggrp_cfg_anchor(new_config);
|
||||
if (new_config != NULL) {
|
||||
start_periodic_read(plugin, new_config);
|
||||
}
|
||||
|
||||
@@ -38,7 +38,8 @@ void handle_add_tags(nng_aio *aio)
|
||||
|
||||
REST_PROCESS_HTTP_REQUEST_VALIDATE_JWT(
|
||||
aio, neu_json_add_tags_req_t, neu_json_decode_add_tags_req, {
|
||||
neu_taggrp_config_t *config = neu_system_find_group_config(
|
||||
neu_taggrp_config_t *new_config = NULL;
|
||||
neu_taggrp_config_t *config = neu_system_find_group_config(
|
||||
plugin, req->node_id, req->group_config_name);
|
||||
neu_datatag_table_t *table =
|
||||
neu_system_get_datatags_table(plugin, req->node_id);
|
||||
@@ -51,12 +52,14 @@ void handle_add_tags(nng_aio *aio)
|
||||
}
|
||||
|
||||
if (config == NULL) {
|
||||
config = neu_taggrp_cfg_new(req->group_config_name);
|
||||
neu_taggrp_cfg_set_interval(config, 10000);
|
||||
neu_system_add_group_config(plugin, req->node_id, config);
|
||||
new_config = neu_taggrp_cfg_new(req->group_config_name);
|
||||
neu_taggrp_cfg_set_interval(new_config, 10000);
|
||||
neu_system_add_group_config(plugin, req->node_id, new_config);
|
||||
} else {
|
||||
new_config = neu_taggrp_cfg_clone(config);
|
||||
}
|
||||
|
||||
vector_t * ids = neu_taggrp_cfg_get_datatag_ids(config);
|
||||
vector_t * ids = neu_taggrp_cfg_get_datatag_ids(new_config);
|
||||
neu_err_code_e code = { 0 };
|
||||
|
||||
for (int i = 0; i < req->n_tag; i++) {
|
||||
@@ -86,7 +89,11 @@ void handle_add_tags(nng_aio *aio)
|
||||
}
|
||||
}
|
||||
|
||||
neu_taggrp_cfg_unanchor(config);
|
||||
if (config != NULL) {
|
||||
neu_system_update_group_config(plugin, req->node_id,
|
||||
new_config);
|
||||
}
|
||||
// neu_taggrp_cfg_unanchor(config);
|
||||
|
||||
NEU_JSON_RESPONSE_ERROR(
|
||||
code, { http_response(aio, code, result_error); });
|
||||
@@ -99,7 +106,8 @@ void handle_del_tags(nng_aio *aio)
|
||||
|
||||
REST_PROCESS_HTTP_REQUEST_VALIDATE_JWT(
|
||||
aio, neu_json_del_tags_req_t, neu_json_decode_del_tags_req, {
|
||||
neu_taggrp_config_t *config = neu_system_find_group_config(
|
||||
neu_taggrp_config_t *new_config = NULL;
|
||||
neu_taggrp_config_t *config = neu_system_find_group_config(
|
||||
plugin, req->node_id, req->group_config_name);
|
||||
neu_datatag_table_t *table =
|
||||
neu_system_get_datatags_table(plugin, req->node_id);
|
||||
@@ -111,9 +119,11 @@ void handle_del_tags(nng_aio *aio)
|
||||
return;
|
||||
}
|
||||
|
||||
new_config = neu_taggrp_cfg_clone(config);
|
||||
|
||||
for (int i = 0; i < req->n_id; i++) {
|
||||
if (neu_datatag_tbl_remove(table, req->ids[i]) == 0) {
|
||||
vector_t *ids = neu_taggrp_cfg_get_datatag_ids(config);
|
||||
vector_t *ids = neu_taggrp_cfg_get_datatag_ids(new_config);
|
||||
|
||||
VECTOR_FOR_EACH(ids, iter)
|
||||
{
|
||||
@@ -127,6 +137,8 @@ void handle_del_tags(nng_aio *aio)
|
||||
}
|
||||
}
|
||||
|
||||
neu_system_update_group_config(plugin, req->node_id, new_config);
|
||||
|
||||
NEU_JSON_RESPONSE_ERROR(NEU_ERR_SUCCESS, {
|
||||
http_response(aio, NEU_ERR_SUCCESS, result_error);
|
||||
})
|
||||
|
||||
@@ -130,12 +130,12 @@ neu_taggrp_config_t *neu_taggrp_cfg_clone(neu_taggrp_config_t *src_config)
|
||||
int rv;
|
||||
neu_taggrp_config_t *dst_config;
|
||||
|
||||
if (src_config != NULL) {
|
||||
if (src_config == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
dst_config = neu_taggrp_cfg_new(src_config->config_name);
|
||||
if (dst_config != NULL) {
|
||||
if (dst_config == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user