forked from ornladios/ADIOS2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: Posix transport should fail if you try to read past EOF (ornladi…
…os#3997) * Add test for local operator, tweak posix transport to fail on EOF when desired, add a unit test * Disable posix test on Windows
- Loading branch information
1 parent
7a63268
commit c1367bd
Showing
9 changed files
with
309 additions
and
10 deletions.
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; | ||
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.