ewmscp  ..
Public Member Functions | Protected Attributes | List of all members
outputHandler::daosFs::writerDaosFs Class Reference

#include <outputHandlerDaosFs.h>

Inheritance diagram for outputHandler::daosFs::writerDaosFs:
[legend]
Collaboration diagram for outputHandler::daosFs::writerDaosFs:
[legend]

Public Member Functions

 writerDaosFs (const std::string &aPath, bool mightAppend, size_t sourceSize, size_t readBlockSize, copyRequest::stateType &state, bool noWrite, std::unique_ptr< ioHandle::attrDataType > aAttrData, std::unique_ptr< acl::list > aAclData, daosFs &aHandler)
 
 writerDaosFs (std::string &aPath, bool noWrite, std::unique_ptr< ioHandle::attrDataType > aAttrData, std::unique_ptr< acl::list > aAclData, daosFs &aHandler)
 
void closeAndRemoveBadCopy () override
 
 ~writerDaosFs () noexcept(false) override
 
void seek (size_t position) override
 
bool parallelizable () const override
 tell if this handler is capable of parallel IO. Unsually not the case More...
 
size_t getSize () const override
 
void writeBlock (const block &b) override
 
void writeBlockP (const block &b) override
 
void doAttributePreservations (const genericStat &readInitialStat) override
 
void sync () override
 
- Public Member Functions inherited from daosFsIoCommon
 daosFsIoCommon (const std::string &aPath, daosFsCommon &aHandler)
 
void setXattr (const std::string &name, const std::string &value) override
 
std::string getXattr (const std::string &name) override
 get one extended attribute value More...
 
void removeXattr (const std::string &name) override
 
std::unique_ptr< const genericStatgetStat () override
 
std::unique_ptr< ioHandle::attrDataTypegetAttrData (const outputHandler::base *aOutputHandler) override
 get attributes in the optimal way for setting with aOutputHandler More...
 
- Public Member Functions inherited from ioHandle
 ioHandle ()
 
virtual ~ioHandle () noexcept(false)
 
virtual size_t getBlockSize () const
 
virtual void setBlockSize (size_t newSize)
 
virtual std::unique_ptr< acl::listgetAclData ()
 get acls More...
 

Protected Attributes

struct stat writeInitialStat
 
std::unique_ptr< ioHandle::attrDataTypeattrData
 
std::unique_ptr< acl::listaclData
 
- Protected Attributes inherited from daosFsIoCommon
const std::string & path
 
dfs_obj_t * obj
 
daosFsCommonhandler
 
- Protected Attributes inherited from ioHandle
size_t blockSize
 in bytes, block size to be used when reading or writing More...
 

Detailed Description

Definition at line 13 of file outputHandlerDaosFs.h.

Constructor & Destructor Documentation

◆ writerDaosFs() [1/2]

outputHandler::daosFs::writerDaosFs::writerDaosFs ( const std::string &  aPath,
bool  mightAppend,
size_t  sourceSize,
size_t  readBlockSize,
copyRequest::stateType state,
bool  noWrite,
std::unique_ptr< ioHandle::attrDataType aAttrData,
std::unique_ptr< acl::list aAclData,
daosFs aHandler 
)

Definition at line 229 of file outputHandlerDaosFs.cpp.

237  :
238  daosFsIoCommon(aPath, aHandler),
239  attrData(std::move(aAttrData)),
240  aclData(std::move(aAclData)) {
241  bool haveWriteStat = false;
242  if (noWrite) {
243  obj = nullptr;
244  blockSize = 4096;
245  } else {
246  auto openMode = O_CREAT | O_TRUNC | O_WRONLY;
247  state.clear(copyRequest::stateBitType::append); // clear any old append bits, may be left over from former attempts
249  fd = throwcall::badval(open(path.c_str(), openMode, S_IWUSR),
250  -1, "can't open ", path, " for writing");
251  if (!haveWriteStat) {
252  throwcall::good0(fstat(fd, &writeInitialStat), "can't stat destination file ", path);
253  }
254  blockSize = writeInitialStat.st_blksize;
255  throwcall::good0(posix_fadvise(fd, 0, 0, POSIX_FADV_SEQUENTIAL),
256  "can't advise ", path, " as sequential");
257  throwcall::good0(posix_fadvise(fd, 0, 0, POSIX_FADV_NOREUSE),
258  "can't advise ", path, " as use only once");
259  }
260  };

