Skip to content

refactor: typed_kv::adapter should use Buffer - #4497

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

Xuanwo merged 4 commits into
mainfrom
typed-kv-buffer

Conversation

@tisonkun

Copy link
Copy Markdown
Member

This closes #4480.

@tisonkun
tisonkun requested a review from Xuanwo as a code owner April 16, 2024 09:31
@github-actions
github-actions Bot requested review from G-XD and xyjixyjixyji April 16, 2024 09:31
@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/raw/oio/buf/queue_buf.rs Resolved
self.buffer.advance(written);
}

let buffer = std::mem::take(&mut self.buffer);

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'm not sure if we need loop still. Generally &mut self should take the ref exclusive. But I'm not quit sure.

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.

If .await can give up the mut ref, we always have the risk the before close, there is a new push.

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.

Close could fail and users might retry close later, we should keep buffer in memory until users decide to drop this writer.

let written = self.inner.write(self.buffer.collect()).await?;
self.buffer.advance(written);
let buffer = std::mem::take(&mut self.buffer);
self.inner.write(buffer.collect()).await?;

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.

This is incorrect because write does not guarantee that all content will be successfully written. We need to advance the written size here and keep unwritten content.

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 it's meaningless to make collect takes mut self. Please push a new commit on this patch or write a new PR.

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 revert the change.

self.buffer.advance(written);
}

let buffer = std::mem::take(&mut self.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.

Close could fail and users might retry close later, we should keep buffer in memory until users decide to drop this writer.

@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 commented Apr 16, 2024 •

Copy link
Copy Markdown
Member

gcs failed for #4439, need more research but we know that it's not related to this PR.

@Xuanwo
Xuanwo merged commit 2e9e89b into main Apr 16, 2024
@Xuanwo
Xuanwo deleted the typed-kv-buffer branch April 16, 2024 10:47
@tisonkun

Copy link
Copy Markdown
Member Author

Cool. That change makes sense.

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.

typed_kv::adapter should use Buffer

2 participants