ewmscp  ..
Public Member Functions | Static Protected Attributes | List of all members
outputHandler::dcap::writerDcap Class Reference

#include <outputHandlerDcap.h>

Inheritance diagram for outputHandler::dcap::writerDcap:
[legend]
Collaboration diagram for outputHandler::dcap::writerDcap:
[legend]

Public Member Functions

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

Static Protected Attributes

static options::single< bool > unsafeWrite
 
static options::single< bool > noChecksum
 

Additional Inherited Members

- Protected Attributes inherited from dcapIoCommon
const std::string path
 
int fd = -1
 
- 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 12 of file outputHandlerDcap.h.

Constructor & Destructor Documentation

◆ writerDcap()

outputHandler::dcap::writerDcap::writerDcap ( const std::string &  aPath,
bool  mightAppend,
size_t  sourceSize,
size_t  readBlockSize,
copyRequest::stateType state,
bool  noWrite,
std::unique_ptr< acl::list aAclData 
)

Definition at line 246 of file outputHandlerDcap.cpp.

252  :
253  dcapIoCommon(aPath) {
254  blockSize = 16 * 1024 * 1024;
255  if (noWrite) {
256  fd = -1;
257  } else {
258  dCapLock extraOptionLock;
259  std::string options("-alloc-size=");
260  options += std::to_string(sourceSize);
261  dc_setExtraOption(const_cast<char*>(options.c_str())); // const cast to work around broken interface
262  if (aclData) {
263  setAclData(*aclData);
264  }
265  auto openMode = O_CREAT | O_TRUNC | O_WRONLY;
266  state.clear(copyRequest::stateBitType::append); // clear any old append sets, may be left over from former attempts
267  // No appends on dcache, it's a WORM system
268  fd = throwcall::dcap::badval(dc_open(path.c_str(), openMode, S_IWUSR | S_IRUSR),
269  -1, "can't open ", path, " for writing");
270  if (unsafeWrite) {
271  dc_unsafeWrite(fd);
272  }
273  if (noChecksum) {
274  dc_noCheckSum(fd);
275  }
276  }
277  };

References copyRequest::append, throwcall::dcap::badval(), ioHandle::blockSize, enumAsBitmask< T >::clear(), dcapIoCommon::fd, noChecksum, dcapIoCommon::path, outputHandler::dcap::setAclData(), and unsafeWrite.

Here is the call graph for this function:

◆ ~writerDcap()

outputHandler::dcap::writerDcap::~writerDcap ( )
overridenoexcept

Definition at line 293 of file outputHandlerDcap.cpp.

293  {
294  if (fd != -1) {
295  dCapLock extraOptionLock;
296  if (isUnwinding()) {
298  return;
299  }
300  throwcall::dcap::good0(dc_close(fd), "can't close ", path);
301  }
302  };

References throwcall::dcap::good0().

Here is the call graph for this function:

Member Function Documentation

◆ closeAndRemoveBadCopy()

void outputHandler::dcap::writerDcap::closeAndRemoveBadCopy ( )
override

Definition at line 278 of file outputHandlerDcap.cpp.

278  {
279  if (dc_close(fd) != 0) {
281  path, "close during unwind ",
282  dc_strerror(dc_errno));
283  }
285  path, "unlink failed copy", "due to exception");
286  if (dc_unlink(path.c_str()) != 0) {
288  path, "can't remove bad copy ",
289  dc_strerror(dc_errno));
290  }
291  };

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

Here is the call graph for this function:

◆ doAttributePreservations()

void outputHandler::dcap::writerDcap::doAttributePreservations ( const genericStat readInitialStat)
override

Definition at line 327 of file outputHandlerDcap.cpp.

327  {
328  throw unimplementedActionError("for dCap doAttributePreservations must be used with setAttributesAfterClose");
329  }

◆ sync()

void outputHandler::dcap::writerDcap::sync ( )
override