References copyRequest::append, throwcall::badval(), ioHandle::blockSize, enumAsBitmask< T >::clear(), throwcall::good0(), daosFsIoCommon::obj, daosFsIoCommon::path, outputHandler::slownessThreshold, timerInstTO, and writeInitialStat.

Here is the call graph for this function:

◆ writerDaosFs() [2/2]

outputHandler::daosFs::writerDaosFs::writerDaosFs ( std::string &  aPath,
bool  noWrite,
std::unique_ptr< ioHandle::attrDataType aAttrData,
std::unique_ptr< acl::list aAclData,
daosFs aHandler 
)

◆ ~writerDaosFs()

outputHandler::daosFs::writerDaosFs::~writerDaosFs ( )
overridenoexcept

Definition at line 308 of file outputHandlerDaosFs.cpp.

308  {
309  if (fd != -1) {
310  if (isUnwinding()) {
312  return;
313  } else {
314  if (attrData) {
315  try {
316  attrData->set(this);
317  } catch (const std::exception& e) {
319  path, "set attr at close ",
320  e.what());
322  throw;
323  }
324  }
326  throwcall::good0(close(fd), "can't close ", path);
327  }
328  }
329  };

References errMsg::debug, errMsg::emit(), throwcall::good0(), outputHandler::slownessThreshold, and timerInstTO.

Here is the call graph for this function:

Member Function Documentation

◆ closeAndRemoveBadCopy()

void outputHandler::daosFs::writerDaosFs::closeAndRemoveBadCopy ( )
override

Definition at line 292 of file outputHandlerDaosFs.cpp.

292  {
293  if (close(fd) != 0) {
295  path, "close during unwind ",
296  std::system_category().default_error_condition(errno).message());
297  }
299  path, "unlink failed copy", "due to exception");
300  auto retval = unlink(path.c_str());
301  if (retval && errno != ENOENT) {
303  path, "can't remove bad copy ",
304  std::system_category().default_error_condition(errno).message());
305  }
306  }

References errMsg::debug, errMsg::emit(), and errMsg::err.

Here is the call graph for this function:

◆ doAttributePreservations()

void outputHandler::daosFs::writerDaosFs::doAttributePreservations ( const genericStat readInitialStat)
override

Definition at line 395 of file outputHandlerDaosFs.cpp.

395  {
396  if (preserve.timestamps) {
397  struct timespec times[2];
398  readInitialStat.getAtime(times[0]);
399  readInitialStat.getMtime(times[1]);
400  timerInst(futimens);
401  throwcall::good0(futimens(fd, times), "can't set time stamp of ", path);
402  }
403 
404  if (preserve.mode) {
405  timerInst(fchmod);
406  throwcall::good0(fchmod(fd, readInitialStat.mode), "can't set mode of ", path);
407  } else {
408  auto oldmask = umask(0);
409  timerInst(fchmod);
410  throwcall::good0(fchmod(fd, modeBits & ~oldmask), "can't set mode of ", path);
411  umask(oldmask);
412  }
413 
414  if (gid != -1 || uid != -1) {
415  timerInst(fchown);
416  throwcall::good0(fchown(fd, uid, gid), "can't set owner/group (", uid, ",", gid, ") of ", path);
417  } else if (preserve.ownership) {
418  timerInst(fchown);
419  throwcall::good0(fchown(fd, readInitialStat.ownerUid, readInitialStat.ownerGid),
420  "can't set owner/group (", readInitialStat.ownerUid, ",", readInitialStat.ownerGid, ") of ",
421  path);
422  }
423  }

References genericStat::getAtime(), genericStat::getMtime(), gid, throwcall::good0(), genericStat::mode, modeBits, genericStat::ownerGid, genericStat::ownerUid, preserve, timerInst, and uid.

Here is the call graph for this function:

