-
Notifications
You must be signed in to change notification settings - Fork 126
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
Posix transport should fail if you try to read past EOF #3997
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,13 +2,12 @@ | |
* Distributed under the OSI-approved Apache License, Version 2.0. See | ||
* accompanying file Copyright.txt for details. | ||
* | ||
* FileDescriptor.cpp file I/O using POSIX I/O library | ||
* FilePOSIX.cpp file I/O using POSIX I/O library | ||
* | ||
* Created on: Oct 6, 2016 | ||
* Author: William F Godoy [email protected] | ||
*/ | ||
#include "FilePOSIX.h" | ||
#include "adios2/helper/adiosLog.h" | ||
#include "adios2/helper/adiosString.h" | ||
|
||
#ifdef ADIOS2_HAVE_O_DIRECT | ||
#ifndef _GNU_SOURCE | ||
|
@@ -22,7 +21,8 @@ | |
#include <fcntl.h> // open | ||
#include <sys/stat.h> // open, fstat | ||
#include <sys/types.h> // open | ||
#include <unistd.h> // write, close, ftruncate | ||
#include <thread> | ||
#include <unistd.h> // write, close, ftruncate | ||
|
||
/// \cond EXCLUDE_FROM_DOXYGEN | ||
#include <ios> //std::ios_base::failure | ||
|
@@ -398,6 +398,7 @@ void FilePOSIX::WriteV(const core::iovec *iov, const int iovcnt, size_t start) | |
void FilePOSIX::Read(char *buffer, size_t size, size_t start) | ||
{ | ||
auto lf_Read = [&](char *buffer, size_t size) { | ||
size_t backoff_ns = 20; | ||
while (size > 0) | ||
{ | ||
ProfilerStart("read"); | ||
|
@@ -417,6 +418,25 @@ void FilePOSIX::Read(char *buffer, size_t size, size_t start) | |
"Toolkit", "transport::file::FilePOSIX", "Read", | ||
"couldn't read from file " + m_Name + " " + SysErrMsg()); | ||
} | ||
else if (readSize == 0) | ||
{ | ||
if (m_FailOnEOF) | ||
{ | ||
helper::Throw<std::ios_base::failure>( | ||
"Toolkit", "transport::file::FilePOSIX", "Read", | ||
"Read past end of file on " + m_Name + " " + SysErrMsg()); | ||
} | ||
else | ||
{ | ||
// read past EOF, but we're to wait for data. Exponential backoff with a limit | ||
// of .5 sec (500,000,000 nanosec) | ||
std::this_thread::sleep_for(std::chrono::nanoseconds(backoff_ns)); | ||
constexpr size_t backoff_limit = 500 * 1000 * 1000; | ||
vicentebolea marked this conversation as resolved.
Show resolved
Hide resolved
|
||
backoff_ns *= 2; | ||
if (backoff_ns > backoff_limit) | ||
backoff_ns = backoff_limit; | ||
} | ||
} | ||
|
||
buffer += readSize; | ||
size -= readSize; | ||
|
@@ -595,5 +615,14 @@ void FilePOSIX::Truncate(const size_t length) | |
|
||
void FilePOSIX::MkDir(const std::string &fileName) {} | ||
|
||
void FilePOSIX::SetParameters(const Params ¶ms) | ||
{ | ||
// Parameters are set from config parameters if present | ||
// Otherwise, they are set from environment if present | ||
// Otherwise, they remain at their default value | ||
|
||
helper::GetParameter(params, "FailOnEOF", m_FailOnEOF); | ||
} | ||
|
||
} // end namespace transport | ||
} // end namespace adios2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,8 +4,6 @@ | |
* | ||
* FileDescriptor.h wrapper of POSIX library functions for file I/O | ||
* | ||
* Created on: Oct 6, 2016 | ||
* Author: William F Godoy [email protected] | ||
*/ | ||
|
||
#ifndef ADIOS2_TOOLKIT_TRANSPORT_FILE_FILEDESCRIPTOR_H_ | ||
|
@@ -68,10 +66,13 @@ class FilePOSIX : public Transport | |
|
||
void MkDir(const std::string &fileName) final; | ||
|
||
void SetParameters(const Params ¶ms) final; | ||
|
||
private: | ||
/** POSIX file handle returned by Open */ | ||
int m_FileDescriptor = -1; | ||
int m_Errno = 0; | ||
bool m_FailOnEOF = false; // default to false for historic reasons | ||
bool m_IsOpening = false; | ||
std::future<int> m_OpenFuture; | ||
bool m_DirectIO = false; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,8 +4,6 @@ | |
* | ||
* TransportMan.cpp | ||
* | ||
* Created on: May 23, 2017 | ||
* Author: William F Godoy [email protected] | ||
*/ | ||
|
||
#include "TransportMan.h" | ||
|
@@ -410,6 +408,26 @@ void TransportMan::ReadFile(char *buffer, const size_t size, const size_t start, | |
itTransport->second->Read(buffer, size, start); | ||
} | ||
|
||
void TransportMan::SetParameters(const Params ¶ms, const int transportIndex) | ||
{ | ||
if (transportIndex == -1) | ||
{ | ||
for (auto &transportPair : m_Transports) | ||
{ | ||
auto &transport = transportPair.second; | ||
|
||
transport->SetParameters(params); | ||
} | ||
} | ||
else | ||
{ | ||
auto itTransport = m_Transports.find(transportIndex); | ||
CheckFile(itTransport, | ||
", in call to SetParameters with index " + std::to_string(transportIndex)); | ||
itTransport->second->SetParameters(params); | ||
} | ||
} | ||
|
||
void TransportMan::FlushFiles(const int transportIndex) | ||
{ | ||
if (transportIndex == -1) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,8 +4,6 @@ | |
* | ||
* TransportMan.h : manages a vector of transports | ||
* | ||
* Created on: May 23, 2017 | ||
* Author: William F Godoy [email protected] | ||
*/ | ||
|
||
#ifndef ADIOS2_TOOLKIT_TRANSPORT_TRANSPORTMANAGER_H_ | ||
|
@@ -210,6 +208,13 @@ class TransportMan | |
*/ | ||
bool FileExists(const std::string &name, const Params ¶meters, const bool profile); | ||
|
||
/** | ||
* Set Transport Paramers | ||
* @param params | ||
* @param transportIndex | ||
*/ | ||
void SetParameters(const Params ¶ms, const int transportIndex = -1); | ||
|
||
protected: | ||
core::IO &m_IO; | ||
helper::Comm const &m_Comm; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Would be nice to keep.
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.
If you look at the history of the file it went through multiple revisions and it has many authors. I think we should remove the header from all the files since there is a copyright file that is covering the entire repo and includes all the authors (you are included). I'll bring it up next Tuesday and if everyone agrees I can can create a PR.