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

KVStore & derived classes: design docs, implementation & configuration #8667

Merged
merged 2 commits into from
Nov 25, 2018

Conversation

davidsaada
Copy link
Contributor

@davidsaada davidsaada commented Nov 7, 2018

Description

This PR implements KVStore, the new Key Value based storage framework. It includes the following:

  • KVStore - Key Value store base class.

Derived classes:

  • TDBStore - Tiny Database store over a flash device
  • FileSystemStore - Key Value store over file system
  • SecureStore - A Security Key Value store implementation over an underlying key value store

Global APIs - A set of APIs to access all KVStore classes in a C style manner.

Configuration framework - Means to generate configurations for the above, covering most of the typical applications.

Device Key adaptations.

Design documents for all of the above.

Implemented by @yossi2le, @offirko, @theamirocohen & myself, supervised by @dannybenor.

Pull request type

[ ] Fix
[ ] Refactor
[ ] Target update
[x] Functionality change
[ ] Docs update
[ ] Test update
[ ] Breaking change

@dannybenor
Copy link

This PR will be updated with small changes while reviewed. We already reviewed internally and therefore I will approve it

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 8, 2018

travis-ci/astyle — Passed, 556 files (+11 files)

Can you run astyle on new added files here? #8591 is addressing storage files in the current codebase, so only new files in this PR should have style fix and we should be good for storage files

Copy link
Contributor

@0xc0170 0xc0170 left a comment

Choose a reason for hiding this comment

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

Initial screen review to provide early feedback

*
* @param partition partition configuration struct.
*/
void deinit_partition(kv_map_entry_t * partition);
Copy link
Contributor

Choose a reason for hiding this comment

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

#if !defined(DOXYGEN_ONLY) for private/protected members/methods in new files? so doxygen is not generated for our public docs (see #8670)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@@ -0,0 +1,388 @@
# Storage configuration
Copy link
Contributor

Choose a reason for hiding this comment

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

design docs - were they reviewed by docs team or we request it now here? Let us know, we will add docs reviewers

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We had an internal review, but not by the docs team. Please add them.

return &fss;
}

FileSystem *_get_filesystem_default(BlockDevice *bd, const char *mount)
Copy link
Contributor

@0xc0170 0xc0170 Nov 8, 2018

Choose a reason for hiding this comment

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

_get_filesystem_default vs _get_fileSystemStore - we follow the former (no camelcase for function names). Similar in other functions in this file, like _calculate_blocksize_match_TDBStore -> _calculate_blocksize_match_tbdstore. or I even noticed _storage_config_TDB_EXTERNAL, please consolidate

(this might be normal in the storage files?)

Copy link
Contributor

Choose a reason for hiding this comment

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

The following cannot be changed cause the calling function will build the correct function name using configuration macro:
_get_filesystem_FAT
_get_filesystem_LITTLE
_get_blockdevice_FLASHIAP
_get_blockdevice_SPIF
_get_blockdevice_QSPIF
_get_blockdevice_DATAFLASH
_get_blockdevice_SD
_storage_config_TDB_INTERNAL
_storage_config_TDB_EXTERNAL
_storage_config_TDB_EXTERNAL_NO_RBP
_storage_config_FILESYSTEM
_storage_config_FILESYSTEM_NO_RBP

the rest I have changed to lower case.

Copy link
Contributor

Choose a reason for hiding this comment

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

That one I have missed but noticed some string macros. How does this work (this function_MACRO) here?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, by design the mbed_lib.json value of default is in lower case.

Copy link
Contributor

Choose a reason for hiding this comment

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

Done.

@davidsaada
Copy link
Contributor Author

Can you run astyle on new added files here?

Done.

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 8, 2018

@AnotherButler There is new API (doxygen) and new design documents here, please review

@davidsaada
Copy link
Contributor Author

Added dependency on #8703 (as without it, TDBStore performance is bad).

