Skip to content
This repository has been archived by the owner on May 21, 2024. It is now read-only.

Add ecu_version_report counter for primary #1451

Merged
merged 1 commit into from
Nov 22, 2019
Merged

Add ecu_version_report counter for primary #1451

merged 1 commit into from
Nov 22, 2019

Conversation

xcheng-here
Copy link
Contributor

According to the standard of Uptane, add counter for
ECU version report. Currently, only added for primary.
It's name in the manifest is "report_counter", in the
payload of primary ecu version report.

Signed-off-by: cheng.xiang ext-cheng.xiang@here.com

@xcheng-here
Copy link
Contributor Author

Ah, I missed scripts for database migration and rollback. And I didn't test all of the test cases before push it, only tested the case I modified. So stupid.

Copy link
Collaborator

@pattivacek pattivacek left a comment

Choose a reason for hiding this comment

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

On the whole, looks like it's on the right track to me. You will need to add forward and backwards migrations, though.

A few tiny issues:

  • For future reference, the github branch name could be formatted a bit more nicely. See https://github.com/advancedtelematic/aktualizr/blob/master/CONTRIBUTING.md#making-a-pull-request. Including the ticket name is useful, but since no one outside of Here knows what those are, it's useful to specify fix/feat/etc. and a brief useful name, e.g. feat/OTA-3864/version-report-counter. No need to rename this PR, though.
  • Always feel free to select the team as reviewers of your PRs, although you might not get much feedback while the tests are failing.
  • One of the tests is failing due to metadata expiry, but Laurent has fixed it in his PR I just merged. A simple rebase on master should fix that.


storage_->saveEcuReportCounter(Uptane::EcuSerial(ecu_serials[0].first.ToString()), 0);
return true;
}
// Postcondition: "ECUs registered" flag set in the storage
Copy link
Collaborator

Choose a reason for hiding this comment

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

Tiny quibble, but an empty line here between the functions would be good.

// keep the same order as in ecu_serials (start with primary)
auto statement = db.prepareStatement(
"SELECT ecu_serial, counter FROM ecu_report_counter INNER JOIN ecu_serials ON "
"ecu_serials.serial = ecu_serial AND ecu_serials.is_primary = 1 ORDER BY ecu_serials.id;");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why the inner join? Is that just to get the Primary first?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I want this sql help me filter the Primary for now. There is already a loop several lines below, it will put all of the ecu_serial in the vector. So, when I need to implement this feature for all of the ECUs, in this file I only need to modify this line of sql. I'm not very familiar with sql, just learned a few in 15 minutes. Do you think it's not good to use it in this way ?

Copy link
Collaborator

@pattivacek pattivacek Nov 19, 2019

Choose a reason for hiding this comment

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

Now I get it. I still think the ecu_serials.serial = ecu_serial AND ecu_serials.is_primary = 1 is unnecessary, though. You might as well get everything, and ordering by ecu_serials.id should mean the Primary is always first. You can see a similar example in SQLStorage::loadEcuInstallationResults() that does about the same thing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems the SQLStorage::loadEcuInstallationResults() is also using "INNER JOIN". I think the reason might be that we only have "id" column in ecu_serial table, so if we want to order the result by "id", we still have to inner join with ecu_serial table. I think "ORDER BY" might be better than default order of "select".

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry, I misquoted what I thought was unnecessary. I think the INNER JOIN and ORDER BY are fine, it's just the AND ecu_serials.is_primary = 1 that I think is unnecessary.

auto statement = db.prepareStatement<std::string, int64_t>(
"INSERT OR REPLACE INTO ecu_report_counter (ecu_serial, counter) VALUES "
"(?,?);",
ecu_serial.ToString(), counter);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure INSERT OR REPLACE is right here. We should enforce one counter per ECU, so won't we need a WHERE clause? The counter itself doesn't need to be unique.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't use WHERE because I also use this function in initializer, when it's an empty table. After initialization, every call of this function should use an existing ecu_serial from database, so there will be only one line for each ecu in this ecu_report_counter table.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Okay, I think this was my mistake. I'm out of practice with SQL! Looking at other examples, this looks fine.

