8000 capsules: tickv: call error cb on append error by bradjc · Pull Request #3489 · tock/tock · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

capsules: tickv: call error cb on append error #3489

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

Merged
merged 4 commits into from
Jul 18, 2023

Conversation

bradjc
Copy link
Contributor
@bradjc bradjc commented Jun 15, 2023

Pull Request Overview

In the tickv capsule we need to signal a callback even if the append fails.

Testing Strategy

Writing to an existing key.

TODO or Help Wanted

n/a

Documentation Updated

  • Updated the relevant files in /docs, or no updates are required.

Formatting

  • Ran make prepush.

@lschuermann lschuermann requested a review from alistair23 June 16, 2023 10:06
@bradjc bradjc mentioned this pull request Jun 16, 2023
2 tasks
alevy
alevy previously approved these changes Jun 16, 2023
match ret {
Ok(tickv::success_codes::SuccessCode::Complete)
| Ok(tickv::success_codes::SuccessCode::Written)
| Err(tickv::error_codes::ErrorCode::BufferTooSmall(_)) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we signal this as a success to the caller?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because on delete our kv store layer only reads the header, not the entire value, so it only provides a smaller buffer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't follow. What delete?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

kv_store::delete().

To remove an object we call get with a buffer large enough to read just the tock tickv header.

Copy link
Contributor

Choose a reason for hiding this comment

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

I still don't follow.

So in kv_store the generate_key_complete() function calls get_value() with a hashed key and a buffer to store the value.

That ends up triggering the read_complete() callback for a Operation::GetKey in tickv.rs.

The ret is an Err(tickv::error_codes::ErrorCode::BufferTooSmall(_)) which triggers the get_value_complete() callback.

But then get_value_complete() doesn't check result because it expects a failure. So what doesn't work? The PR and commit messages don't really explain what this is fixing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How can kv_store not check result? What if some other error occurs?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I agree it should check result.

A small change like this:

diff --git a/capsules/extra/src/tickv.rs b/capsules/extra/src/tickv.rs
index d70e4e13a..fa91f5319 100644
--- a/capsules/extra/src/tickv.rs
+++ b/capsules/extra/src/tickv.rs
@@ -282,6 +282,16 @@ impl<'a, F: Flash, H: Hasher<'a, 8>, const PAGE_SIZE: usize> flash::Client<F>
                         );
                     });
                 }
+                Err(tickv::error_codes::ErrorCode::BufferTooSmall(_)) => {
+                    self.operation.set(Operation::None);
+                    self.client.map(|cb| {
+                        cb.get_value_complete(
+                            Err(ErrorCode::SIZE),
+                            self.key_buffer.take().unwrap(),
+                            self.ret_buffer.take().unwrap(),
+                        );
+                    });
+                }
                 Err(tickv::error_codes::ErrorCode::EraseNotReady(_)) | Ok(_) => {}
                 _ => {
                     self.operation.set(Operation::None);

and then get_value_complete() can check the result and ignore the ErrorCode::SIZE as expected

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can you create a branch or suggested change?

Copy link
Contributor

Choose a reason for hiding this comment

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

Something like this? alistair23@7671497

bradjc added a commit that referenced this pull request Jun 24, 2023
@@ -45,7 +45,7 @@ use kernel::utilities::leasable_buffer::LeasableMutableBuffer;
use kernel::ErrorCode;
use tickv::{self, AsyncTicKV};

#[derive(Clone, Copy, PartialEq)]
#[derive(Clone, Copy, PartialEq, Debug)]
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need this to be Debug?

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've done a lot of debugging.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ha!

But it does add code size and it isn't being used by default

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think it should add size in the case that it isn't being called

match ret {
Ok(tickv::success_codes::SuccessCode::Complete)
| Ok(tickv::success_codes::SuccessCode::Written)
| Err(tickv::error_codes::ErrorCode::BufferTooSmall(_)) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't follow. What delete?

@github-actions github-actions bot added the HIL This affects a Tock HIL interface. label Jul 2, 2023
@bradjc
Copy link
Contributor Author
bradjc commented Jul 2, 2023

Added SIZE error when the retrieved value does not fit within the provided buffer.

Copy link
Contributor
@brghena brghena left a comment

Choose a reason for hiding this comment

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

I don't fully understand the TicKV design, but these changes all look valid to me. I've left a pair of comments to double-check.

match ret {
Ok(tickv::success_codes::SuccessCode::Complete)
| Ok(tickv::success_codes::SuccessCode::Written) => {
self.operation.set(Operation::None);
Copy link
Contributor

Choose a reason for hiding this comment

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

Appending doesn't need a callback?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right. So appending is read (check if the key exists) then a write (write the new key-value) so the callback happens after the write in the write_done callback.

Comment on lines +270 to +272
buf_buffer.map(|buf| {
self.ret_buffer.replace(buf);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Generally, the system of continue_operation() taking a buffer and then returning it, then this code needing to put that buffer right back, but you've got to make sure you put it in the right place, seems like a bug waiting to happen.

I'm satisfied that you did it correctly for GetKey and AppendKey (I think). And I'm not saying you should rewrite it now, but to me it feels bad.

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 think this gets better with the full set of changes. I tried to clarify that there are key buffers and value buffers so it's easier to keep track of them and where they need to go.

bradjc added a commit that referenced this pull request Jul 17, 2023
@lschuermann lschuermann added this pull request to the merge queue Jul 18, 2023
Merged via the queue into master with commit 7b0823a Jul 18, 2023
@lschuermann lschuermann deleted the capsules-tickv-append-err-cb branch July 18, 2023 20:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
HIL This affects a Tock HIL interface.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants
0