* @brief As a singleton, return the single instance of the class.
* This class is a singleton for the following reasons:
* - Ease of use, so you don't have to coordinate instantiations.
* - Lazy instantiation of internal data, (which we can't achieve with simple static classes).
Copy link
Contributor

Choose a reason for hiding this comment

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

Query: Is "lazy instantiation" a common term I haven't heard of, or should we rephrase this?

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's a common term.


### Sequential writes

All writes occur sequentially on the physical storage as records, superseding the previous ones for the same key. Each data record is written right after the last written one. If a key is updated, a new record with this key is written, overriding the previous value of this key. If a key is deleted, a new record with a "deleted" flag is added.
Copy link
Contributor

Choose a reason for hiding this comment

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

A lot of this document is in passive voice, and I'm not sure what's doing the action. What's writing data records? What's updating keys? What's deleting keys? Is it you, the user? Please clarify.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. Rephrased these lines.

Copy link
Contributor

Choose a reason for hiding this comment

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

Your changes look good. I came across a couple design docs I missed in my first round of edits, so I'm finishing those up, and then I'll be finished.

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 22, 2018

^^ @OPpuolitaival Please review the latest test results and help us restarted (make it reported here)

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 22, 2018

Restarted the CI

@mbed-ci
Copy link

mbed-ci commented Nov 22, 2018

Test run: SUCCESS

Summary: 4 of 4 test jobs passed
Build number : 26
Build artifacts
Build logs

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 22, 2018

@ARMmbed/mbed-os-test @davidsaada CI reports 3 failues (check test failed status), tehre are timeouts, like targets did not even start (and only for kvstore tests)
Please review

Exporters timeouted, we will restart now

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 22, 2018

Looks like exporter again time outed for IAR. @mbed-os-test Please review

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 23, 2018

I run locally EV_COG_AD3029LZ | features-storage-tests-kvstore-general_tests_phase_1 for GCC_ARM and IAR - all passing.

@davidsaada
Copy link
Contributor Author

0xc0170 those failures are sporadic, but all appear in our kvstore general test, so we think there's something to it and investigate it now.

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 23, 2018

I restarted tests to confirm there is an issue with EV_COG devices

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 24, 2018

Confirmed the failures, latest CI test run (13h ago)

ARCH_PRO iar_arm / ARCH_PRO-IAR.features-storage-tests-kvstore-general_tests_phase_1.features-storage-tests-kvstore-general_tests_phase_1
EV_COG_AD3029LZ iar_arm / EV_COG_AD3029LZ-IAR.features-storage-tests-kvstore-general_tests_phase_1.features-storage-tests-kvstore-general_tests_phase_1
EV_COG_AD3029LZ arm-none-eabi-gcc / EV_COG_AD3029LZ-GCC_ARM.features-storage-tests-kvstore-general_tests_phase_1.features-storage-tests-kvstore-general_tests_phase_1

@dannybenor
Copy link

The problem we have with this test is related to targets that do not support storage because they do not have any component enabled for block devices. We will continue the investigation tomorrow.

@davidsaada
Copy link
Contributor Author

Pushed an update that may work. It's a long shot which I can't tell whether will work for sure, as I wasn't able to reproduce the problem on ARCH_PRO and have no EV_COG_AD3029LZ to check the fix with on any raas node.

David Saada added 2 commits November 24, 2018 17:43
Implement the following:
KVStore base class
TDBStore class
FileSystemStore class
SecureStore class
Global APIs
Configuration framework
Design documentation
@0xc0170
Copy link
Contributor

0xc0170 commented Nov 24, 2018

CI triggered

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 24, 2018

Looks like it passed testing (the latest update fixed the issue).

@mbed-ci
Copy link

mbed-ci commented Nov 24, 2018

Test run: SUCCESS

Summary: 4 of 4 test jobs passed
Build number : 27
Build artifacts
Build logs

@@ -3504,7 +3504,7 @@
}
},
"DISCO_L475VG_IOT01A": {
"components_add": ["QSPIF"],
"components_add": ["QSPIF", "FLASHIAP"],
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hi
Did you check this new component with this DISCO_L475 target ?
I got all components-storage-blockdevice-component_flashiap-tests FAIL with 5.11.0 release... :-(

Copy link
Contributor

Choose a reason for hiding this comment

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

Please create also a new issue for this

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry about that. We have tested the block device with the general_test under feature/storage/TESTS/blockdevice and it uses get default instance and calculate the correct address and size. The component test fails because the base address and size are not set in the COMPONENT_FLASHIAP mbed_lib target overwrites. I run this with start address set to 0x801A800 and the size to 0xE5800 and it works. @jeromecoutant do you like me to add those to the mbed_lib.json permanently or you have some other numbers you prefer?

Copy link
Contributor

Choose a reason for hiding this comment

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

Second thought that we will change the current implementation of the test and if no parameters will be provided in mbed_lib.app the test will calculate the start address and the size by itself as the get default instance does. Take a look at PR #9268

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

Successfully merging this pull request may close these issues.