Skip to content

Commit

Permalink
mgmtd: remove redundant next_phase variable
Browse files Browse the repository at this point in the history
next_phase is always curr_phase + 1. It's not necessary to maintain it
separately.

Signed-off-by: Igor Ryzhov <[email protected]>
  • Loading branch information
idryzhov committed Jan 11, 2024
1 parent 2148f70 commit aee5aa0
Showing 1 changed file with 14 additions and 34 deletions.
48 changes: 14 additions & 34 deletions mgmtd/mgmt_txn.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ struct mgmt_commit_cfg_req {

/* Track commit phases */
enum mgmt_commit_phase curr_phase;
enum mgmt_commit_phase next_phase;

enum mgmt_commit_phase be_phase[MGMTD_BE_CLIENT_ID_MAX];

Expand Down Expand Up @@ -261,15 +260,12 @@ static int mgmt_txn_send_commit_cfg_reply(struct mgmt_txn_ctx *txn,
enum mgmt_result result,
const char *error_if_any);

static inline const char *mgmt_txn_commit_phase_str(struct mgmt_txn_ctx *txn,
bool curr)
static inline const char *mgmt_txn_commit_phase_str(struct mgmt_txn_ctx *txn)
{
if (!txn->commit_cfg_req)
return "None";

return (mgmt_commit_phase2str(
curr ? txn->commit_cfg_req->req.commit_cfg.curr_phase
: txn->commit_cfg_req->req.commit_cfg.next_phase));
return mgmt_commit_phase2str(txn->commit_cfg_req->req.commit_cfg.curr_phase);
}

static void mgmt_txn_lock(struct mgmt_txn_ctx *txn, const char *file, int line);
Expand Down Expand Up @@ -795,9 +791,8 @@ mgmt_try_move_commit_to_next_phase(struct mgmt_txn_ctx *txn,
{
enum mgmt_be_client_id id;

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));
MGMTD_TXN_DBG("txn-id: %" PRIu64 ", Phase '%s'",
txn->txn_id, mgmt_txn_commit_phase_str(txn));

/*
* Check if all clients has moved to next phase or not.
Expand All @@ -817,16 +812,14 @@ mgmt_try_move_commit_to_next_phase(struct mgmt_txn_ctx *txn,
}
}

MGMTD_TXN_DBG("Move entire txn-id: %" PRIu64 " from '%s' to '%s'",
txn->txn_id, mgmt_txn_commit_phase_str(txn, true),
mgmt_txn_commit_phase_str(txn, false));

/*
* If we are here, it means all the clients has moved to next phase.
* So we can move the whole commit to next phase.
*/
cmtcfg_req->curr_phase = cmtcfg_req->next_phase;
cmtcfg_req->next_phase++;
cmtcfg_req->curr_phase++;

MGMTD_TXN_DBG("Move entire txn-id: %" PRIu64 " to phase '%s'",
txn->txn_id, mgmt_txn_commit_phase_str(txn));

mgmt_txn_register_event(txn, MGMTD_TXN_PROC_COMMITCFG);

Expand Down Expand Up @@ -962,7 +955,6 @@ static int mgmt_txn_create_config_batches(struct mgmt_txn_req *txn_req,
MGMTD_COMMIT_PHASE_TXN_CREATE;
}

cmtcfg_req->next_phase = MGMTD_COMMIT_PHASE_TXN_CREATE;
return 0;
}

Expand Down Expand Up @@ -1156,19 +1148,15 @@ static int mgmt_txn_send_be_txn_create(struct mgmt_txn_ctx *txn)
}
}

txn->commit_cfg_req->req.commit_cfg.next_phase =
MGMTD_COMMIT_PHASE_SEND_CFG;

/*
* Dont move the commit to next phase yet. Wait for the TXN_REPLY to
* come back.
*/

MGMTD_TXN_DBG("txn-id: %" PRIu64 " session-id: %" PRIu64
" Phase(Current:'%s', Next: '%s')",
" Phase '%s'",
txn->txn_id, txn->session_id,
mgmt_txn_commit_phase_str(txn, true),
mgmt_txn_commit_phase_str(txn, false));
mgmt_txn_commit_phase_str(txn));

return 0;
}
Expand All @@ -1190,7 +1178,6 @@ static int mgmt_txn_send_be_cfg_data(struct mgmt_txn_ctx *txn,
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);

cfg_req.cfgdata_reqs = batch->cfg_datap;
cfg_req.num_reqs = batch->num_cfg_data;
Expand Down Expand Up @@ -1375,9 +1362,6 @@ static int mgmt_txn_send_be_cfg_apply(struct mgmt_txn_ctx *txn)
}
}

txn->commit_cfg_req->req.commit_cfg.next_phase =
MGMTD_COMMIT_PHASE_TXN_DELETE;

/*
* Dont move the commit to next phase yet. Wait for all VALIDATE_REPLIES
* to come back.
Expand All @@ -1395,10 +1379,9 @@ static void mgmt_txn_process_commit_cfg(struct event *thread)
assert(txn);

MGMTD_TXN_DBG("Processing COMMIT_CONFIG for txn-id: %" PRIu64
" session-id: %" PRIu64 " Phase(Current:'%s', Next: '%s')",
" session-id: %" PRIu64 " Phase '%s'",
txn->txn_id, txn->session_id,
mgmt_txn_commit_phase_str(txn, true),
mgmt_txn_commit_phase_str(txn, false));
mgmt_txn_commit_phase_str(txn));

assert(txn->commit_cfg_req);
cmtcfg_req = &txn->commit_cfg_req->req.commit_cfg;
Expand All @@ -1424,12 +1407,10 @@ static void mgmt_txn_process_commit_cfg(struct event *thread)
* Backend by now.
*/
#ifndef MGMTD_LOCAL_VALIDATIONS_ENABLED
assert(cmtcfg_req->next_phase == MGMTD_COMMIT_PHASE_APPLY_CFG);
MGMTD_TXN_DBG("txn-id: %" PRIu64 " session-id: %" PRIu64
" trigger sending CFG_VALIDATE_REQ to all backend clients",
txn->txn_id, txn->session_id);
#else /* ifndef MGMTD_LOCAL_VALIDATIONS_ENABLED */
assert(cmtcfg_req->next_phase == MGMTD_COMMIT_PHASE_APPLY_CFG);
MGMTD_TXN_DBG("txn-id: %" PRIu64 " session-id: %" PRIu64
" trigger sending CFG_APPLY_REQ to all backend clients",
txn->txn_id, txn->session_id);
Expand Down Expand Up @@ -1465,10 +1446,9 @@ static void mgmt_txn_process_commit_cfg(struct event *thread)
}

MGMTD_TXN_DBG("txn-id:%" PRIu64 " session-id: %" PRIu64
" phase updated to (current:'%s', next: '%s')",
" phase updated to '%s'",
txn->txn_id, txn->session_id,
mgmt_txn_commit_phase_str(txn, true),
mgmt_txn_commit_phase_str(txn, false));
mgmt_txn_commit_phase_str(txn));
}

static void mgmt_init_get_data_reply(struct mgmt_get_data_reply *get_reply)
Expand Down

0 comments on commit aee5aa0

Please sign in to comment.