-
Notifications
You must be signed in to change notification settings - Fork 526
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
use butil::IOBuf in WriteChunk #81
use butil::IOBuf in WriteChunk #81
Conversation
db62609
to
5477453
Compare
@@ -329,6 +329,33 @@ int Ext4FileSystemImpl::Write(int fd, | |||
return length; | |||
} | |||
|
|||
int Ext4FileSystemImpl::Write(int fd, | |||
butil::IOBuf buf, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const &
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里是需要把iobuf写入到fd中,会涉及到对iobuf的修改,所以不能用const引用。
这里只拷贝了一次iobuf,开销不大。
src/fs/ext4_filesystem_impl.cpp
Outdated
int retryTimes = 0; | ||
|
||
while (remainLength > 0) { | ||
ssize_t ret = buf.pcut_into_file_descriptor(fd, offset, length); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
第三个参数应该是remainLength吧
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -52,6 +54,7 @@ class Ext4FileSystemImpl : public LocalFileSystem { | |||
int List(const string& dirPath, vector<std::string>* names) override; | |||
int Read(int fd, char* buf, uint64_t offset, int length) override; | |||
int Write(int fd, const char* buf, uint64_t offset, int length) override; | |||
int Write(int fd, butil::IOBuf buf, uint64_t offset, int length) override; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const &
* @param length:写入数据的长度 | ||
* @return 返回成功写入的数据长度,失败返回-1 | ||
*/ | ||
virtual int Write(int fd, butil::IOBuf buf, uint64_t offset, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上
@@ -161,7 +162,7 @@ TEST_F(CSChunkfilePoolMockTest, PersistEnCodeMetaInfoTest) { | |||
{ | |||
EXPECT_CALL(*lfs_, Open(poolMetaPath, _)) | |||
.WillOnce(Return(-1)); | |||
EXPECT_CALL(*lfs_, Write(_, _, _, _)) | |||
EXPECT_CALL(*lfs_, Write(_, Matcher<const char*>(_), _, _)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
为啥这些还是会带char*的参数?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里是因为写入操作可能会与快照的metapage有关,更新metapage调用的是Write(_, const char*,....)这个接口。
5477453
to
8951933
Compare
off_t offset, | ||
size_t length, | ||
uint32_t* cost, | ||
const std::string & cloneSourceLocation = ""); | ||
|
||
// Deprecated, only use for unit & integration test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deprecated? 现在的测试中还是要用的吧
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
测试代码里还是用了很多这个接口,所以暂时没改掉。
这里备注了一下,正常情况下不应该使用这个接口,只有单元测试/集成测试需要。
int retryTimes = 0; | ||
|
||
while (remainLength > 0) { | ||
ssize_t ret = buf.pcut_into_file_descriptor(fd, offset, remainLength); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
会分批写入文件吗
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
正常来说不会。这里内部还是用的pwritev来做的,有可能会返回EINTR。
@@ -52,6 +54,7 @@ class Ext4FileSystemImpl : public LocalFileSystem { | |||
int List(const string& dirPath, vector<std::string>* names) override; | |||
int Read(int fd, char* buf, uint64_t offset, int length) override; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
read这里返回也会从char*拷贝一次到iobuf?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
读请求的buffer,会通过iobuf::append_user_data的方式由iobuf管理,这种情况不会拷贝。
Change-Id: If514d166a27da3066649820a140f28ec193b41a1
8951933
to
7306508
Compare
Change-Id: If514d166a27da3066649820a140f28ec193b41a1
What problem does this PR solve?
Issue Number: None
Problem Summary:
What is changed and how it works?
What's Changed: zeroize memory copy in chunkserver writechunk
How it Works:
Side effects(Breaking backward compatibility? Performance regression?):
Check List