-
Notifications
You must be signed in to change notification settings - Fork 749
Fix FS storage races #34452
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
base: main
Are you sure you want to change the base?
Fix FS storage races #34452
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -59,6 +59,12 @@ class TFsOperationActor : public TActorBootstrapped<TFsOperationActor> { | |||||||||
| return RequiresKey<TEvResponse>::value; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| static void FsyncParentDir(const TString& filePath) { | ||||||||||
| TFsPath parent = TFsPath(filePath).Parent(); | ||||||||||
| TFile dirFd(parent.GetPath(), RdOnly | Seq); | ||||||||||
| dirFd.Flush(); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| template<typename TEvResponse> | ||||||||||
| void ReplySuccess(const NActors::TActorId& sender, const std::optional<TString>& key) { | ||||||||||
| typename TEvResponse::TAwsResult awsResult; | ||||||||||
|
|
@@ -202,11 +208,11 @@ class TFsOperationActor : public TActorBootstrapped<TFsOperationActor> { | |||||||||
| TFsPath fsPath(key); | ||||||||||
| fsPath.Parent().MkDirs(); | ||||||||||
|
|
||||||||||
| TFile file(fsPath.GetPath(), CreateAlways | WrOnly); | ||||||||||
| file.Flock(LOCK_EX | LOCK_NB); | ||||||||||
| file.Write(body.data(), body.size()); | ||||||||||
| file.Flush(); | ||||||||||
| file.Close(); | ||||||||||
| TMultipartUploadSession session(key); | ||||||||||
| session.File.Write(body.data(), body.size()); | ||||||||||
| session.File.Flush(); | ||||||||||
| FsyncParentDir(key); | ||||||||||
| session.File.Close(); | ||||||||||
| ReplySuccess<TEvPutObjectResponse>(ev->Sender, key); | ||||||||||
| } catch (const TSystemError& ex) { | ||||||||||
| if (!HandleFileLockError<TEvPutObjectResponse>(ex, ev->Sender, key, "PutObject")) { | ||||||||||
|
|
@@ -503,6 +509,7 @@ class TFsOperationActor : public TActorBootstrapped<TFsOperationActor> { | |||||||||
| session.File.Flush(); | ||||||||||
|
|
||||||||||
| NFs::Rename(incompleteKey, key); | ||||||||||
| FsyncParentDir(key); | ||||||||||
| session.File.Close(); | ||||||||||
|
|
||||||||||
| FS_LOG_I("CompleteMultipartUpload" | ||||||||||
|
|
@@ -545,9 +552,14 @@ class TFsOperationActor : public TActorBootstrapped<TFsOperationActor> { | |||||||||
| auto& session = it->second; | ||||||||||
| const TString filePath = session.Key; | ||||||||||
|
|
||||||||||
| NFs::Remove(filePath); | ||||||||||
| session.File.Close(); | ||||||||||
| bool removed = NFs::Remove(filePath); | ||||||||||
| if (!removed) { | ||||||||||
| FS_LOG_W("AbortMultipartUpload: failed to delete incomplete file" | ||||||||||
| << ": uploadId# " << uploadId | ||||||||||
| << ", file# " << filePath); | ||||||||||
| } | ||||||||||
| ActiveUploads.erase(it); | ||||||||||
| session.File.Close(); | ||||||||||
|
Comment on lines
561
to
+562
|
||||||||||
| ActiveUploads.erase(it); | |
| session.File.Close(); | |
| session.File.Close(); | |
| ActiveUploads.erase(it); |
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.
FsyncParentDiropens a directory withTFile(parent.GetPath(), RdOnly | Seq)and callsFlush()(fsync). On Windows,TFileHandleusesCreateFileWwithoutFILE_FLAG_BACKUP_SEMANTICS, so opening a directory path will fail and make Put/Complete operations error out. Consider guarding this code for non-Windows platforms or implementing directory-open with the required Windows flags (or using a dedicated helper in util).