Definition at line 373 of file outputHandlerDcap.cpp.

373  {
374  throwcall::dcap::good0(dc_fsync(fd), "can't sync ", path);
375  }

References throwcall::dcap::good0().

Here is the call graph for this function:

◆ writeBlock()

void outputHandler::dcap::writerDcap::writeBlock ( const block b)
override

Definition at line 305 of file outputHandlerDcap.cpp.

305  {
306  size_t bytes_writen_so_far = 0;
307 
308  while (bytes_writen_so_far < b.size()) {
310  auto count = b.size() - bytes_writen_so_far;
311 
312  if (b.isHole()) { // just write zeroes
313  count = std::min({count, blockSize, block::nullBufferSize()});
314  } else {
315  count = std::min(count, blockSize);
316  }
317  auto bytes_writen = throwcall::dcap::badval(dc_write(fd, b.bufferAt(bytes_writen_so_far), count),
318  -1, "write failed on ", path);
319  if (bytes_writen == 0) {
320  throw std::runtime_error("wrote 0 bytes for " + path);
321  }
322  writeRateLimit.update(bytes_writen);
323  bytes_writen_so_far += bytes_writen;
324  }
325  }

References throwcall::dcap::badval(), block::bufferAt(), block::isHole(), block::nullBufferSize(), block::size(), throttle::watch::update(), throttle::watch::wait(), and writeRateLimit.

Here is the call graph for this function:

Member Data Documentation

◆ noChecksum

options::single<bool> outputHandler::dcap::writerDcap::noChecksum
staticprotected

Definition at line 15 of file outputHandlerDcap.h.

Referenced by writerDcap().

◆ unsafeWrite

options::single<bool> outputHandler::dcap::writerDcap::unsafeWrite
staticprotected

Definition at line 14 of file outputHandlerDcap.h.

Referenced by writerDcap().


The documentation for this class was generated from the following files:
throwcall::dcap::badval
T badval(T call, t badvalue, const Args &... args)
Definition: dcapCommon.h:28
errMsg::location
class for defining the location of a error message in the source code.
Definition: errMsgQueue.h:14
dCapLock
Definition: dcapCommon.h:40
outputHandler::dcap::writerDcap::noChecksum
static options::single< bool > noChecksum
Definition: outputHandlerDcap.h:15
unimplementedActionError
class for exceptions that result from unimplemented functions Exceptions of this kind are to be throw...
Definition: copyRequestTypes.h:32
outputHandler::dcap::setAclData
static void setAclData(const acl::list &aclData, bool isDir=false)
Definition: outputHandlerDcap.cpp:188
dcapIoCommon::path
const std::string path
Definition: dcapCommon.h:76
options
Definition: Options.h:33
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
outputHandler::dcap::writerDcap::closeAndRemoveBadCopy
void closeAndRemoveBadCopy() override
Definition: outputHandlerDcap.cpp:278
outputHandler::dcap::writerDcap::unsafeWrite
static options::single< bool > unsafeWrite
Definition: outputHandlerDcap.h:14
dcapIoCommon::dcapIoCommon
dcapIoCommon(const std::string &aPath)
Definition: dcapCommon.cpp:181
block::nullBufferSize
static size_t nullBufferSize()
Definition: block.cpp:34
errMsg::level::err
@ err
throttle::watch::wait
void wait()
Definition: throttle.h:50
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
throwcall::dcap::good0
void good0(T call, const Args &... args)
Definition: dcapCommon.h:21
block::size
size_t size() const
Definition: block.h:16
writeRateLimit
throttle::watch writeRateLimit
dcapIoCommon::fd
int fd
Definition: dcapCommon.h:77
enumAsBitmask::clear
void clear(const T aBits)
Definition: enumAsBitmask.h:31
throttle::watch::update
void update(double units=1.0)
Definition: throttle.h:35
copyRequest::stateBitType::append
@ append