◆ getSize()

size_t outputHandler::daosFs::writerDaosFs::getSize ( ) const
override

Definition at line 339 of file outputHandlerDaosFs.cpp.

339  {
340  return writeInitialStat.st_size;
341  }

◆ parallelizable()

bool outputHandler::daosFs::writerDaosFs::parallelizable ( ) const
overridevirtual

tell if this handler is capable of parallel IO. Unsually not the case

Reimplemented from ioHandle.

Definition at line 336 of file outputHandlerDaosFs.cpp.

336  {
337  return writeInitialStat.st_size == 0;
338  }

◆ seek()

void outputHandler::daosFs::writerDaosFs::seek ( size_t  position)
override

Definition at line 331 of file outputHandlerDaosFs.cpp.

331  {
332  timerInst(lseek);
333  throwcall::badval(lseek(fd, position, SEEK_SET),
334  -1, "can't seek ", path, " to ", position);
335  }

References throwcall::badval(), and timerInst.

Here is the call graph for this function:

◆ sync()

void outputHandler::daosFs::writerDaosFs::sync ( )
override

Definition at line 462 of file outputHandlerDaosFs.cpp.

462  {
463  timerInst(fsync);
464  throwcall::good0(fsync(fd), "can't sync ", path);
465  }

References throwcall::good0(), and timerInst.

Here is the call graph for this function:

◆ writeBlock()

void outputHandler::daosFs::writerDaosFs::writeBlock ( const block b)
override

Definition at line 343 of file outputHandlerDaosFs.cpp.

343  {
344  if (b.isHole()) { // just write a hole...
345  static timer::anchor a("lseek");
347  auto currentPosition = throwcall::badval(lseek(fd, 0, SEEK_CUR), -1, "lseek to determine position on", path);
348  i.stop();
349  auto holeEnd = currentPosition + b.size();
350  {
351  timerInst(ftruncate);
352  throwcall::good0(ftruncate(fd, holeEnd),
353  "fruncate ", path, " to ", holeEnd);
354  }
355  timerInst(lseek);
356  throwcall::badval(lseek(fd, holeEnd, SEEK_SET), -1,
357  "can't seek to hole end (", holeEnd, ") in ", path);
358  return;
359  }
360 
361  size_t bytes_writen_so_far = 0;
362 
363  while (bytes_writen_so_far < b.size()) {
364  auto count = b.size() - bytes_writen_so_far;
365 
366  if (count > blockSize) {
367  count = blockSize;
368  }
370  timerInst(write);
371  auto bytes_writen = throwcall::badval(write(fd, b.bufferAt(bytes_writen_so_far), count),
372  -1, "write failed on ", path);
373  writeRateLimit.update(bytes_writen);
374  bytes_writen_so_far += bytes_writen;
375  }
376  }

References throwcall::badval(), block::bufferAt(), throwcall::good0(), block::isHole(), block::size(), timer::instanceUnscoped::stop(), timerInst, throttle::watch::update(), throttle::watch::wait(), and writeRateLimit.

Here is the call graph for this function:

◆ writeBlockP()

void outputHandler::daosFs::writerDaosFs::writeBlockP ( const block b)
override

Definition at line 379 of file outputHandlerDaosFs.cpp.

379  {
380  size_t bytes_writen_so_far = 0;
381 
382  while (bytes_writen_so_far < b.size()) {
383  auto count = b.size() - bytes_writen_so_far;
384 
385  if (count > blockSize) {
386  count = blockSize;
387  }
388  timerInst(pwrite);
389  auto bytes_writen = throwcall::badval(pwrite(fd, b.bufferAt(bytes_writen_so_far), count, b.offset() + bytes_writen_so_far),
390  -1, "write failed on ", path);
391  bytes_writen_so_far += bytes_writen;
392  }
393  }

References throwcall::badval(), block::bufferAt(), block::offset(), block::size(), and timerInst.

Here is the call graph for this function:

Member Data Documentation

◆ aclData

std::unique_ptr<acl::list> outputHandler::daosFs::writerDaosFs::aclData
protected

Definition at line 17 of file outputHandlerDaosFs.h.