@@ -23,3 +23,4 @@ CREATE TABLE ecu_installation_results(ecu_serial TEXT NOT NULL PRIMARY KEY, succ
CREATE TABLE need_reboot(unique_mark INTEGER PRIMARY KEY CHECK (unique_mark = 0), flag INTEGER NOT NULL DEFAULT 0);
CREATE TABLE rollback_migrations(version_from INT PRIMARY KEY, migration TEXT NOT NULL);
CREATE TABLE delegations(meta BLOB NOT NULL, role_name TEXT NOT NULL, UNIQUE(role_name));
CREATE TABLE ecu_report_counter(ecu_serial TEXT NOT NULL PRIMARY KEY, counter INTEGER NOT NULL DEFAULT 0);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Good call to include the ecu_serial already. Once this ticket is good and merged, I think part two will be adding secondary-specific counters, so it'll be nice not to have to do another migration.

if (!storage->loadEcuReportCounter(&ecu_cnt) || (ecu_cnt.size() == 0)) {
LOG_ERROR << "No ECU version report counter, please check the database!";
} else {
primary_ecu_version["report_counter"] = std::to_string(ecu_cnt[0].second + 1);
Copy link
Collaborator

Choose a reason for hiding this comment

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

@simao @jochenschneider If we add the ECU version report counter here, does that look good to you? You can maybe see it better in the test below (https://github.com/advancedtelematic/aktualizr/pull/1451/files#diff-81426acc9fdba515977c8106aaa0eec4R159).

Copy link
Contributor

Choose a reason for hiding this comment

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

Is that field documented somewhere? It is hard to see the context here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Is https://saeljira.it.here.com/browse/OTA-3864 enough context?

But actually, either way it makes sense to make this more obvious. @xcheng-here can you post an example of what a manifest with the counter would look like? You can get it from the logs while running manually or by debugging the test case that uses it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I'd love to have an example.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I uploaded a manifest.txt to the jira case, it's at line 94.

@xcheng-here xcheng-here force-pushed the OTA-3864 branch 2 times, most recently from 8d72990 to ab445d4 Compare November 20, 2019 12:02
@codecov-io
Copy link

codecov-io commented Nov 20, 2019

Codecov Report

Merging #1451 into master will decrease coverage by 0.14%.
The diff coverage is 86.84%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1451      +/-   ##
==========================================
- Coverage   80.45%   80.31%   -0.15%     
==========================================
  Files         183      183              
  Lines       11010    11047      +37     
==========================================
+ Hits         8858     8872      +14     
- Misses       2152     2175      +23
Impacted Files Coverage Δ
src/libaktualizr/storage/invstorage.h 97.56% <ø> (ø) ⬆️
src/libaktualizr/primary/initializer.h 100% <ø> (ø) ⬆️
src/libaktualizr/storage/sqlstorage.h 50% <ø> (ø) ⬆️
src/libaktualizr/primary/sotauptaneclient.cc 88.93% <100%> (+0.08%) ⬆️
src/libaktualizr/primary/initializer.cc 80.64% <81.81%> (-0.05%) ⬇️
src/libaktualizr/storage/sqlstorage.cc 76.45% <86.36%> (-1.36%) ⬇️
src/libaktualizr/storage/sqlstorage_base.cc 78.37% <0%> (-2.03%) ⬇️
src/libaktualizr/storage/sql_utils.h 84.5% <0%> (-1.41%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 662aa23...3e6bb34. Read the comment docs.

According to the standard of Uptane, add counter for
ECU version report. Currently, only added for primary.
It's name in the manifest is "report_counter", in the
payload of primary ecu version report.

Signed-off-by: cheng.xiang <ext-cheng.xiang@here.com>
Copy link
Collaborator

@pattivacek pattivacek left a comment

Choose a reason for hiding this comment

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

Looks good, thanks! The Travis failure is bogus; the tests passed.

@jochenschneider @simao how hard would it be to start checking for this counter?

@pattivacek pattivacek merged commit 5b09647 into master Nov 22, 2019
@pattivacek pattivacek deleted the OTA-3864 branch November 22, 2019 08:33
@jochenschneider
Copy link
Contributor

jochenschneider commented Nov 22, 2019

You mean checking that it increases? That wouldn't be rocket science. It's just that we are still working on the new version of the director and would preferably implement it there.

@pattivacek
Copy link
Collaborator

You mean checking that it increases? That wouldn't be rocket science. It's just that we are still working on the new version of the director and would preferably implement it there.

Sounds fine. I'd like to also implement this counter for secondaries as well, but I'd like to make sure we have this figured out with the backend side of things before we get too far ahead of ourselves on the embedded side. We can be patient for now, though. :)

@pattivacek
Copy link
Collaborator

It's just that we are still working on the new version of the director and would preferably implement it there.

Should I make a ticket for the BE to capture that work?

@jochenschneider
Copy link
Contributor

That sounds like a good idea. Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants