dird: add prev and new jobid variables#1499
Conversation
core/src/dird/dird_conf.cc
Outdated
| static char yes[] = "yes"; | ||
| static char no[] = "no"; | ||
|
|
||
| static char str[50]; |
There was a problem hiding this comment.
Is using a static array to store and return the result okay? I copied that from another similar callback, so I'm not sure.
There was a problem hiding this comment.
I don't really like it, because it won't be thread-safe. i.e. if the threads for multiple jobs enter job_code_callback() around the same time, there's a possible data-race on str which may lead to the wrong value being returned.
However, there's no great way to work around this inside the function right now. I guess the best way to proceed would be to remove the requirement for extern "C" and return a std::string instead of a char*.
I'll see if I can make that change easily.
There was a problem hiding this comment.
Alright, thanks for your feedback. I already have a branch where I've refactored this callback to return an std::optional<std::string>, should I merge that into this PR or do you want that somewhere else?
There was a problem hiding this comment.
I've only refactored it up to util.cc#edit_job_codes though (SamuelBoerlin@0b7498a#diff-edeceb51c3de23d07b2d5d9e679d111e1238b74cc870a492143e5283e4386ee9R937-R943), after which point it gets more complicated.
There was a problem hiding this comment.
That looks promising! You can just add it to this PR as it is the refactoring required to implement the feature you're working on.
You could
- drop the
extern "C"everywhere, having C-linkage if you need astd::stringprobably won't help much - return the plain
char*/const char*, compiler will take care of conversion on return
Your solution for edit_job_codes() is probably as good as it gets without refactoring the whole thing. However, for a plain char* snprintf() is better suited than Bsnprintf(), as the latter expects a resizable POOLMEM*.
|
Just realized there seems to already exist a %m variable here: https://github.com/bareos/bareos/blob/master/core/src/filed/fileset.cc#L68-L69 |
arogge
left a comment
There was a problem hiding this comment.
btw. I cannot thank you enough for adding the test for your new feature!
core/src/dird/dird_conf.cc
Outdated
| static char yes[] = "yes"; | ||
| static char no[] = "no"; | ||
|
|
||
| static char str[50]; |
There was a problem hiding this comment.
That looks promising! You can just add it to this PR as it is the refactoring required to implement the feature you're working on.
You could
- drop the
extern "C"everywhere, having C-linkage if you need astd::stringprobably won't help much - return the plain
char*/const char*, compiler will take care of conversion on return
Your solution for edit_job_codes() is probably as good as it gets without refactoring the whole thing. However, for a plain char* snprintf() is better suited than Bsnprintf(), as the latter expects a resizable POOLMEM*.
|
That looks really really good. The only issue I see is the letters you chose. |
|
Thanks! Okay, makes sense. I'll go with |
|
I've also added %m to the docs because that one was undocumented as far as I can tell. |
b7a715f to
5883b45
Compare
|
Sorry for keeping you waiting so long. |
arogge
left a comment
There was a problem hiding this comment.
These changes look great. Thank you for the effort you put into this!
You can fix the CHANGELOG.md conflict by just removing your change in that file, the Bot will take care of that.
Do you have a need to see this in Bareos 22? I think we could backport these changes if you have a need for them to become available in the next Bareos 22 release...
5883b45 to
3d0ada2
Compare
|
Great! I've removed the changelog changes again. |
3d0ada2 to
f5a9472
Compare
Thank you for contributing to the Bareos Project!
This PR adds two new RunScript variables %O and %N which contain the previous and new jobid of a migration/copy job.
Currently there is no convenient way to retrieve this information in RunScripts. This would be useful to e.g. easily archive copied or migrated jobs (especially with always incremental and in combination with #1372):
Please check
If you have any questions or problems, please give a comment in the PR.
Helpful documentation and best practices
Checklist for the reviewer of the PR (will be processed by the Bareos team)
Make sure you check/merge the PR using
devtools/pr-toolto have some simple automated checks run and a proper changelog record added.General
Source code quality
Tests