Skip to content

Commit

Permalink
plugin: add max_cores attribute per association
Browse files Browse the repository at this point in the history
Problem: The priority plugin does not store max_cores information
per-association in the plugin, which it will need in order to do
resource tracking across all of an association's running jobs.

Add max_cores to the list of information sent to the priority plugin
per-association.

Add max_cores as an attribute to the Association class so that it can
be stored and accessed per-association in the plugin. Set a default for
this attribute when creating a temporary association in the plugin.

Edit the accounting.cpp unit test to account for the addition of the
new max_cores attribute.
  • Loading branch information
cmoussa1 committed Jan 7, 2025
1 parent 6b4210a commit b23c957
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 10 deletions.
4 changes: 3 additions & 1 deletion src/cmd/flux-account-priority-update.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def bulk_update(path):
for row in cur.execute(
"""SELECT userid, bank, default_bank,
fairshare, max_running_jobs, max_active_jobs,
queues, active, projects, default_project, max_nodes
queues, active, projects, default_project, max_nodes, max_cores
FROM association_table"""
):
# create a JSON payload with the results of the query
Expand All @@ -94,6 +94,7 @@ def bulk_update(path):
"projects": str(row[8]),
"def_project": str(row[9]),
"max_nodes": int(row[10]),
"max_cores": int(row[11]),
}
bulk_user_data.append(single_user_data)

Expand Down Expand Up @@ -159,6 +160,7 @@ def send_instance_owner_info():
"projects": "*",
"def_project": "*",
"max_nodes": 1000000,
"max_cores": 1000000,
}

flux.Flux().rpc(
Expand Down
5 changes: 3 additions & 2 deletions src/plugins/accounting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ json_t* Association::to_json () const
}

// 'o' steals the reference for both held_job_ids and user_queues
json_t *u = json_pack ("{s:s, s:f, s:i, s:i, s:i, s:i,"
" s:o, s:o, s:i, s:o, s:s, s:i, s:i}",
json_t *u = json_pack ("{s:s, s:f, s:i, s:i, s:i, s:i, s:o,"
" s:o, s:i, s:o, s:s, s:i, s:i, s:i}",
"bank_name", bank_name.c_str (),
"fairshare", fairshare,
"max_run_jobs", max_run_jobs,
Expand All @@ -99,6 +99,7 @@ json_t* Association::to_json () const
"projects", user_projects,
"def_project", def_project.c_str (),
"max_nodes", max_nodes,
"max_cores", max_cores,
"active", active);

if (!u)
Expand Down
1 change: 1 addition & 0 deletions src/plugins/accounting.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class Association {
std::vector<std::string> projects; // list of accessible projects
std::string def_project; // default project
int max_nodes; // max num nodes across all running jobs
int max_cores; // max num cores across all running jobs

// methods
json_t* to_json () const; // convert object to JSON string
Expand Down
9 changes: 6 additions & 3 deletions src/plugins/mf_priority.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ static void add_special_association (flux_plugin_t *p, flux_t *h, int userid)
a->active = 1;
a->held_jobs = std::vector<long int>();
a->max_nodes = INT16_MAX;
a->max_cores = INT16_MAX;

if (flux_jobtap_job_aux_set (p,
FLUX_JOBTAP_CURRENT_JOB,
Expand Down Expand Up @@ -277,7 +278,7 @@ static void rec_update_cb (flux_t *h,
void *arg)
{
char *bank, *def_bank, *assoc_queues, *assoc_projects, *def_project = NULL;
int uid, max_running_jobs, max_active_jobs, max_nodes = 0;
int uid, max_running_jobs, max_active_jobs, max_nodes, max_cores = 0;
double fshare = 0.0;
json_t *data, *jtemp = NULL;
json_error_t error;
Expand All @@ -301,7 +302,7 @@ static void rec_update_cb (flux_t *h,

if (json_unpack_ex (el, &error, 0,
"{s:i, s:s, s:s, s:F, s:i,"
" s:i, s:s, s:i, s:s, s:s, s:i}",
" s:i, s:s, s:i, s:s, s:s, s:i, s:i}",
"userid", &uid,
"bank", &bank,
"def_bank", &def_bank,
Expand All @@ -312,7 +313,8 @@ static void rec_update_cb (flux_t *h,
"active", &active,
"projects", &assoc_projects,
"def_project", &def_project,
"max_nodes", &max_nodes) < 0)
"max_nodes", &max_nodes,
"max_cores", &max_cores) < 0)
flux_log (h, LOG_ERR, "mf_priority unpack: %s", error.text);

Association *b;
Expand All @@ -325,6 +327,7 @@ static void rec_update_cb (flux_t *h,
b->active = active;
b->def_project = def_project;
b->max_nodes = max_nodes;
b->max_cores = max_cores;

// split queues comma-delimited string and add it to b->queues vector
b->queues.clear ();
Expand Down
9 changes: 5 additions & 4 deletions src/plugins/test/accounting_test01.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ void add_user_to_map (
a.active,
a.projects,
a.def_project,
a.max_nodes
a.max_nodes,
a.max_cores
};
}

Expand All @@ -67,9 +68,9 @@ void initialize_map (
std::map<int, std::map<std::string, Association>> &users)
{
Association user1 = {"bank_A", 0.5, 5, 0, 7, 0, {},
{}, 0, 1, {"*"}, "*", 2147483647};
{}, 0, 1, {"*"}, "*", 2147483647, 2147483647};
Association user2 = {"bank_A", 0.5, 5, 0, 7, 0, {},
{}, 0, 1, {"*"}, "*", 2147483647};
{}, 0, 1, {"*"}, "*", 2147483647, 2147483647};

add_user_to_map (users, 1001, "bank_A", user1);
users_def_bank[1001] = "bank_A";
Expand Down Expand Up @@ -271,7 +272,7 @@ static void test_check_map_dne_true ()
users_def_bank.clear ();

Association tmp_user = {"DNE", 0.5, 5, 0, 7, 0, {},
{}, 0, 1, {"*"}, "*", 2147483647};
{}, 0, 1, {"*"}, "*", 2147483647, 2147483647};
add_user_to_map (users, 9999, "DNE", tmp_user);
users_def_bank[9999] = "DNE";

Expand Down

0 comments on commit b23c957

Please sign in to comment.