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

Sqlite storage double buffering #546

Merged
merged 39 commits into from
Nov 25, 2020
Merged

Conversation

adamdbrw
Copy link
Collaborator

Ongoing work on implementation for #436

@adamdbrw adamdbrw requested a review from a team as a code owner October 26, 2020 16:30
@adamdbrw adamdbrw requested review from thomas-moulard and dabonnie and removed request for a team October 26, 2020 16:30
@adamdbrw
Copy link
Collaborator Author

adamdbrw commented Oct 26, 2020

Current issues:

  • Role of max_cache_size parameter is confused atm. The vector storing messages should likely be removed now.
  • Decision whether buffering is storage implementation specific -> in the abstraction
  • When to open transaction. Also, transaction size/cache size should not be specified by number of messages (this is rather poor way to parametrize for the user)

@adamdbrw adamdbrw marked this pull request as draft October 26, 2020 17:09
Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>
Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>
Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>
Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>
Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>
Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>
Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>
Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>
Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>
Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>
Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>
Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>
Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>
Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>
@emersonknapp
Copy link
Collaborator

emersonknapp commented Oct 29, 2020

Note that cache size is now in bytes rather than number of messages, as of #530 - max_cache_size should probably be equivalent to the transaction size to start, unless you think they should be different?

@pijaro
Copy link
Collaborator

pijaro commented Oct 29, 2020

Yes, we are aware that max_cache_size is now a size in bytes. Currently we use max_cache_size as a limit for each buffer (proposed 2 buffers configuration) whereas transaction size is dynamic but <= max_cache_size, depending on disk write speed (if the disk is throttled with writing data, then transaction_size ~= max_cache_size).

We will update draft soon.

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>
Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>
Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>
Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>
@adamdbrw adamdbrw force-pushed the sqlite_storage_double_buffering branch from 47af55f to 56dfb8d Compare November 2, 2020 14:49
Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>
Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>
…le_buffering

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>
Signed-off-by: Adam Dabrowski <adam.dabrowski@robotec.ai>
Signed-off-by: Adam Dabrowski <adam.dabrowski@robotec.ai>
Signed-off-by: Adam Dabrowski <adam.dabrowski@robotec.ai>
Copy link
Collaborator

@Karsten1987 Karsten1987 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 to me. Let' see what CI has to say:

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

rosbag2_cpp/include/rosbag2_cpp/cache/message_cache.hpp Outdated Show resolved Hide resolved
rosbag2_cpp/include/rosbag2_cpp/cache/message_cache.hpp Outdated Show resolved Hide resolved
rosbag2_cpp/include/rosbag2_cpp/cache/message_cache.hpp Outdated Show resolved Hide resolved
@adamdbrw
Copy link
Collaborator Author

Quite some warnings on Windows, but pretty straightforward to address. We will handle them tomorrow.

adamdbrw and others added 2 commits November 23, 2020 19:26
Signed-off-by: Adam Dabrowski <adam.dabrowski@robotec.ai>
Signed-off-by: Adam Dabrowski <adam.dabrowski@robotec.ai>
@adamdbrw
Copy link
Collaborator Author

adamdbrw commented Nov 24, 2020

@Karsten1987 @mjeronimo, could you re-trigger Windows CI job? Otherwise this is ready to merge as far as I am concerned.

Also, could you allow @pijaro to push branches to rosbag2? Would make it a bit easier for us.

@mjeronimo
Copy link
Contributor

mjeronimo commented Nov 24, 2020

Restarting Windows build
Build Status

@adamdbrw - @Karsten1987 will have to add @pijaro; I'm not an owner of this repo and can't grant permissions.

@adamdbrw
Copy link
Collaborator Author

There are 9 warnings left. They don't look like they are associated with the PR changes though.. or am I wrong?

Copy link
Collaborator

@Karsten1987 Karsten1987 left a comment

Choose a reason for hiding this comment

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

The same windows warnings are currently seen on the nightlies. So yes, there are unrelated.

@mjeronimo I'll leave it up to you to take a pass on this as well.

@mjeronimo
Copy link
Contributor

