Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plugin: improve check of internal user/bank map in job.validate #386

Merged
merged 2 commits into from
Sep 14, 2023

Conversation

cmoussa1
Copy link
Member

Problem

As noted in #385, in validate_cb (), the multi-factor priority plugin has a bug where even if it only has the special does-not-exist ("DNE") entries for at least one user/bank (indicating that the plugin has not received any flux-accounting data yet), subsequently submitted jobs by other users get rejected with the "no bank found for user" error message, which is the rejection message typically output when the plugin has valid user/bank data.


This PR adds a helper function to the priority plugin that scans the users map and checks the default bank for each user. As soon as it finds a user/bank with a default bank that is not the special "DNE" entry, it returns false. This helper function is called in the job.validate callback to ensure that the plugin's internal user/bank map contains valid user/bank data before
rejecting a user's job because they don't have a valid entry in the flux-accounting database.

It also adds a small set of tests that exercise this functionality of submitting multiple jobs from multiple users and checking that they are held in state PRIORITY before any data is loaded to the plugin; then, valid data is sent to the plugin and the jobs are checked to confirm that they transition to RUN. It also adds a test to make sure that a user that does not have a valid entry in the flux-accounting DB cannot submit jobs to the plugin.

Fixes #385

@cmoussa1 cmoussa1 added the bug-fix A proposal for something that isn't working label Sep 13, 2023
Copy link
Contributor

@grondo grondo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a quick couple early comments/questions. Haven't fully reviewed yet.

static bool check_map_for_dne_only ()
{
// check if the map only contains DNE entries
bool only_dne_data = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This variable appears to be unused

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, thanks for catching this. I must have missed that when I was moving this block of code to a helper function. Will fix this

// Scan the users map and look at each user's default bank to see if any one
// of them have a valid bank (i.e one that is not "DNE"; if any of the users do
// do have a valid bank, it will return false)
static bool check_map_for_dne_only ()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A really quick thought here before a full review.

If this function instead returned the default bank for a user or DNE if the user has no default bank, would it potentially be useful elsewhere? Also, it might be more clear if the users map was passed as a parameter to the function...

Copy link
Member Author

@cmoussa1 cmoussa1 Sep 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there are a couple of other places where the default bank for a user is queried, but I had actually posted an experimental PR (#371) where the bank lookup was moved to its own helper function. It looks like this:

static bank_info_result get_bank_info (
        std::map<int, std::map<std::string, struct bank_info>>::iterator it,
        int userid,
        char *bank)
{
    std::map<std::string, struct bank_info>::iterator bank_it;

    // make sure user belongs to bank they specified; if no bank was passed in,
    // look up their default bank
    if (bank != NULL) {
        bank_it = it->second.find (std::string (bank));
        if (bank_it == it->second.end ())
            return {INVALID_BANK, bank_it};
    } else {
        bank = const_cast<char*> (users_def_bank[userid].c_str ());
        bank_it = it->second.find (std::string (bank));
        if (bank_it == it->second.end ())
            return {NO_DEFAULT_BANK, bank_it};
    }

    return {BANK_SUCCESS, bank_it};
}

I had originally thought that it would be useful to have functionality like the one proposed in this PR (just scanning the users map for the first non-DNE bank it sees) kept separate, but perhaps it would be better to combine the two? Off the top of my head, maybe in the check where it looks for a default bank, it could add something like:

else {
        bank = const_cast<char*> (users_def_bank[userid].c_str ());
        bank_it = it->second.find (std::string (bank));
+       if (it->second == "DNE")
+           return {DNE_DEFAULT_BANK, bank_it};
        else if (bank_it == it->second.end ())
            return {NO_DEFAULT_BANK, bank_it};
}

Also, it might be more clear if the users map was passed as a parameter to the function...

The users map is a global variable in the plugin. Would it be sufficient to add a comment in this function to mention this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, a comment would definitely help!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just force-pushed up a change to add a comment about both the users and users_def_bank maps since they are both global variables.

@cmoussa1 cmoussa1 force-pushed the issue#385 branch 2 times, most recently from d27c4c6 to 236a728 Compare September 13, 2023 20:17
Copy link
Contributor

@grondo grondo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, this looks good and we should get it merged since it fixes an issue.

@cmoussa1
Copy link
Member Author

Thanks, will set MWP on this shortly!

Problem: In validate_cb (), the multi-factor priority plugin has a bug
where even if it only has the special does-not-exist ("DNE") entries for
at least one user/bank (indicating that the plugin has not received any
flux-accounting data yet), subsequently submitted jobs by other users
get rejected with the "no bank found for user" error message, which is
the rejection message typically output when the plugin has valid
user/bank data.

Add a helper function to the priority plugin that scans the users map
and checks the default bank for each user. As soon as it finds a
user/bank with a default bank that is not the special "DNE" entry,
return false. Otherwise, return true.

Use this helper function in the callback for job.validate to ensure that
the plugin's internal user/bank map contains valid user/bank data before
rejecting a user's job because they don't have a valid entry in the
flux-accounting database.
Problem: the flux-accounting testsuite has no tests that check that
multiple users can submit jobs to the multi-factor priority plugin while
it has no data from the flux-accounting DB and have them be held in
state PRIORITY while the plugin waits for data.

Add some tests that exercise this functionality.
@codecov
Copy link

codecov bot commented Sep 14, 2023

Codecov Report

Merging #386 (2f8b2ff) into master (041c734) will increase coverage by 0.10%.
The diff coverage is 100.00%.

❗ Current head 2f8b2ff differs from pull request most recent head e05a05a. Consider uploading reports for the commit e05a05a to get more accurate results

@@            Coverage Diff             @@
##           master     #386      +/-   ##
==========================================
+ Coverage   81.32%   81.43%   +0.10%     
==========================================
  Files          20       20              
  Lines        1360     1368       +8     
==========================================
+ Hits         1106     1114       +8     
  Misses        254      254              
Files Changed Coverage Δ
src/plugins/mf_priority.cpp 79.80% <100.00%> (+0.41%) ⬆️

@mergify mergify bot merged commit e015c00 into flux-framework:master Sep 14, 2023
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug-fix A proposal for something that isn't working merge-when-passing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

plugin: subsequently-submitted jobs get rejected even when plugin has only "DNE" data
2 participants