Skip to content

cats: failed update message when updating all volumes from all pools#1015

Merged
arogge merged 9 commits intobareos:masterfrom
alaaeddineelamri:dev/alaaeddineelamri/master/failed-update-all-volumes-all-pools
Feb 1, 2022
Merged

cats: failed update message when updating all volumes from all pools#1015
arogge merged 9 commits intobareos:masterfrom
alaaeddineelamri:dev/alaaeddineelamri/master/failed-update-all-volumes-all-pools

Conversation

@alaaeddineelamri
Copy link
Contributor

@alaaeddineelamri alaaeddineelamri commented Dec 7, 2021

Description:

When trying to update all volumes from all pools using the update command, while not having any volumes configured, an error message is displayed mentioning that no rows were affected. The behavior is normal, but the message is misplaced. This PR fixes the issue.

Please check

  • Short description and the purpose of this PR is present above this paragraph
  • Your name is present in the AUTHORS file (optional)

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)

General
  • PR name is meaningful
  • Purpose of the PR is understood
  • Separate commit for this PR in the CHANGELOG.md, PR number referenced is same
  • Commit descriptions are understandable and well formatted
Source code quality
  • Source code changes are understandable
  • Variable and function names are meaningful
  • Code comments are correct (logically and spelling)
  • Required documentation changes are present and part of the PR
  • bareos-check-sources --since-merge does not report any problems
  • git status should not report modifications in the source tree after building and testing
Tests
  • Decision taken that a system- or unittest is required (if not, then remove this paragraph)
  • The decision towards a systemtest is reasonable compared to a unittest
  • Testname matches exactly what is being tested
  • Output of the test leads quickly to the origin of the fault

@bruno-at-bareos
Copy link
Contributor

[suggestion] inject a small test ? Like create an empty pool, make a default backup to create a volume in default. change retention time parameter in default then run the command and check retention time changed for previous volumes + no error
This test would have the advantage to trace any error that shouldn't appear, and make sure the calling command is doing something.

@alaaeddineelamri alaaeddineelamri force-pushed the dev/alaaeddineelamri/master/failed-update-all-volumes-all-pools branch 4 times, most recently from 8c97898 to ce4a75f Compare December 16, 2021 16:43
@alaaeddineelamri alaaeddineelamri force-pushed the dev/alaaeddineelamri/master/failed-update-all-volumes-all-pools branch from ce4a75f to 6fdbb8c Compare December 23, 2021 10:14
Copy link
Member

@arogge arogge left a comment

Choose a reason for hiding this comment

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

There's a problem with the CHANGELOG.md and there's potential for some refactoring in UPDATE_DB() that you might consider.

Comment on lines +1007 to +1008
#define UPDATE_DB_NO_AFFECTED_ROWS(jcr, cmd) \
UpdateDB(__FILE__, __LINE__, jcr, cmd, 0)
Copy link
Member

Choose a reason for hiding this comment

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

While this is a lot better than before, the naming is still bad.

Just from the naming I'd guess that UPDATE_DB() runs an update query on the database without any further checks (besides making sure the query did not fail).
For UPDATE_DB_NO_AFFECTED_ROWS() I'd guess it does the same as UPDATE_DB() but won't return the number of affected rows.

I think it would be a lot easier to understand if we changed UPDATE_DB() and BareosDB::UpdateDB() to

  • not to take the additional parameter for minimum affected rows
  • return the number of affected rows as an int and -1 on error.

This way the existing calls to UPDATE_DB() that look like if(UPDATE_DB(...)) would have to be changed to if(UPDATE_DB(...) > 0) (i.e. at least one row was affected) and UPDATE_DB_NO_AFFECTED_ROWS() could be done with either >= 0 or != -1.

Same is probably true for INSERT_DB(), which currently fails if you do a multi-row insert like INSERT INTO x (col_name) VALUES (row1_value), (row2_value), (row3_value); or INSERT INTO y SELECT * FROM z;. So for keeping the existing behaviour you'd need if(INSERT_DB(...) == 1).

@alaaeddineelamri alaaeddineelamri force-pushed the dev/alaaeddineelamri/master/failed-update-all-volumes-all-pools branch 2 times, most recently from 1086a0d to 5fbf69c Compare January 20, 2022 12:39
Copy link
Member

@arogge arogge left a comment

Choose a reason for hiding this comment

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

There are some unneccessary constructs, that should probably be removed.
Other than that I'm not sure how far you want to go with this, but I have another refactoring, that might be worth a shot:
Currently we have a lot of DbLock(this) and DbUnlock(this). Especially in constructs like

DbLock(this);
int retval = SOMETHING_DB(...);
DbUnlock(this);
return retval;

This could be simplified if we had an RAII-Container for DbLock()/DbUnlock() like this:

class DbLocker {
  BareosDb* db_handle_;
 public:
  DbLocker(BareosDb* db_handle) : db_handle_(db_handle) {
    DbLock(db_handle_)
  }
  ~DbLocker() {
    DbUnlock(db_handle_);
  }
}

because then you could refactor the above code into:

DbLocker _{this};
return SOMETHING_DB(...);

As DbLocker will handle unlocking when it goes out-of-scope, we can return without the intermediate variable.

@alaaeddineelamri alaaeddineelamri force-pushed the dev/alaaeddineelamri/master/failed-update-all-volumes-all-pools branch from 5fbf69c to 3dee692 Compare January 27, 2022 14:03
@alaaeddineelamri alaaeddineelamri force-pushed the dev/alaaeddineelamri/master/failed-update-all-volumes-all-pools branch from 3dee692 to 22d6c7f Compare January 28, 2022 11:19
Copy link
Member

@arogge arogge left a comment

Choose a reason for hiding this comment

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

Incredible work!
I admit that the simple change escalated quite a lot, but I think removing 86 gotos and saving around 300 lines of code was probably worth it.

@arogge arogge merged commit d79d2da into bareos:master Feb 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants