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

refactor: kv::adapter should use Buffer (write part) #4496

Merged
merged 4 commits into from
Apr 16, 2024
Merged

Conversation

tisonkun
Copy link
Member

This closes #4479

@@ -149,6 +149,12 @@ impl Default for Buffer {
}
}

impl AsRef<[u8]> for Buffer {
Copy link
Member

Choose a reason for hiding this comment

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

Buffer could have multiple bytes. It's better not to implement this to avoid Buffer been used wrongly.

Copy link
Member Author

Choose a reason for hiding this comment

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

Then we call .chunk everywhere?

Copy link
Member

@Xuanwo Xuanwo Apr 16, 2024

Choose a reason for hiding this comment

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

Then we call .chunk everywhere?

Yes, if the consumer accepts bytes::Buf. In most cases, such as in this PR, we should collect them into a single Bytes to allow writing them in one request (for example, in redis set call).

We can optimize this by introducing multi_write for the KV adapter, similar to what we do with oio::Write.

Copy link
Member Author

Choose a reason for hiding this comment

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

I suggest you push a new commit onto this branch. I can't get it quite clear.

And we may wait a bit for #4497 to get the collect update.

Copy link
Member

@Xuanwo Xuanwo Apr 16, 2024

Choose a reason for hiding this comment

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

I suggest you push a new commit onto this branch. I can't get it quite clear.

DONE.

};

self.kv.set(&self.path, &buf).await
let buf = self.buffer.collect();
Copy link
Member Author

Choose a reason for hiding this comment

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

I wonder if we can avoid clone here but set self.buffer = QueueBuf::default() with mem::replace. And then call into_buffer as introduced in #4497.

Copy link
Member

@Xuanwo Xuanwo left a comment

Choose a reason for hiding this comment

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

Thanks!

@Xuanwo Xuanwo merged commit 5299879 into main Apr 16, 2024
250 checks passed
@Xuanwo Xuanwo deleted the kv-write-buffer branch April 16, 2024 11:06
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.

kv::adapter should use Buffer
2 participants