mjeronimo commented Nov 24, 2020

@adamdbrw I've also confirmed that all of the CMakeLists.txt warnings are also in the nightlies. However, there is one new warning related to the use of the std::accumulate template function from the <numeric> header:

'=': conversion from 'size_t' to '_Ty', possible loss of data

Which, I believe, is referring to the usage here:

https://github.com/ros2/rosbag2/blob/sqlite_storage_double_buffering/rosbag2_cpp/test/rosbag2_cpp/test_message_cache.cpp#L54

The sizes of size_t and uint32_t are different (size_t == 8 bytes, while uint32_t == 4 bytes). I think you can get rid of this one with some slight modifications to the code to use the appropriate types for the accumulation.

Signed-off-by: Adam Dabrowski <adam.dabrowski@robotec.ai>
@adamdbrw
Copy link
Collaborator Author

@mjeronimo: final warning should be fixed now

Signed-off-by: Adam Dabrowski <adam.dabrowski@robotec.ai>
@adamdbrw
Copy link
Collaborator Author

adamdbrw commented Nov 25, 2020

Performance of master vs this PR:

image(4)

Note that both old and new default for cache (--max-cache-size parameter), namely 1MB and 100MB, are included in results. For this test setup, with 100MB to 500MB of messages being written each second, a cache of 1MB is pathological. Note that Recorded Messages % reaches 100% for each row when this PR is combined with #568.

@mjeronimo
Copy link
Contributor

Restarting Windows build to confirm removal of warning:
Build Status

@adamdbrw
Copy link
Collaborator Author

Seems like the numeric warning is gone and only cmake (unrelated) ones remain. Are we good to merge this?

@mjeronimo
Copy link
Contributor

Yes, just confirmed with the latest build that all CMake warnings are also in the nightly build and that the warning is gone. Merging.

@mjeronimo mjeronimo merged commit c38630b into master Nov 25, 2020
@delete-merged-branch delete-merged-branch bot deleted the sqlite_storage_double_buffering branch November 25, 2020 18:58
@emersonknapp
Copy link
Collaborator

Woohoo! Thanks everyone for pushing this through - it looks great, this is a huge improvement for rosbag2.

@y-okumura-isp
Copy link

Are there any plans to backport it to Foxy?

emersonknapp pushed a commit that referenced this pull request Feb 2, 2021
* Double buffers

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* Circular queue and FLUSH option as define

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* Minor naming and lexical fixes.

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* Removed FLUSH_BUFFERS define check.

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* Sqlite3 storage logging fixes.

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* Sqlite3 storage circular buffer with pre allocated memory.

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* Sqlite3 storage buffers moved to shared_ptrs.

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* Uncrustify

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* Moved double buffers to writer

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* Buffer layer reset in seq compression writer in rosbag2 cpp

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* Buffer layer for rosbag2 writer refactor

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* Changed buffers in BufferLayer to std vectors.

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* BufferLayer uncrustify

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* Removed non-applicable test for writer cache.

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* BufferLayer review fixes

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* Rosbag metadata msgs count fixed for BufferLayer

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* Condition variable for buffer layer sync.

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* Fixed buffer locks

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* Buffers in BufferLayer refactored, moved into new class

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* Buffer layer split bags fixed.

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* Storage options include fix in buffer layer header.

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* Mutex around swapping buffers in buffer layer.

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* Fixed cache 0 bug in buffer layer.

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* Minor buffer layer refactor.

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* Counting messages in writer refactored.

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* Changed default cache size to 100Mb and updated parameter description

Signed-off-by: Adam Dabrowski <adam.dabrowski@robotec.ai>

* Applied review remarks:
- significant refactoring: separation of cache classes
- applied suggested improvements
- some renaming
- reduce code duplication that would otherwise increase with cache refactor, between compression and plain writers

Signed-off-by: Adam Dabrowski <adam.dabrowski@robotec.ai>

* Applied review comments
- cache consumer now takes a callback and is independent of storage
- namespace changes, renaming, cleaning
- counting and logging messages by topic

