Loading...
Searching...
No Matches
XrdCephBufferDataSimple.hh
Go to the documentation of this file.
#ifndef __XRD_CEPH_BUFFER_DATA_SIMPLE_HH__
#define __XRD_CEPH_BUFFER_DATA_SIMPLE_HH__
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
#include <sys/types.h>
#include "IXrdCephBufferData.hh"
#include "BufferUtils.hh"
#include <vector>
#include <atomic>
#include <chrono>
namespace XrdCephBuffer {
class XrdCephBufferDataSimple : public virtual IXrdCephBufferData
{
public:
XrdCephBufferDataSimple(size_t bufCapacity);
virtual ~XrdCephBufferDataSimple();
virtual size_t capacity() const override;
virtual size_t length() const override;
virtual void setLength(size_t len) override;
virtual bool isValid() const override;
virtual void setValid(bool isValid) override;
virtual off_t startingOffset() const override;
virtual off_t setStartingOffset(off_t offset) override;
virtual ssize_t readBuffer(void* buf, off_t offset, size_t blen) const override;
virtual ssize_t invalidate() override;
virtual ssize_t writeBuffer(const void* buf, off_t offset, size_t blen, off_t externalOffset=0) override;
virtual const void* raw() const override {return capacity() > 0 ? &(m_buffer[0]) : nullptr;}
virtual void* raw() override {return capacity() > 0 ? &(m_buffer[0]) : nullptr;}
protected:
size_t m_bufferSize;
bool m_valid = false;
std::vector<char> m_buffer; // actual physical buffer
off_t m_externalOffset = 0;
size_t m_bufLength = 0;
// timer and counter info
std::atomic< long> m_stats_read_timer{0}, m_stats_write_timer{0};
std::atomic< long> m_stats_read_bytes{0}, m_stats_write_bytes{0};
std::atomic< long> m_stats_read_req{0}, m_stats_write_req{0};
long m_stats_read_longest{0}, m_stats_write_longest{0};
// staric vars to store the total useage of memory across this class
static std::atomic<long> m_total_memory_used;
static std::atomic<long> m_total_memory_nbuffers;
}; // XrdCephBufferDataSimple
} // namespace
#endif
BufferUtils.hh
IXrdCephBufferData.hh
XrdCephBuffer::IXrdCephBufferData
Interface to the Buffer's physical representation. Allow an interface to encapsulate the requirements...
Definition IXrdCephBufferData.hh:18
XrdCephBuffer::XrdCephBufferDataSimple::raw
virtual void * raw() override
Definition XrdCephBufferDataSimple.hh:44
XrdCephBuffer::XrdCephBufferDataSimple::readBuffer
virtual ssize_t readBuffer(void *buf, off_t offset, size_t blen) const override
set cache into an invalid state
Definition XrdCephBufferDataSimple.cc:86
XrdCephBuffer::XrdCephBufferDataSimple::m_bufferSize
size_t m_bufferSize
Definition XrdCephBufferDataSimple.hh:48
XrdCephBuffer::XrdCephBufferDataSimple::setStartingOffset
virtual off_t setStartingOffset(off_t offset) override
Definition XrdCephBufferDataSimple.cc:71
XrdCephBuffer::XrdCephBufferDataSimple::m_stats_write_req
std::atomic< long > m_stats_write_req
Definition XrdCephBufferDataSimple.hh:57
XrdCephBuffer::XrdCephBufferDataSimple::m_stats_read_longest
long m_stats_read_longest
Definition XrdCephBufferDataSimple.hh:58
XrdCephBuffer::XrdCephBufferDataSimple::isValid
virtual bool isValid() const override
Currently occupied and valid space, which may be less than capacity.
Definition XrdCephBufferDataSimple.cc:60
XrdCephBuffer::XrdCephBufferDataSimple::capacity
virtual size_t capacity() const override
Definition XrdCephBufferDataSimple.cc:48
XrdCephBuffer::XrdCephBufferDataSimple::m_stats_write_longest
long m_stats_write_longest
Definition XrdCephBufferDataSimple.hh:58
XrdCephBuffer::XrdCephBufferDataSimple::m_stats_read_req
std::atomic< long > m_stats_read_req
Definition XrdCephBufferDataSimple.hh:57
XrdCephBuffer::XrdCephBufferDataSimple::startingOffset
virtual off_t startingOffset() const override
Definition XrdCephBufferDataSimple.cc:68
XrdCephBuffer::XrdCephBufferDataSimple::raw
virtual const void * raw() const override
write data into the buffer, store the external offset if provided
Definition XrdCephBufferDataSimple.hh:43
XrdCephBuffer::XrdCephBufferDataSimple::m_bufLength
size_t m_bufLength
what does the first byte of the buffer map to for external offsets
Definition XrdCephBufferDataSimple.hh:52
XrdCephBuffer::XrdCephBufferDataSimple::m_stats_write_bytes
std::atomic< long > m_stats_write_bytes
Definition XrdCephBufferDataSimple.hh:56
XrdCephBuffer::XrdCephBufferDataSimple::XrdCephBufferDataSimple
XrdCephBufferDataSimple(size_t bufCapacity)
Definition XrdCephBufferDataSimple.cc:23
XrdCephBuffer::XrdCephBufferDataSimple::m_stats_read_bytes
std::atomic< long > m_stats_read_bytes
Definition XrdCephBufferDataSimple.hh:56
XrdCephBuffer::XrdCephBufferDataSimple::invalidate
virtual ssize_t invalidate() override
copy data from the internal buffer to buf
Definition XrdCephBufferDataSimple.cc:76
XrdCephBuffer::XrdCephBufferDataSimple::m_externalOffset
off_t m_externalOffset
Definition XrdCephBufferDataSimple.hh:51
XrdCephBuffer::XrdCephBufferDataSimple::m_valid
bool m_valid
the buffer size
Definition XrdCephBufferDataSimple.hh:49
XrdCephBuffer::XrdCephBufferDataSimple::m_stats_write_timer
std::atomic< long > m_stats_write_timer
Definition XrdCephBufferDataSimple.hh:55
XrdCephBuffer::XrdCephBufferDataSimple::setValid
virtual void setValid(bool isValid) override
Definition XrdCephBufferDataSimple.cc:63
XrdCephBuffer::XrdCephBufferDataSimple::~XrdCephBufferDataSimple
virtual ~XrdCephBufferDataSimple()
Definition XrdCephBufferDataSimple.cc:33
XrdCephBuffer::XrdCephBufferDataSimple::writeBuffer
virtual ssize_t writeBuffer(const void *buf, off_t offset, size_t blen, off_t externalOffset=0) override
set cache into an invalid state; do this before writes to be consistent
Definition XrdCephBufferDataSimple.cc:125
XrdCephBuffer::XrdCephBufferDataSimple::m_total_memory_nbuffers
static std::atomic< long > m_total_memory_nbuffers
total number of buffers actively open
Definition XrdCephBufferDataSimple.hh:62
XrdCephBuffer::XrdCephBufferDataSimple::m_total_memory_used
static std::atomic< long > m_total_memory_used
total memory of all these buffers
Definition XrdCephBufferDataSimple.hh:61
XrdCephBuffer::XrdCephBufferDataSimple::length
virtual size_t length() const override
total available space
Definition XrdCephBufferDataSimple.cc:54
XrdCephBuffer::XrdCephBufferDataSimple::setLength
virtual void setLength(size_t len) override
Currently occupied and valid space, which may be less than capacity.
Definition XrdCephBufferDataSimple.cc:57
XrdCephBuffer::XrdCephBufferDataSimple::m_stats_read_timer
std::atomic< long > m_stats_read_timer
length of valid stored data; might be less than the capacity
Definition XrdCephBufferDataSimple.hh:55
XrdCephBuffer::XrdCephBufferDataSimple::m_buffer
std::vector< char > m_buffer
Definition XrdCephBufferDataSimple.hh:50
XrdCephBuffer
is a simple implementation of IXrdCephBufferData using std::vector<char> representation for the buffe...
Definition BufferUtils.hh:29