◆ attrData

std::unique_ptr<ioHandle::attrDataType> outputHandler::daosFs::writerDaosFs::attrData
protected

Definition at line 16 of file outputHandlerDaosFs.h.

◆ writeInitialStat

struct stat outputHandler::daosFs::writerDaosFs::writeInitialStat
protected

Definition at line 15 of file outputHandlerDaosFs.h.

Referenced by writerDaosFs().


The documentation for this class was generated from the following files:
genericStat::ownerGid
gid_t ownerGid
Definition: genericStat.h:24
daosFsIoCommon::obj
dfs_obj_t * obj
Definition: daosFsCommon.h:53
genericStat::mode
mode_t mode
Definition: genericStat.h:22
outputHandler::daosFs::writerDaosFs::closeAndRemoveBadCopy
void closeAndRemoveBadCopy() override
Definition: outputHandlerDaosFs.cpp:292
block::offset
size_t offset() const
Definition: block.h:25
errMsg::location
class for defining the location of a error message in the source code.
Definition: errMsgQueue.h:14
genericStat::getAtime
void getAtime(struct timespec &spec) const
Definition: genericStat.cpp:62
throwcall::badval
T badval(T call, t badvalue, const Args &... args)
template function to wrap system calls that return a special bad value on failure
Definition: throwcall.h:54
outputHandler::daosFs::writerDaosFs::writeInitialStat
struct stat writeInitialStat
Definition: outputHandlerDaosFs.h:15
outputHandler::daosFs::writerDaosFs::aclData
std::unique_ptr< acl::list > aclData
Definition: outputHandlerDaosFs.h:17
outputHandler::slownessThreshold
static options::single< timer::clock_type::duration > slownessThreshold('\0',"daosFsSlownessThreshold", "duration after which file operations are considered slow", std::chrono::milliseconds(10))
genericStat::getMtime
void getMtime(struct timespec &spec) const
Definition: genericStat.cpp:65
gid
options::single< int > gid
block::isHole
bool isHole() const
Definition: block.h:36
errMsg::level::debug
@ debug
ioHandle::blockSize
size_t blockSize
in bytes, block size to be used when reading or writing
Definition: ioHandle.h:17
block::bufferAt
void * bufferAt(size_t offset)
only way to access the data in the block
Definition: block.cpp:28
timer::instanceUnscoped
Definition: timer.h:95
timer::anchor
Definition: timer.h:22
preserve
decltype(preserve) preserve
set of properties to preserve in the copy
Definition: ewmscp.cpp:111
uid
options::single< int > uid
errMsg::level::err
@ err
throttle::watch::wait
void wait()
Definition: throttle.h:50
daosFsIoCommon::daosFsIoCommon
daosFsIoCommon(const std::string &aPath, daosFsCommon &aHandler)
Definition: daosFsCommon.cpp:115
errMsg::emit
void emit(level aLogLevel, const location &loc, const std::string &aObject, const std::string &aAction, const Args &... args)
function to create and enqueue a message, this is the only way that messages should be created!
Definition: errMsgQueue.h:148
timerInst
#define timerInst(subfunc)
Definition: timer.h:157
block::size
size_t size() const
Definition: block.h:16
writeRateLimit
throttle::watch writeRateLimit
timerInstTO
#define timerInstTO(subfunc, timeout, object)
Definition: timer.h:158
throwcall::good0
void good0(T call, const Args &... args)
template function to wrap system calls that return 0 on success
Definition: throwcall.h:40
daosFsIoCommon::path
const std::string & path
Definition: daosFsCommon.h:52
enumAsBitmask::clear
void clear(const T aBits)
Definition: enumAsBitmask.h:31
throttle::watch::update
void update(double units=1.0)
Definition: throttle.h:35
outputHandler::daosFs::writerDaosFs::attrData
std::unique_ptr< ioHandle::attrDataType > attrData
Definition: outputHandlerDaosFs.h:16
copyRequest::stateBitType::append
@ append
genericStat::ownerUid
uid_t ownerUid
Definition: genericStat.h:23
modeBits
options::single< modeBitType > modeBits