Signed-off-by: Adam Dabrowski <adam.dabrowski@robotec.ai>

* linter

Signed-off-by: Adam Dabrowski <adam.dabrowski@robotec.ai>

* Changes after review: fixing flushing, topic counts, and more

Signed-off-by: Adam Dabrowski <adam.dabrowski@robotec.ai>

* Fix for splitting - flushing state now correctly turns off

Signed-off-by: Adam Dabrowski <adam.dabrowski@robotec.ai>

* cache classes documentation

Signed-off-by: Adam Dabrowski <adam.dabrowski@robotec.ai>

* simplified signature

Signed-off-by: Adam Dabrowski <adam.dabrowski@robotec.ai>

* a couple of tests for cache

Signed-off-by: Adam Dabrowski <adam.dabrowski@robotec.ai>

* address review: explicit constructor and doxygen styling

Signed-off-by: Adam Dabrowski <adam.dabrowski@robotec.ai>

* Windows warnings fix

Signed-off-by: Adam Dabrowski <adam.dabrowski@robotec.ai>

* fixed type mismatch warning on Windows

Signed-off-by: Adam Dabrowski <adam.dabrowski@robotec.ai>

* added minor comment

Signed-off-by: Adam Dabrowski <adam.dabrowski@robotec.ai>

Co-authored-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>
@emersonknapp
Copy link
Collaborator

Are there any plans to backport it to Foxy?

It's not certain yet - the code has diverged significantly in API-breaking ways from the Foxy release that will make it hard to backport this on its own. We're having an active conversation now to potentially backport all of the latest rosbag2 code to Foxy, but this is in its early stages.

emersonknapp pushed a commit that referenced this pull request Feb 17, 2021
* Double buffers

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* Circular queue and FLUSH option as define

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* Minor naming and lexical fixes.

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* Removed FLUSH_BUFFERS define check.

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* Sqlite3 storage logging fixes.

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* Sqlite3 storage circular buffer with pre allocated memory.

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* Sqlite3 storage buffers moved to shared_ptrs.

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* Uncrustify

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* Moved double buffers to writer

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* Buffer layer reset in seq compression writer in rosbag2 cpp

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* Buffer layer for rosbag2 writer refactor

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* Changed buffers in BufferLayer to std vectors.

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* BufferLayer uncrustify

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* Removed non-applicable test for writer cache.

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* BufferLayer review fixes

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* Rosbag metadata msgs count fixed for BufferLayer

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* Condition variable for buffer layer sync.

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* Fixed buffer locks

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* Buffers in BufferLayer refactored, moved into new class

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* Buffer layer split bags fixed.

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* Storage options include fix in buffer layer header.

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* Mutex around swapping buffers in buffer layer.

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* Fixed cache 0 bug in buffer layer.

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* Minor buffer layer refactor.

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* Counting messages in writer refactored.

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* Changed default cache size to 100Mb and updated parameter description

Signed-off-by: Adam Dabrowski <adam.dabrowski@robotec.ai>

* Applied review remarks:
- significant refactoring: separation of cache classes
- applied suggested improvements
- some renaming
- reduce code duplication that would otherwise increase with cache refactor, between compression and plain writers

Signed-off-by: Adam Dabrowski <adam.dabrowski@robotec.ai>

* Applied review comments
- cache consumer now takes a callback and is independent of storage
- namespace changes, renaming, cleaning
- counting and logging messages by topic

Signed-off-by: Adam Dabrowski <adam.dabrowski@robotec.ai>

* linter

Signed-off-by: Adam Dabrowski <adam.dabrowski@robotec.ai>

* Changes after review: fixing flushing, topic counts, and more

Signed-off-by: Adam Dabrowski <adam.dabrowski@robotec.ai>

* Fix for splitting - flushing state now correctly turns off

Signed-off-by: Adam Dabrowski <adam.dabrowski@robotec.ai>

* cache classes documentation

Signed-off-by: Adam Dabrowski <adam.dabrowski@robotec.ai>

