Skip to content

Add FileSystemBuffer::Fragment class to support file_system_buffer#20949

Merged
mattklein123 merged 8 commits intoenvoyproxy:mainfrom
ravenblackx:buffer2
Apr 26, 2022
Merged

Add FileSystemBuffer::Fragment class to support file_system_buffer#20949
mattklein123 merged 8 commits intoenvoyproxy:mainfrom
ravenblackx:buffer2

Conversation

@ravenblackx
Copy link
Copy Markdown
Contributor

Signed-off-by: Raven Black ravenblack@dropbox.com

Commit Message: Add FileSystemBuffer::Fragment class to support file_system_buffer
Additional Description: This is a small helper class that manages pieces of stream buffer, moving them to disk/SSD and back to memory asynchronously on demand, with completion callback. Build rule is envoy_cc_library for now so the eventual adding the filter to the build step can be done separately from the implementation.
Risk Level: None yet, not in use.
Testing: 100% unit test coverage. Integration test for the filter in a later PR will also use it.
Docs Changes: n/a
Release Notes: n/a
Platform Specific Features: n/a

Signed-off-by: Raven Black <ravenblack@dropbox.com>
@ravenblackx
Copy link
Copy Markdown
Contributor Author

/assign mattklein123

Signed-off-by: Raven Black <ravenblack@dropbox.com>
Signed-off-by: Raven Black <ravenblack@dropbox.com>
Signed-off-by: Raven Black <ravenblack@dropbox.com>
@ravenblackx
Copy link
Copy Markdown
Contributor Author

/retest

@repokitteh-read-only
Copy link
Copy Markdown

Retrying Azure Pipelines:
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #20949 (comment) was created by @ravenblackx.

see: more, trace.

Copy link
Copy Markdown
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

Nice. Generally LGTM with some small comments. Thank you!

/wait


// Removes the buffer from a memory instance and resets it to size 0.
//
// It is an error to call extract() on a Fragment that is not in memory.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Presumably this returns nullptr? Should this return StatusOr to make precondition failures / programming errors more obvious?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Expanded on the comment to clarify it will cause an exception to call extract on a fragment that is not in memory.

// [this](absl::StatusOr<UpdateFragmentFunction> status_or_update_fragment) {
// if (status_or_update_fragment.ok()) {
// auto update_fragment = status_or_update_fragment.value();
// dispatcher->dispatch([this, update_fragment]() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Where does dispatcher come from in this example? Related to our convo on Slack, this can likely also be gone by the time dispatcher runs. Should some kind of weak_ptr callback system be built into this thing so the caller doesn't need to bother? Or can we at least document more how this is supposed to be used?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I was trying to keep this helper more context-agnostic, but you're right, it is simpler if the helper gets a dispatch function directly. I still offloaded the safety aspect to the caller, because that way Fragment doesn't need to know anything about filters, but taking a dispatch function parameter makes it much simpler than a callback that returns a callback that must be called back!

Fragment::toStorage(AsyncFileHandle file, off_t offset,
std::function<void(absl::StatusOr<UpdateFragmentFunction>)> on_done) {
ASSERT(isMemory());
auto data = dynamic_cast<MemoryFragment*>(data_.get())->extract();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Instead of using dynamic_cast to deal with the state machine, and potential errors show up as nullptr, can you use absl::Variant instead? Then the state machine and possible values are more clear?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Nice suggestion, thanks. Not so keen on more internal implementation details being moved into the header file, which unfortunately is required for variant, but it's better enough to be worth it.

…equiring caller callback call a callback

Signed-off-by: Raven Black <ravenblack@dropbox.com>
Signed-off-by: Raven Black <ravenblack@dropbox.com>
mattklein123
mattklein123 previously approved these changes Apr 26, 2022
Copy link
Copy Markdown
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@mattklein123 mattklein123 enabled auto-merge (squash) April 26, 2022 17:05
@mattklein123
Copy link
Copy Markdown
Member

Can you check tidy CI?

/wait

…convert unique_ptr to shared_ptr to satisfy lambda (!)

Signed-off-by: Raven Black <ravenblack@dropbox.com>
auto-merge was automatically disabled April 26, 2022 18:57

Head branch was pushed to by a user without write access

Signed-off-by: Raven Black <ravenblack@dropbox.com>
@mattklein123 mattklein123 enabled auto-merge (squash) April 26, 2022 19:50
@mattklein123 mattklein123 disabled auto-merge April 26, 2022 23:08
@mattklein123 mattklein123 merged commit e4e6488 into envoyproxy:main Apr 26, 2022
@ravenblackx ravenblackx deleted the buffer2 branch April 27, 2022 05:04
ravenblackx added a commit to ravenblackx/envoy that referenced this pull request Jun 8, 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.

2 participants