Skip to content

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

Merged
Xuanwo merged 4 commits into
mainfrom
kv-write-buffer
Apr 16, 2024
Merged

Xuanwo merged 4 commits into
mainfrom
kv-write-buffer

Conversation

@tisonkun

Copy link
Copy Markdown
Member

This closes #4479

@tisonkun
tisonkun requested a review from Xuanwo as a code owner April 16, 2024 09:19
@github-actions
github-actions Bot requested review from ClSlaid and silver-ymz April 16, 2024 09:19
@github-actions github-actions Bot added the releases-note/refactor The PR does a refactor on code or has a title that begins with "refactor" label Apr 16, 2024
Comment thread core/src/types/buffer.rs Outdated
}
}

impl AsRef<[u8]> for Buffer {

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.

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

Copy link
Copy Markdown
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?

@Xuanwo Xuanwo Apr 16, 2024 •

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.

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
Copy Markdown
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.

@Xuanwo Xuanwo Apr 16, 2024 •

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.

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

DONE.

Comment thread core/src/raw/adapters/kv/backend.rs Outdated
};

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

Copy link
Copy Markdown
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.

@Xuanwo Xuanwo left a comment

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.

Thanks!

@Xuanwo
Xuanwo merged commit 5299879 into main Apr 16, 2024
@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

Labels

releases-note/refactor The PR does a refactor on code or has a title that begins with "refactor"

Projects

None yet

Development

Successfully merging this pull request may close these issues.

kv::adapter should use Buffer

2 participants