* simplified signature

Signed-off-by: Adam Dabrowski <adam.dabrowski@robotec.ai>

* a couple of tests for cache

Signed-off-by: Adam Dabrowski <adam.dabrowski@robotec.ai>

* address review: explicit constructor and doxygen styling

Signed-off-by: Adam Dabrowski <adam.dabrowski@robotec.ai>

* Windows warnings fix

Signed-off-by: Adam Dabrowski <adam.dabrowski@robotec.ai>

* fixed type mismatch warning on Windows

Signed-off-by: Adam Dabrowski <adam.dabrowski@robotec.ai>

* added minor comment

Signed-off-by: Adam Dabrowski <adam.dabrowski@robotec.ai>

Co-authored-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>
Signed-off-by: Emerson Knapp <eknapp@amazon.com>
skudryas pushed a commit to skudryas/rosbag2 that referenced this pull request Mar 12, 2021
* Double buffers

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* Circular queue and FLUSH option as define

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* Minor naming and lexical fixes.

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* Removed FLUSH_BUFFERS define check.

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* Sqlite3 storage logging fixes.

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* Sqlite3 storage circular buffer with pre allocated memory.

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* Sqlite3 storage buffers moved to shared_ptrs.

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* Uncrustify

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* Moved double buffers to writer

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* Buffer layer reset in seq compression writer in rosbag2 cpp

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* Buffer layer for rosbag2 writer refactor

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* Changed buffers in BufferLayer to std vectors.

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* BufferLayer uncrustify

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* Removed non-applicable test for writer cache.

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* BufferLayer review fixes

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* Rosbag metadata msgs count fixed for BufferLayer

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* Condition variable for buffer layer sync.

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* Fixed buffer locks

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* Buffers in BufferLayer refactored, moved into new class

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* Buffer layer split bags fixed.

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* Storage options include fix in buffer layer header.

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* Mutex around swapping buffers in buffer layer.

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* Fixed cache 0 bug in buffer layer.

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* Minor buffer layer refactor.

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* Counting messages in writer refactored.

Signed-off-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>

* Changed default cache size to 100Mb and updated parameter description

Signed-off-by: Adam Dabrowski <adam.dabrowski@robotec.ai>

* Applied review remarks:
- significant refactoring: separation of cache classes
- applied suggested improvements
- some renaming
- reduce code duplication that would otherwise increase with cache refactor, between compression and plain writers

Signed-off-by: Adam Dabrowski <adam.dabrowski@robotec.ai>

* Applied review comments
- cache consumer now takes a callback and is independent of storage
- namespace changes, renaming, cleaning
- counting and logging messages by topic

Signed-off-by: Adam Dabrowski <adam.dabrowski@robotec.ai>

* linter

Signed-off-by: Adam Dabrowski <adam.dabrowski@robotec.ai>

* Changes after review: fixing flushing, topic counts, and more

Signed-off-by: Adam Dabrowski <adam.dabrowski@robotec.ai>

* Fix for splitting - flushing state now correctly turns off

Signed-off-by: Adam Dabrowski <adam.dabrowski@robotec.ai>

* cache classes documentation

Signed-off-by: Adam Dabrowski <adam.dabrowski@robotec.ai>

* simplified signature

Signed-off-by: Adam Dabrowski <adam.dabrowski@robotec.ai>

* a couple of tests for cache

Signed-off-by: Adam Dabrowski <adam.dabrowski@robotec.ai>

* address review: explicit constructor and doxygen styling

Signed-off-by: Adam Dabrowski <adam.dabrowski@robotec.ai>

* Windows warnings fix

Signed-off-by: Adam Dabrowski <adam.dabrowski@robotec.ai>

* fixed type mismatch warning on Windows

Signed-off-by: Adam Dabrowski <adam.dabrowski@robotec.ai>

* added minor comment

Signed-off-by: Adam Dabrowski <adam.dabrowski@robotec.ai>

Co-authored-by: Piotr Jaroszek <piotr.jaroszek@robotec.ai>
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.

6 participants