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

curvefs/client: fix bug when upload failed. #1130

Merged
merged 1 commit into from
Mar 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
curvefs/client: fix bug when upload failed.
  • Loading branch information
wuhongsong committed Mar 11, 2022
commit 21053b480f28a7cc709e853a02ef0e974d505b2a
27 changes: 17 additions & 10 deletions curvefs/src/client/s3/disk_cache_write.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,17 @@ int DiskCacheWrite::UploadFile(const std::string &name,
VLOG(9) << "PutObjectAsyncCallBack success, "
<< "remove file: " << context->key;
posixWrapper_->free(buffer);
} else if (syncTask) {
syncTask->SetError();
}

if (syncTask) {
VLOG(9) << "UploadFile, name = " << name << " signal start";
syncTask->Signal();
VLOG(9) << "UploadFile, name = " << name << " signal finish";
if (syncTask) {
VLOG(9) << "UploadFile, name = "
<< name << " signal start";
syncTask->Signal();
VLOG(9) << "UploadFile, name = "
<< name << " signal finish";
}
return;
}
LOG(WARNING) << "upload object failed: " << context->key;
client_->UploadAsync(context);
};
auto context = std::make_shared<PutObjectAsyncContext>();
context->key = name;
Expand Down Expand Up @@ -361,15 +363,20 @@ int DiskCacheWrite::UploadAllCacheWriteFile() {
continue;
}
PutObjectAsyncCallBack cb =
[&, buffer](const std::shared_ptr<PutObjectAsyncContext> &context) {
[&, buffer](const std::shared_ptr<PutObjectAsyncContext> &context) {
if (context->retCode == 0) {
if (pendingReq.fetch_sub(1) == 1) {
VLOG(3) << "pendingReq is over";
cond.Signal();
}
VLOG(3) << "PutObjectAsyncCallBack success"
<< ", file: " << context->key;
posixWrapper_->free(buffer);
};
return;
}
LOG(WARNING) << "upload object failed: " << context->key;
client_->UploadAsync(context);
};
auto context = std::make_shared<PutObjectAsyncContext>();
context->key = *iter;
context->buffer = buffer;
Expand Down
40 changes: 26 additions & 14 deletions curvefs/test/client/test_disk_cache_write.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,38 +356,50 @@ TEST_F(TestDiskCacheWrite, UploadAllCacheWriteFile_2) {
dir = opendir(".");
EXPECT_NE(dir, nullptr);

struct dirent fake;
struct dirent fake, fake2;
strcpy(fake.d_name, "fake"); // NOLINT
strcpy(fake2.d_name, "fake2"); // NOLINT

EXPECT_CALL(*wrapper_, stat(NotNull(), NotNull()))
.Times(3)
.WillOnce(Return(0))
.WillOnce(Return(0))
.WillOnce(Return(0));
.WillRepeatedly(Return(0));
EXPECT_CALL(*wrapper_, opendir(NotNull()))
.WillOnce(Return(dir));
EXPECT_CALL(*wrapper_, readdir(NotNull()))
.Times(2)
.Times(3)
.WillOnce(Return(&fake))
.WillOnce(Return(&fake2))
.WillOnce(ReturnNull());
EXPECT_CALL(*wrapper_, closedir(NotNull()))
.WillOnce(Return(0));
EXPECT_CALL(*wrapper_, open(_, _, _))
.WillOnce(Return(0));
.WillRepeatedly(Return(0));
EXPECT_CALL(*wrapper_, close(_))
.WillOnce(Return(0));
.WillRepeatedly(Return(0));

EXPECT_CALL(*wrapper_, malloc(_))
.WillOnce(Return(&path));
EXPECT_CALL(*wrapper_, malloc(_))
.WillRepeatedly(Return(&path));
EXPECT_CALL(*wrapper_, memset(_, _, _))
.WillOnce(Return(&path));
.WillRepeatedly(Return(&path));
EXPECT_CALL(*wrapper_, free(_))
.WillRepeatedly(Return());
EXPECT_CALL(*wrapper_, read(_, _, _))
.WillOnce(Return(239772865546436));
.WillRepeatedly(Return(239772865546436));

EXPECT_CALL(*client_, UploadAsync(_))
.WillRepeatedly(Invoke(
EXPECT_CALL(*client_, UploadAsync(_))
.Times(3)
.WillOnce(Invoke(
[&] (const std::shared_ptr<PutObjectAsyncContext>& context) {
context->key = "test";
context->retCode = 0;
context->cb(context);
}))
.WillOnce(Invoke(
[&] (const std::shared_ptr<PutObjectAsyncContext>& context) {
context->key = "test";
context->retCode = -1;
context->cb(context);
}))
.WillOnce(Invoke(
[&] (const std::shared_ptr<PutObjectAsyncContext>& context) {
context->key = "test";
context->retCode = 0;
Expand Down