mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-05 20:07:46 +00:00
mgmtd, lib: remove batch ids from all messages
Batch IDs are only used to verify that all messages were received and processed by a backend. It's not necessary to do that as we use reliable stream transport - messages can't be dropped or received out of order. This commit also fixes possible race condition that can happen if one backend process messages slower than other backends. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
This commit is contained in:
parent
19bcca4f2e
commit
b3b5951ee7
@ -94,16 +94,14 @@ message BeTxnReply {
|
||||
|
||||
message BeCfgDataCreateReq {
|
||||
required uint64 txn_id = 1;
|
||||
required uint64 batch_id = 2;
|
||||
repeated YangCfgDataReq data_req = 3;
|
||||
required bool end_of_data = 4;
|
||||
repeated YangCfgDataReq data_req = 2;
|
||||
required bool end_of_data = 3;
|
||||
}
|
||||
|
||||
message BeCfgDataCreateReply {
|
||||
required uint64 txn_id = 1;
|
||||
required uint64 batch_id = 2;
|
||||
required bool success = 3;
|
||||
optional string error_if_any = 4;
|
||||
required bool success = 2;
|
||||
optional string error_if_any = 3;
|
||||
}
|
||||
|
||||
message BeCfgDataApplyReq {
|
||||
|
@ -51,9 +51,6 @@ struct mgmt_be_txn_req {
|
||||
|
||||
PREDECL_LIST(mgmt_be_batches);
|
||||
struct mgmt_be_batch_ctx {
|
||||
/* Batch-Id as assigned by MGMTD */
|
||||
uint64_t batch_id;
|
||||
|
||||
struct mgmt_be_txn_req txn_req;
|
||||
|
||||
uint32_t flags;
|
||||
@ -128,37 +125,15 @@ static int mgmt_be_client_send_msg(struct mgmt_be_client *client_ctx,
|
||||
}
|
||||
|
||||
static struct mgmt_be_batch_ctx *
|
||||
mgmt_be_find_batch_by_id(struct mgmt_be_txn_ctx *txn,
|
||||
uint64_t batch_id)
|
||||
mgmt_be_batch_create(struct mgmt_be_txn_ctx *txn)
|
||||
{
|
||||
struct mgmt_be_batch_ctx *batch = NULL;
|
||||
|
||||
FOREACH_BE_TXN_BATCH_IN_LIST (txn, batch) {
|
||||
if (batch->batch_id == batch_id)
|
||||
return batch;
|
||||
}
|
||||
batch = XCALLOC(MTYPE_MGMTD_BE_BATCH, sizeof(struct mgmt_be_batch_ctx));
|
||||
|
||||
return NULL;
|
||||
}
|
||||
mgmt_be_batches_add_tail(&txn->cfg_batches, batch);
|
||||
|
||||
static struct mgmt_be_batch_ctx *
|
||||
mgmt_be_batch_create(struct mgmt_be_txn_ctx *txn, uint64_t batch_id)
|
||||
{
|
||||
struct mgmt_be_batch_ctx *batch = NULL;
|
||||
|
||||
batch = mgmt_be_find_batch_by_id(txn, batch_id);
|
||||
if (!batch) {
|
||||
batch = XCALLOC(MTYPE_MGMTD_BE_BATCH,
|
||||
sizeof(struct mgmt_be_batch_ctx));
|
||||
assert(batch);
|
||||
|
||||
batch->batch_id = batch_id;
|
||||
mgmt_be_batches_add_tail(&txn->cfg_batches, batch);
|
||||
|
||||
MGMTD_BE_CLIENT_DBG("Added new batch-id: %" PRIu64
|
||||
" to transaction",
|
||||
batch_id);
|
||||
}
|
||||
MGMTD_BE_CLIENT_DBG("Added new batch to transaction");
|
||||
|
||||
return batch;
|
||||
}
|
||||
@ -335,8 +310,7 @@ failed:
|
||||
}
|
||||
|
||||
static int mgmt_be_send_cfgdata_create_reply(struct mgmt_be_client *client_ctx,
|
||||
uint64_t txn_id, uint64_t batch_id,
|
||||
bool success,
|
||||
uint64_t txn_id, bool success,
|
||||
const char *error_if_any)
|
||||
{
|
||||
Mgmtd__BeMessage be_msg;
|
||||
@ -344,7 +318,6 @@ static int mgmt_be_send_cfgdata_create_reply(struct mgmt_be_client *client_ctx,
|
||||
|
||||
mgmtd__be_cfg_data_create_reply__init(&cfgdata_reply);
|
||||
cfgdata_reply.txn_id = (uint64_t)txn_id;
|
||||
cfgdata_reply.batch_id = (uint64_t)batch_id;
|
||||
cfgdata_reply.success = success;
|
||||
if (error_if_any)
|
||||
cfgdata_reply.error_if_any = (char *)error_if_any;
|
||||
@ -353,9 +326,8 @@ static int mgmt_be_send_cfgdata_create_reply(struct mgmt_be_client *client_ctx,
|
||||
be_msg.message_case = MGMTD__BE_MESSAGE__MESSAGE_CFG_DATA_REPLY;
|
||||
be_msg.cfg_data_reply = &cfgdata_reply;
|
||||
|
||||
MGMTD_BE_CLIENT_DBG("Sending CFGDATA_CREATE_REPLY txn-id: %" PRIu64
|
||||
" batch-id: %" PRIu64,
|
||||
txn_id, batch_id);
|
||||
MGMTD_BE_CLIENT_DBG("Sending CFGDATA_CREATE_REPLY txn-id: %" PRIu64,
|
||||
txn_id);
|
||||
|
||||
return mgmt_be_client_send_msg(client_ctx, &be_msg);
|
||||
}
|
||||
@ -432,9 +404,8 @@ static int mgmt_be_txn_cfg_prepare(struct mgmt_be_txn_ctx *txn)
|
||||
err_buf[sizeof(err_buf) - 1] = 0;
|
||||
MGMTD_BE_CLIENT_ERR(
|
||||
"Failed to update configs for txn-id: %" PRIu64
|
||||
" batch-id: %" PRIu64
|
||||
" to candidate, err: '%s'",
|
||||
txn->txn_id, batch->batch_id, err_buf);
|
||||
txn->txn_id, err_buf);
|
||||
return -1;
|
||||
}
|
||||
gettimeofday(&edit_nb_cfg_end, NULL);
|
||||
@ -497,9 +468,6 @@ static int mgmt_be_txn_cfg_prepare(struct mgmt_be_txn_ctx *txn)
|
||||
client_ctx->num_prep_nb_cfg++;
|
||||
|
||||
FOREACH_BE_TXN_BATCH_IN_LIST (txn, batch) {
|
||||
mgmt_be_send_cfgdata_create_reply(
|
||||
client_ctx, txn->txn_id, batch->batch_id,
|
||||
error ? false : true, error ? err_buf : NULL);
|
||||
if (!error) {
|
||||
SET_FLAG(batch->flags,
|
||||
MGMTD_BE_BATCH_FLAGS_CFG_PREPARED);
|
||||
@ -508,6 +476,9 @@ static int mgmt_be_txn_cfg_prepare(struct mgmt_be_txn_ctx *txn)
|
||||
}
|
||||
}
|
||||
|
||||
mgmt_be_send_cfgdata_create_reply(client_ctx, txn->txn_id,
|
||||
error ? false : true, error ? err_buf : NULL);
|
||||
|
||||
MGMTD_BE_CLIENT_DBG(
|
||||
"Avg-nb-edit-duration %lu uSec, nb-prep-duration %lu (avg: %lu) uSec, batch size %u",
|
||||
client_ctx->avg_edit_nb_cfg_tm, prep_nb_cfg_tm,
|
||||
@ -524,7 +495,6 @@ static int mgmt_be_txn_cfg_prepare(struct mgmt_be_txn_ctx *txn)
|
||||
*/
|
||||
static int mgmt_be_update_setcfg_in_batch(struct mgmt_be_client *client_ctx,
|
||||
struct mgmt_be_txn_ctx *txn,
|
||||
uint64_t batch_id,
|
||||
Mgmtd__YangCfgDataReq *cfg_req[],
|
||||
int num_req)
|
||||
{
|
||||
@ -533,17 +503,13 @@ static int mgmt_be_update_setcfg_in_batch(struct mgmt_be_client *client_ctx,
|
||||
int index;
|
||||
struct nb_cfg_change *cfg_chg;
|
||||
|
||||
batch = mgmt_be_batch_create(txn, batch_id);
|
||||
if (!batch) {
|
||||
MGMTD_BE_CLIENT_ERR("Batch create failed!");
|
||||
return -1;
|
||||
}
|
||||
batch = mgmt_be_batch_create(txn);
|
||||
assert(batch);
|
||||
|
||||
txn_req = &batch->txn_req;
|
||||
txn_req->event = MGMTD_BE_TXN_PROC_SETCFG;
|
||||
MGMTD_BE_CLIENT_DBG("Created SETCFG request for batch-id: %" PRIu64
|
||||
" txn-id: %" PRIu64 " cfg-items:%d",
|
||||
batch_id, txn->txn_id, num_req);
|
||||
MGMTD_BE_CLIENT_DBG("Created SETCFG request for txn-id: %" PRIu64
|
||||
" cfg-items:%d", txn->txn_id, num_req);
|
||||
|
||||
txn_req->req.set_cfg.num_cfg_changes = num_req;
|
||||
for (index = 0; index < num_req; index++) {
|
||||
@ -577,7 +543,7 @@ static int mgmt_be_update_setcfg_in_batch(struct mgmt_be_client *client_ctx,
|
||||
}
|
||||
|
||||
static int mgmt_be_process_cfgdata_req(struct mgmt_be_client *client_ctx,
|
||||
uint64_t txn_id, uint64_t batch_id,
|
||||
uint64_t txn_id,
|
||||
Mgmtd__YangCfgDataReq *cfg_req[],
|
||||
int num_req, bool end_of_data)
|
||||
{
|
||||
@ -587,8 +553,7 @@ static int mgmt_be_process_cfgdata_req(struct mgmt_be_client *client_ctx,
|
||||
if (!txn)
|
||||
goto failed;
|
||||
|
||||
mgmt_be_update_setcfg_in_batch(client_ctx, txn, batch_id, cfg_req,
|
||||
num_req);
|
||||
mgmt_be_update_setcfg_in_batch(client_ctx, txn, cfg_req, num_req);
|
||||
|
||||
if (txn && end_of_data) {
|
||||
MGMTD_BE_CLIENT_DBG("End of data; CFG_PREPARE_REQ processing");
|
||||
@ -719,13 +684,11 @@ static int mgmt_be_client_handle_msg(struct mgmt_be_client *client_ctx,
|
||||
break;
|
||||
case MGMTD__BE_MESSAGE__MESSAGE_CFG_DATA_REQ:
|
||||
MGMTD_BE_CLIENT_DBG("Got CFG_DATA_REQ txn-id: %" PRIu64
|
||||
" batch-id: %" PRIu64 " end-of-data %u",
|
||||
" end-of-data %u",
|
||||
be_msg->cfg_data_req->txn_id,
|
||||
be_msg->cfg_data_req->batch_id,
|
||||
be_msg->cfg_data_req->end_of_data);
|
||||
mgmt_be_process_cfgdata_req(
|
||||
client_ctx, be_msg->cfg_data_req->txn_id,
|
||||
be_msg->cfg_data_req->batch_id,
|
||||
be_msg->cfg_data_req->data_req,
|
||||
be_msg->cfg_data_req->n_data_req,
|
||||
be_msg->cfg_data_req->end_of_data);
|
||||
|
@ -379,9 +379,8 @@ mgmt_be_adapter_handle_msg(struct mgmt_be_client_adapter *adapter,
|
||||
case MGMTD__BE_MESSAGE__MESSAGE_CFG_DATA_REPLY:
|
||||
MGMTD_BE_ADAPTER_DBG(
|
||||
"Got CFGDATA_REPLY from '%s' txn-id %" PRIx64
|
||||
" batch-id %" PRIu64 " err:'%s'",
|
||||
adapter->name, be_msg->cfg_data_reply->txn_id,
|
||||
be_msg->cfg_data_reply->batch_id,
|
||||
" err:'%s'", adapter->name,
|
||||
be_msg->cfg_data_reply->txn_id,
|
||||
be_msg->cfg_data_reply->error_if_any
|
||||
? be_msg->cfg_data_reply->error_if_any
|
||||
: "None");
|
||||
@ -390,7 +389,6 @@ mgmt_be_adapter_handle_msg(struct mgmt_be_client_adapter *adapter,
|
||||
*/
|
||||
mgmt_txn_notify_be_cfgdata_reply(
|
||||
be_msg->cfg_data_reply->txn_id,
|
||||
be_msg->cfg_data_reply->batch_id,
|
||||
be_msg->cfg_data_reply->success,
|
||||
be_msg->cfg_data_reply->error_if_any, adapter);
|
||||
break;
|
||||
@ -461,7 +459,7 @@ int mgmt_be_send_txn_req(struct mgmt_be_client_adapter *adapter,
|
||||
}
|
||||
|
||||
int mgmt_be_send_cfgdata_req(struct mgmt_be_client_adapter *adapter,
|
||||
uint64_t txn_id, uint64_t batch_id,
|
||||
uint64_t txn_id,
|
||||
Mgmtd__YangCfgDataReq **cfgdata_reqs,
|
||||
size_t num_reqs, bool end_of_data)
|
||||
{
|
||||
@ -469,7 +467,6 @@ int mgmt_be_send_cfgdata_req(struct mgmt_be_client_adapter *adapter,
|
||||
Mgmtd__BeCfgDataCreateReq cfgdata_req;
|
||||
|
||||
mgmtd__be_cfg_data_create_req__init(&cfgdata_req);
|
||||
cfgdata_req.batch_id = batch_id;
|
||||
cfgdata_req.txn_id = txn_id;
|
||||
cfgdata_req.data_req = cfgdata_reqs;
|
||||
cfgdata_req.n_data_req = num_reqs;
|
||||
@ -481,8 +478,8 @@ int mgmt_be_send_cfgdata_req(struct mgmt_be_client_adapter *adapter,
|
||||
|
||||
MGMTD_BE_ADAPTER_DBG(
|
||||
"Sending CFGDATA_CREATE_REQ to '%s' txn-id: %" PRIu64
|
||||
" batch-id: %" PRIu64,
|
||||
adapter->name, txn_id, batch_id);
|
||||
" last: %s",
|
||||
adapter->name, txn_id, end_of_data ? "yes" : "no");
|
||||
|
||||
return mgmt_be_adapter_send_msg(adapter, &be_msg);
|
||||
}
|
||||
|
@ -166,9 +166,6 @@ extern int mgmt_be_send_txn_req(struct mgmt_be_client_adapter *adapter,
|
||||
* txn_id
|
||||
* Unique transaction identifier.
|
||||
*
|
||||
* batch_id
|
||||
* Request batch ID.
|
||||
*
|
||||
* cfgdata_reqs
|
||||
* An array of pointer to Mgmtd__YangCfgDataReq.
|
||||
*
|
||||
@ -182,7 +179,7 @@ extern int mgmt_be_send_txn_req(struct mgmt_be_client_adapter *adapter,
|
||||
* 0 on success, -1 on failure.
|
||||
*/
|
||||
extern int mgmt_be_send_cfgdata_req(struct mgmt_be_client_adapter *adapter,
|
||||
uint64_t txn_id, uint64_t batch_id,
|
||||
uint64_t txn_id,
|
||||
Mgmtd__YangCfgDataReq **cfgdata_reqs,
|
||||
size_t num_reqs, bool end_of_data);
|
||||
|
||||
|
259
mgmtd/mgmt_txn.c
259
mgmtd/mgmt_txn.c
@ -77,7 +77,6 @@ PREDECL_LIST(mgmt_txn_batches);
|
||||
|
||||
struct mgmt_txn_be_cfg_batch {
|
||||
struct mgmt_txn_ctx *txn;
|
||||
uint64_t batch_id;
|
||||
enum mgmt_be_client_id be_id;
|
||||
struct mgmt_be_client_adapter *be_adapter;
|
||||
Mgmtd__YangCfgDataReq cfg_data[MGMTD_MAX_CFG_CHANGES_IN_BATCH];
|
||||
@ -86,7 +85,6 @@ struct mgmt_txn_be_cfg_batch {
|
||||
Mgmtd__YangDataValue value[MGMTD_MAX_CFG_CHANGES_IN_BATCH];
|
||||
size_t num_cfg_data;
|
||||
int buf_space_left;
|
||||
enum mgmt_commit_phase comm_phase;
|
||||
struct mgmt_txn_batches_item list_linkage;
|
||||
};
|
||||
|
||||
@ -110,6 +108,8 @@ struct mgmt_commit_cfg_req {
|
||||
enum mgmt_commit_phase curr_phase;
|
||||
enum mgmt_commit_phase next_phase;
|
||||
|
||||
enum mgmt_commit_phase be_phase[MGMTD_BE_CLIENT_ID_MAX];
|
||||
|
||||
/*
|
||||
* Set of config changes to commit. This is used only
|
||||
* when changes are NOT to be determined by comparing
|
||||
@ -129,21 +129,12 @@ struct mgmt_commit_cfg_req {
|
||||
/*
|
||||
* List of backend batches for this commit to be validated
|
||||
* and applied at the backend.
|
||||
*
|
||||
* FIXME: Need to re-think this design for the case set of
|
||||
* validators for a given YANG data item is different from
|
||||
* the set of notifiers for the same. We may need to have
|
||||
* separate list of batches for VALIDATE and APPLY.
|
||||
*/
|
||||
struct mgmt_txn_batches_head curr_batches[MGMTD_BE_CLIENT_ID_MAX];
|
||||
struct mgmt_txn_batches_head next_batches[MGMTD_BE_CLIENT_ID_MAX];
|
||||
struct mgmt_txn_batches_head batches[MGMTD_BE_CLIENT_ID_MAX];
|
||||
/*
|
||||
* The last batch added for any backend client. This is always on
|
||||
* 'curr_batches'
|
||||
* The last batch added for any backend client.
|
||||
*/
|
||||
struct mgmt_txn_be_cfg_batch *last_be_cfg_batch[MGMTD_BE_CLIENT_ID_MAX];
|
||||
struct hash *batches;
|
||||
uint64_t next_batch_id;
|
||||
|
||||
struct mgmt_commit_stats *cmt_stats;
|
||||
};
|
||||
@ -276,10 +267,6 @@ static struct mgmt_master *mgmt_txn_mm;
|
||||
static void mgmt_txn_register_event(struct mgmt_txn_ctx *txn,
|
||||
enum mgmt_txn_event event);
|
||||
|
||||
static int
|
||||
mgmt_move_be_commit_to_next_phase(struct mgmt_txn_ctx *txn,
|
||||
struct mgmt_be_client_adapter *adapter);
|
||||
|
||||
static struct mgmt_txn_be_cfg_batch *
|
||||
mgmt_txn_cfg_batch_alloc(struct mgmt_txn_ctx *txn, enum mgmt_be_client_id id,
|
||||
struct mgmt_be_client_adapter *be_adapter)
|
||||
@ -295,7 +282,7 @@ mgmt_txn_cfg_batch_alloc(struct mgmt_txn_ctx *txn, enum mgmt_be_client_id id,
|
||||
MGMTD_TXN_LOCK(txn);
|
||||
assert(txn->commit_cfg_req);
|
||||
mgmt_txn_batches_add_tail(&txn->commit_cfg_req->req.commit_cfg
|
||||
.curr_batches[id],
|
||||
.batches[id],
|
||||
batch);
|
||||
batch->be_adapter = be_adapter;
|
||||
batch->buf_space_left = MGMTD_BE_CFGDATA_MAX_MSG_LEN;
|
||||
@ -303,11 +290,6 @@ mgmt_txn_cfg_batch_alloc(struct mgmt_txn_ctx *txn, enum mgmt_be_client_id id,
|
||||
mgmt_be_adapter_lock(be_adapter);
|
||||
|
||||
txn->commit_cfg_req->req.commit_cfg.last_be_cfg_batch[id] = batch;
|
||||
if (!txn->commit_cfg_req->req.commit_cfg.next_batch_id)
|
||||
txn->commit_cfg_req->req.commit_cfg.next_batch_id++;
|
||||
batch->batch_id = txn->commit_cfg_req->req.commit_cfg.next_batch_id++;
|
||||
hash_get(txn->commit_cfg_req->req.commit_cfg.batches, batch,
|
||||
hash_alloc_intern);
|
||||
|
||||
return batch;
|
||||
}
|
||||
@ -317,15 +299,12 @@ static void mgmt_txn_cfg_batch_free(struct mgmt_txn_be_cfg_batch **batch)
|
||||
size_t indx;
|
||||
struct mgmt_commit_cfg_req *cmtcfg_req;
|
||||
|
||||
MGMTD_TXN_DBG(" freeing batch-id: %" PRIu64 " txn-id %" PRIu64,
|
||||
(*batch)->batch_id, (*batch)->txn->txn_id);
|
||||
MGMTD_TXN_DBG(" freeing batch txn-id %" PRIu64, (*batch)->txn->txn_id);
|
||||
|
||||
assert((*batch)->txn && (*batch)->txn->type == MGMTD_TXN_TYPE_CONFIG);
|
||||
|
||||
cmtcfg_req = &(*batch)->txn->commit_cfg_req->req.commit_cfg;
|
||||
hash_release(cmtcfg_req->batches, *batch);
|
||||
mgmt_txn_batches_del(&cmtcfg_req->curr_batches[(*batch)->be_id], *batch);
|
||||
mgmt_txn_batches_del(&cmtcfg_req->next_batches[(*batch)->be_id], *batch);
|
||||
mgmt_txn_batches_del(&cmtcfg_req->batches[(*batch)->be_id], *batch);
|
||||
|
||||
if ((*batch)->be_adapter)
|
||||
mgmt_be_adapter_unlock(&(*batch)->be_adapter);
|
||||
@ -343,57 +322,13 @@ static void mgmt_txn_cfg_batch_free(struct mgmt_txn_be_cfg_batch **batch)
|
||||
*batch = NULL;
|
||||
}
|
||||
|
||||
static unsigned int mgmt_txn_cfgbatch_hash_key(const void *data)
|
||||
{
|
||||
const struct mgmt_txn_be_cfg_batch *batch = data;
|
||||
|
||||
return jhash2((uint32_t *)&batch->batch_id,
|
||||
sizeof(batch->batch_id) / sizeof(uint32_t), 0);
|
||||
}
|
||||
|
||||
static bool mgmt_txn_cfgbatch_hash_cmp(const void *d1, const void *d2)
|
||||
{
|
||||
const struct mgmt_txn_be_cfg_batch *batch1 = d1;
|
||||
const struct mgmt_txn_be_cfg_batch *batch2 = d2;
|
||||
|
||||
return (batch1->batch_id == batch2->batch_id);
|
||||
}
|
||||
|
||||
static void mgmt_txn_cfgbatch_hash_free(void *data)
|
||||
{
|
||||
struct mgmt_txn_be_cfg_batch *batch = data;
|
||||
|
||||
mgmt_txn_cfg_batch_free(&batch);
|
||||
}
|
||||
|
||||
static inline struct mgmt_txn_be_cfg_batch *
|
||||
mgmt_txn_cfgbatch_id2ctx(struct mgmt_txn_ctx *txn, uint64_t batch_id)
|
||||
{
|
||||
struct mgmt_txn_be_cfg_batch key = { 0 };
|
||||
struct mgmt_txn_be_cfg_batch *batch;
|
||||
|
||||
if (!txn->commit_cfg_req)
|
||||
return NULL;
|
||||
|
||||
key.batch_id = batch_id;
|
||||
batch = hash_lookup(txn->commit_cfg_req->req.commit_cfg.batches, &key);
|
||||
|
||||
return batch;
|
||||
}
|
||||
|
||||
static void mgmt_txn_cleanup_be_cfg_batches(struct mgmt_txn_ctx *txn,
|
||||
enum mgmt_be_client_id id)
|
||||
{
|
||||
struct mgmt_txn_be_cfg_batch *batch;
|
||||
struct mgmt_txn_batches_head *list;
|
||||
|
||||
list = &txn->commit_cfg_req->req.commit_cfg.curr_batches[id];
|
||||
FOREACH_TXN_CFG_BATCH_IN_LIST (list, batch)
|
||||
mgmt_txn_cfg_batch_free(&batch);
|
||||
|
||||
mgmt_txn_batches_fini(list);
|
||||
|
||||
list = &txn->commit_cfg_req->req.commit_cfg.next_batches[id];
|
||||
list = &txn->commit_cfg_req->req.commit_cfg.batches[id];
|
||||
FOREACH_TXN_CFG_BATCH_IN_LIST (list, batch)
|
||||
mgmt_txn_cfg_batch_free(&batch);
|
||||
|
||||
@ -433,16 +368,13 @@ static struct mgmt_txn_req *mgmt_txn_req_alloc(struct mgmt_txn_ctx *txn,
|
||||
txn_req->req_id, txn->txn_id, txn->session_id);
|
||||
|
||||
FOREACH_MGMTD_BE_CLIENT_ID (id) {
|
||||
txn_req->req.commit_cfg.be_phase[id] =
|
||||
MGMTD_COMMIT_PHASE_PREPARE_CFG;
|
||||
mgmt_txn_batches_init(
|
||||
&txn_req->req.commit_cfg.curr_batches[id]);
|
||||
mgmt_txn_batches_init(
|
||||
&txn_req->req.commit_cfg.next_batches[id]);
|
||||
&txn_req->req.commit_cfg.batches[id]);
|
||||
}
|
||||
|
||||
txn_req->req.commit_cfg.batches =
|
||||
hash_create(mgmt_txn_cfgbatch_hash_key,
|
||||
mgmt_txn_cfgbatch_hash_cmp,
|
||||
"MGMT Config Batches");
|
||||
txn_req->req.commit_cfg.curr_phase = MGMTD_COMMIT_PHASE_PREPARE_CFG;
|
||||
break;
|
||||
case MGMTD_TXN_PROC_GETCFG:
|
||||
txn_req->req.get_data =
|
||||
@ -533,12 +465,6 @@ static void mgmt_txn_req_free(struct mgmt_txn_req **txn_req)
|
||||
* anything more with them
|
||||
*/
|
||||
mgmt_txn_cleanup_be_cfg_batches((*txn_req)->txn, id);
|
||||
if (ccreq->batches) {
|
||||
hash_clean(ccreq->batches,
|
||||
mgmt_txn_cfgbatch_hash_free);
|
||||
hash_free(ccreq->batches);
|
||||
ccreq->batches = NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* If we were in the middle of the state machine then
|
||||
@ -860,49 +786,10 @@ static int mgmt_txn_send_commit_cfg_reply(struct mgmt_txn_ctx *txn,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
mgmt_move_txn_cfg_batch_to_next(struct mgmt_commit_cfg_req *cmtcfg_req,
|
||||
struct mgmt_txn_be_cfg_batch *batch,
|
||||
struct mgmt_txn_batches_head *src_list,
|
||||
struct mgmt_txn_batches_head *dst_list,
|
||||
bool update_commit_phase,
|
||||
enum mgmt_commit_phase to_phase)
|
||||
{
|
||||
mgmt_txn_batches_del(src_list, batch);
|
||||
|
||||
if (update_commit_phase) {
|
||||
MGMTD_TXN_DBG("Move txn-id %" PRIu64 " batch-id: %" PRIu64
|
||||
" from '%s' --> '%s'",
|
||||
batch->txn->txn_id, batch->batch_id,
|
||||
mgmt_commit_phase2str(batch->comm_phase),
|
||||
mgmt_txn_commit_phase_str(batch->txn, false));
|
||||
batch->comm_phase = to_phase;
|
||||
}
|
||||
|
||||
mgmt_txn_batches_add_tail(dst_list, batch);
|
||||
}
|
||||
|
||||
static void mgmt_move_txn_cfg_batches(struct mgmt_txn_ctx *txn,
|
||||
struct mgmt_commit_cfg_req *cmtcfg_req,
|
||||
struct mgmt_txn_batches_head *src_list,
|
||||
struct mgmt_txn_batches_head *dst_list,
|
||||
bool update_commit_phase,
|
||||
enum mgmt_commit_phase to_phase)
|
||||
{
|
||||
struct mgmt_txn_be_cfg_batch *batch;
|
||||
|
||||
FOREACH_TXN_CFG_BATCH_IN_LIST (src_list, batch) {
|
||||
mgmt_move_txn_cfg_batch_to_next(cmtcfg_req, batch, src_list,
|
||||
dst_list, update_commit_phase,
|
||||
to_phase);
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
mgmt_try_move_commit_to_next_phase(struct mgmt_txn_ctx *txn,
|
||||
struct mgmt_commit_cfg_req *cmtcfg_req)
|
||||
{
|
||||
struct mgmt_txn_batches_head *curr_list, *next_list;
|
||||
enum mgmt_be_client_id id;
|
||||
|
||||
MGMTD_TXN_DBG("txn-id: %" PRIu64 ", Phase(current:'%s' next:'%s')",
|
||||
@ -914,7 +801,7 @@ mgmt_try_move_commit_to_next_phase(struct mgmt_txn_ctx *txn,
|
||||
*/
|
||||
FOREACH_MGMTD_BE_CLIENT_ID (id) {
|
||||
if (IS_IDBIT_SET(cmtcfg_req->clients, id) &&
|
||||
mgmt_txn_batches_count(&cmtcfg_req->curr_batches[id])) {
|
||||
cmtcfg_req->be_phase[id] == cmtcfg_req->curr_phase) {
|
||||
/*
|
||||
* There's atleast once client who hasn't moved to
|
||||
* next phase.
|
||||
@ -937,58 +824,12 @@ mgmt_try_move_commit_to_next_phase(struct mgmt_txn_ctx *txn,
|
||||
*/
|
||||
cmtcfg_req->curr_phase = cmtcfg_req->next_phase;
|
||||
cmtcfg_req->next_phase++;
|
||||
MGMTD_TXN_DBG("Move back all config batches for txn-id: %" PRIu64
|
||||
" from next to current branch",
|
||||
txn->txn_id);
|
||||
FOREACH_MGMTD_BE_CLIENT_ID (id) {
|
||||
curr_list = &cmtcfg_req->curr_batches[id];
|
||||
next_list = &cmtcfg_req->next_batches[id];
|
||||
mgmt_move_txn_cfg_batches(txn, cmtcfg_req, next_list, curr_list,
|
||||
false, 0);
|
||||
}
|
||||
|
||||
mgmt_txn_register_event(txn, MGMTD_TXN_PROC_COMMITCFG);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
mgmt_move_be_commit_to_next_phase(struct mgmt_txn_ctx *txn,
|
||||
struct mgmt_be_client_adapter *adapter)
|
||||
{
|
||||
struct mgmt_commit_cfg_req *cmtcfg_req;
|
||||
struct mgmt_txn_batches_head *curr_list, *next_list;
|
||||
|
||||
if (txn->type != MGMTD_TXN_TYPE_CONFIG || !txn->commit_cfg_req)
|
||||
return -1;
|
||||
|
||||
cmtcfg_req = &txn->commit_cfg_req->req.commit_cfg;
|
||||
|
||||
MGMTD_TXN_DBG("Move txn-id: %" PRIu64
|
||||
" for '%s' Phase(current: '%s' next:'%s')",
|
||||
txn->txn_id, adapter->name,
|
||||
mgmt_txn_commit_phase_str(txn, true),
|
||||
mgmt_txn_commit_phase_str(txn, false));
|
||||
|
||||
MGMTD_TXN_DBG("Move all config batches for '%s' from current to next list",
|
||||
adapter->name);
|
||||
curr_list = &cmtcfg_req->curr_batches[adapter->id];
|
||||
next_list = &cmtcfg_req->next_batches[adapter->id];
|
||||
mgmt_move_txn_cfg_batches(txn, cmtcfg_req, curr_list, next_list, true,
|
||||
cmtcfg_req->next_phase);
|
||||
|
||||
MGMTD_TXN_DBG("txn-id: %" PRIu64 ", Phase(current:'%s' next:'%s')",
|
||||
txn->txn_id, mgmt_txn_commit_phase_str(txn, true),
|
||||
mgmt_txn_commit_phase_str(txn, false));
|
||||
|
||||
/*
|
||||
* Check if all clients has moved to next phase or not.
|
||||
*/
|
||||
mgmt_try_move_commit_to_next_phase(txn, cmtcfg_req);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* This is the real workhorse
|
||||
*/
|
||||
@ -1086,8 +927,7 @@ static int mgmt_txn_create_config_batches(struct mgmt_txn_req *txn_req,
|
||||
value;
|
||||
value = NULL;
|
||||
|
||||
MGMTD_TXN_DBG(" -- %s, batch-id: %" PRIu64 " item:%d",
|
||||
adapter->name, batch->batch_id,
|
||||
MGMTD_TXN_DBG(" -- %s, batch item:%d", adapter->name,
|
||||
(int)batch->num_cfg_data);
|
||||
|
||||
batch->num_cfg_data++;
|
||||
@ -1112,6 +952,13 @@ static int mgmt_txn_create_config_batches(struct mgmt_txn_req *txn_req,
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Move all BE clients to create phase */
|
||||
FOREACH_MGMTD_BE_CLIENT_ID(id) {
|
||||
if (IS_IDBIT_SET(cmtcfg_req->clients, id))
|
||||
cmtcfg_req->be_phase[id] =
|
||||
MGMTD_COMMIT_PHASE_TXN_CREATE;
|
||||
}
|
||||
|
||||
cmtcfg_req->next_phase = MGMTD_COMMIT_PHASE_TXN_CREATE;
|
||||
return 0;
|
||||
}
|
||||
@ -1289,7 +1136,6 @@ static int mgmt_txn_send_be_txn_create(struct mgmt_txn_ctx *txn)
|
||||
enum mgmt_be_client_id id;
|
||||
struct mgmt_be_client_adapter *adapter;
|
||||
struct mgmt_commit_cfg_req *cmtcfg_req;
|
||||
struct mgmt_txn_be_cfg_batch *batch;
|
||||
|
||||
assert(txn->type == MGMTD_TXN_TYPE_CONFIG && txn->commit_cfg_req);
|
||||
|
||||
@ -1303,13 +1149,6 @@ static int mgmt_txn_send_be_txn_create(struct mgmt_txn_ctx *txn)
|
||||
"Could not send TXN_CREATE to backend adapter");
|
||||
return -1;
|
||||
}
|
||||
|
||||
FOREACH_TXN_CFG_BATCH_IN_LIST (&txn->commit_cfg_req->req
|
||||
.commit_cfg
|
||||
.curr_batches[id],
|
||||
batch)
|
||||
batch->comm_phase =
|
||||
MGMTD_COMMIT_PHASE_TXN_CREATE;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1344,9 +1183,8 @@ static int mgmt_txn_send_be_cfg_data(struct mgmt_txn_ctx *txn,
|
||||
assert(IS_IDBIT_SET(cmtcfg_req->clients, adapter->id));
|
||||
|
||||
indx = 0;
|
||||
num_batches =
|
||||
mgmt_txn_batches_count(&cmtcfg_req->curr_batches[adapter->id]);
|
||||
FOREACH_TXN_CFG_BATCH_IN_LIST (&cmtcfg_req->curr_batches[adapter->id],
|
||||
num_batches = mgmt_txn_batches_count(&cmtcfg_req->batches[adapter->id]);
|
||||
FOREACH_TXN_CFG_BATCH_IN_LIST (&cmtcfg_req->batches[adapter->id],
|
||||
batch) {
|
||||
assert(cmtcfg_req->next_phase == MGMTD_COMMIT_PHASE_SEND_CFG);
|
||||
|
||||
@ -1354,7 +1192,6 @@ static int mgmt_txn_send_be_cfg_data(struct mgmt_txn_ctx *txn,
|
||||
cfg_req.num_reqs = batch->num_cfg_data;
|
||||
indx++;
|
||||
if (mgmt_be_send_cfgdata_req(adapter, txn->txn_id,
|
||||
batch->batch_id,
|
||||
cfg_req.cfgdata_reqs,
|
||||
cfg_req.num_reqs,
|
||||
indx == num_batches)) {
|
||||
@ -1362,20 +1199,15 @@ static int mgmt_txn_send_be_cfg_data(struct mgmt_txn_ctx *txn,
|
||||
txn, MGMTD_INTERNAL_ERROR,
|
||||
"Internal Error! Could not send config data to backend!");
|
||||
MGMTD_TXN_ERR("Could not send CFGDATA_CREATE txn-id: %" PRIu64
|
||||
" batch-id: %" PRIu64 " to client '%s",
|
||||
txn->txn_id, batch->batch_id,
|
||||
adapter->name);
|
||||
" to client '%s", txn->txn_id, adapter->name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
cmtcfg_req->cmt_stats->last_num_cfgdata_reqs++;
|
||||
mgmt_move_txn_cfg_batch_to_next(
|
||||
cmtcfg_req, batch,
|
||||
&cmtcfg_req->curr_batches[adapter->id],
|
||||
&cmtcfg_req->next_batches[adapter->id], true,
|
||||
MGMTD_COMMIT_PHASE_SEND_CFG);
|
||||
}
|
||||
|
||||
cmtcfg_req->be_phase[adapter->id] = MGMTD_COMMIT_PHASE_SEND_CFG;
|
||||
|
||||
/*
|
||||
* This could be the last Backend Client to send CFGDATA_CREATE_REQ to.
|
||||
* Try moving the commit to next phase.
|
||||
@ -1392,7 +1224,6 @@ static int mgmt_txn_send_be_txn_delete(struct mgmt_txn_ctx *txn,
|
||||
&txn->commit_cfg_req->req.commit_cfg;
|
||||
|
||||
assert(txn->type == MGMTD_TXN_TYPE_CONFIG);
|
||||
assert(!mgmt_txn_batches_count(&cmtcfg_req->curr_batches[adapter->id]));
|
||||
|
||||
if (IS_IDBIT_UNSET(cmtcfg_req->clients, adapter->id))
|
||||
return 0;
|
||||
@ -1438,8 +1269,6 @@ static int mgmt_txn_send_be_cfg_apply(struct mgmt_txn_ctx *txn)
|
||||
enum mgmt_be_client_id id;
|
||||
struct mgmt_be_client_adapter *adapter;
|
||||
struct mgmt_commit_cfg_req *cmtcfg_req;
|
||||
struct mgmt_txn_batches_head *batch_list;
|
||||
struct mgmt_txn_be_cfg_batch *batch;
|
||||
|
||||
assert(txn->type == MGMTD_TXN_TYPE_CONFIG && txn->commit_cfg_req);
|
||||
|
||||
@ -1458,7 +1287,6 @@ static int mgmt_txn_send_be_cfg_apply(struct mgmt_txn_ctx *txn)
|
||||
if (!adapter)
|
||||
return -1;
|
||||
|
||||
batch_list = &cmtcfg_req->curr_batches[id];
|
||||
if (mgmt_be_send_cfgapply_req(adapter, txn->txn_id)) {
|
||||
(void)mgmt_txn_send_commit_cfg_reply(
|
||||
txn, MGMTD_INTERNAL_ERROR,
|
||||
@ -1469,9 +1297,6 @@ static int mgmt_txn_send_be_cfg_apply(struct mgmt_txn_ctx *txn)
|
||||
|
||||
UNSET_FLAG(adapter->flags,
|
||||
MGMTD_BE_ADAPTER_FLAGS_CFG_SYNCED);
|
||||
|
||||
FOREACH_TXN_CFG_BATCH_IN_LIST (batch_list, batch)
|
||||
batch->comm_phase = MGMTD_COMMIT_PHASE_APPLY_CFG;
|
||||
}
|
||||
}
|
||||
|
||||
@ -2387,23 +2212,16 @@ int mgmt_txn_notify_be_txn_reply(uint64_t txn_id, bool create, bool success,
|
||||
txn, MGMTD_INTERNAL_ERROR,
|
||||
"Internal error! Failed to initiate transaction at backend!");
|
||||
}
|
||||
} else {
|
||||
/*
|
||||
* Done with TXN_DELETE. Move the backend client to next phase.
|
||||
*/
|
||||
if (false)
|
||||
mgmt_move_be_commit_to_next_phase(txn, adapter);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mgmt_txn_notify_be_cfgdata_reply(uint64_t txn_id, uint64_t batch_id,
|
||||
bool success, char *error_if_any,
|
||||
int mgmt_txn_notify_be_cfgdata_reply(uint64_t txn_id, bool success,
|
||||
char *error_if_any,
|
||||
struct mgmt_be_client_adapter *adapter)
|
||||
{
|
||||
struct mgmt_txn_ctx *txn;
|
||||
struct mgmt_txn_be_cfg_batch *batch;
|
||||
struct mgmt_commit_cfg_req *cmtcfg_req;
|
||||
|
||||
txn = mgmt_txn_id2ctx(txn_id);
|
||||
@ -2414,14 +2232,9 @@ int mgmt_txn_notify_be_cfgdata_reply(uint64_t txn_id, uint64_t batch_id,
|
||||
return -1;
|
||||
cmtcfg_req = &txn->commit_cfg_req->req.commit_cfg;
|
||||
|
||||
batch = mgmt_txn_cfgbatch_id2ctx(txn, batch_id);
|
||||
if (!batch || batch->txn != txn)
|
||||
return -1;
|
||||
|
||||
if (!success) {
|
||||
MGMTD_TXN_ERR("CFGDATA_CREATE_REQ sent to '%s' failed txn-id: %" PRIu64
|
||||
" batch-id %" PRIu64 " err: %s",
|
||||
adapter->name, txn->txn_id, batch->batch_id,
|
||||
" err: %s", adapter->name, txn->txn_id,
|
||||
error_if_any ? error_if_any : "None");
|
||||
mgmt_txn_send_commit_cfg_reply(
|
||||
txn, MGMTD_INTERNAL_ERROR,
|
||||
@ -2432,13 +2245,10 @@ int mgmt_txn_notify_be_cfgdata_reply(uint64_t txn_id, uint64_t batch_id,
|
||||
}
|
||||
|
||||
MGMTD_TXN_DBG("CFGDATA_CREATE_REQ sent to '%s' was successful txn-id: %" PRIu64
|
||||
" batch-id %" PRIu64 " err: %s",
|
||||
adapter->name, txn->txn_id, batch->batch_id,
|
||||
" err: %s", adapter->name, txn->txn_id,
|
||||
error_if_any ? error_if_any : "None");
|
||||
mgmt_move_txn_cfg_batch_to_next(cmtcfg_req, batch,
|
||||
&cmtcfg_req->curr_batches[adapter->id],
|
||||
&cmtcfg_req->next_batches[adapter->id],
|
||||
true, MGMTD_COMMIT_PHASE_APPLY_CFG);
|
||||
|
||||
cmtcfg_req->be_phase[adapter->id] = MGMTD_COMMIT_PHASE_APPLY_CFG;
|
||||
|
||||
mgmt_try_move_commit_to_next_phase(txn, cmtcfg_req);
|
||||
|
||||
@ -2471,10 +2281,7 @@ int mgmt_txn_notify_be_cfg_apply_reply(uint64_t txn_id, bool success,
|
||||
return 0;
|
||||
}
|
||||
|
||||
mgmt_move_txn_cfg_batches(txn, cmtcfg_req,
|
||||
&cmtcfg_req->curr_batches[adapter->id],
|
||||
&cmtcfg_req->next_batches[adapter->id],
|
||||
true, MGMTD_COMMIT_PHASE_TXN_DELETE);
|
||||
cmtcfg_req->be_phase[adapter->id] = MGMTD_COMMIT_PHASE_TXN_DELETE;
|
||||
|
||||
/*
|
||||
* All configuration for the specific backend has been applied.
|
||||
|
@ -206,8 +206,8 @@ mgmt_txn_notify_be_txn_reply(uint64_t txn_id, bool create, bool success,
|
||||
* Reply to backend adapater with config data create request.
|
||||
*/
|
||||
extern int
|
||||
mgmt_txn_notify_be_cfgdata_reply(uint64_t txn_id, uint64_t batch_id,
|
||||
bool success, char *error_if_any,
|
||||
mgmt_txn_notify_be_cfgdata_reply(uint64_t txn_id, bool success,
|
||||
char *error_if_any,
|
||||
struct mgmt_be_client_adapter *adapter);
|
||||
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user