XRootD
Loading...
Searching...
No Matches
XrdCephBuffer::XrdCephBufferDataSimple Class Reference

Implementation of a buffer using a simple vector<char> Simplest implementation of a buffer using vector<char> for underlying memory. Capacity is reserved on construction and released back at destruction. Does very little itself, except to provide access methods. More...

#include <XrdCephBufferDataSimple.hh>

+ Inheritance diagram for XrdCephBuffer::XrdCephBufferDataSimple:
+ Collaboration diagram for XrdCephBuffer::XrdCephBufferDataSimple:

Public Member Functions

 XrdCephBufferDataSimple (size_t bufCapacity)
 
virtual ~XrdCephBufferDataSimple ()
 
virtual size_t capacity () const override
 
virtual ssize_t invalidate () override
 copy data from the internal buffer to buf
 
virtual bool isValid () const override
 Currently occupied and valid space, which may be less than capacity.
 
virtual size_t length () const override
 total available space
 
virtual const void * raw () const override
 write data into the buffer, store the external offset if provided
 
virtual void * raw () override
 
virtual ssize_t readBuffer (void *buf, off_t offset, size_t blen) const override
 set cache into an invalid state
 
virtual void setLength (size_t len) override
 Currently occupied and valid space, which may be less than capacity.
 
virtual off_t setStartingOffset (off_t offset) override
 
virtual void setValid (bool isValid) override
 
virtual off_t startingOffset () const override
 
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
 
- Public Member Functions inherited from XrdCephBuffer::IXrdCephBufferData
virtual ~IXrdCephBufferData ()
 

Protected Attributes

std::vector< char > m_buffer
 
size_t m_bufferSize
 
size_t m_bufLength = 0
 what does the first byte of the buffer map to for external offsets
 
off_t m_externalOffset = 0
 
std::atomic< long > m_stats_read_bytes {0}
 
long m_stats_read_longest {0}
 
std::atomic< long > m_stats_read_req {0}
 
std::atomic< long > m_stats_read_timer {0}
 length of valid stored data; might be less than the capacity
 
std::atomic< long > m_stats_write_bytes {0}
 
long m_stats_write_longest {0}
 
std::atomic< long > m_stats_write_req {0}
 
std::atomic< long > m_stats_write_timer {0}
 
bool m_valid = false
 the buffer size
 

Static Protected Attributes

static std::atomic< long > m_total_memory_nbuffers {0}
 total number of buffers actively open
 
static std::atomic< long > m_total_memory_used {0}
 total memory of all these buffers
 

Detailed Description

Implementation of a buffer using a simple vector<char> Simplest implementation of a buffer using vector<char> for underlying memory. Capacity is reserved on construction and released back at destruction. Does very little itself, except to provide access methods.

Definition at line 23 of file XrdCephBufferDataSimple.hh.

Constructor & Destructor Documentation

◆ XrdCephBufferDataSimple()

XrdCephBufferDataSimple::XrdCephBufferDataSimple ( size_t bufCapacity)

Definition at line 23 of file XrdCephBufferDataSimple.cc.

23 :
24 m_bufferSize(bufCapacity), m_buffer(bufCapacity,0), m_externalOffset(0),m_bufLength(0) {
25 m_valid = true;
26
27 // update global statistics
28 m_total_memory_used.fetch_add(bufCapacity);
30 BUFLOG("XrdCephBufferDataSimple: Global: " << m_total_memory_nbuffers.load() << " " << m_total_memory_used.load());
31}
#define BUFLOG(x)
size_t m_bufLength
what does the first byte of the buffer map to for external offsets
static std::atomic< long > m_total_memory_nbuffers
total number of buffers actively open
static std::atomic< long > m_total_memory_used
total memory of all these buffers

References BUFLOG, m_buffer, m_bufferSize, m_bufLength, m_externalOffset, m_total_memory_nbuffers, m_total_memory_used, and m_valid.

◆ ~XrdCephBufferDataSimple()

XrdCephBufferDataSimple::~XrdCephBufferDataSimple ( )
virtual

Definition at line 33 of file XrdCephBufferDataSimple.cc.

33 {
34 m_valid = false;
35 // obtain the actual capacity here, as this is the real number of bytes to be released
36 auto cap = m_buffer.capacity();
37 m_buffer.clear();
38 m_buffer.reserve(0); // just to be paranoid and realse memory immediately
39
40 // update global statistics
41 m_total_memory_used.fetch_add(-cap);
43 BUFLOG("XrdCephBufferDataSimple~: Global: " << m_total_memory_nbuffers.load() << " " << m_total_memory_used.load());
44
45}

References BUFLOG, m_buffer, m_total_memory_nbuffers, m_total_memory_used, and m_valid.

Member Function Documentation

◆ capacity()

size_t XrdCephBufferDataSimple::capacity ( ) const
overridevirtual

Implements XrdCephBuffer::IXrdCephBufferData.

Definition at line 48 of file XrdCephBufferDataSimple.cc.

48 {
49 // return defined buffered size, which might in principle be different
50 // to the actual size of the buffer allocated in memory
51 return m_bufferSize;
52}

References m_bufferSize.

Referenced by raw(), raw(), and writeBuffer().

+ Here is the caller graph for this function:

◆ invalidate()

ssize_t XrdCephBufferDataSimple::invalidate ( )
overridevirtual

copy data from the internal buffer to buf

Implements XrdCephBuffer::IXrdCephBufferData.

Definition at line 76 of file XrdCephBufferDataSimple.cc.

76 {
78 m_bufLength = 0;
79 m_valid = false;
80 //m_buffer.clear(); // do we really need to clear the elements ?
81 return 0;
82}

References m_bufLength, m_externalOffset, and m_valid.

◆ isValid()

bool XrdCephBufferDataSimple::isValid ( ) const
overridevirtual

Currently occupied and valid space, which may be less than capacity.

Implements XrdCephBuffer::IXrdCephBufferData.

Definition at line 60 of file XrdCephBufferDataSimple.cc.

60 {
61 return m_valid;
62}

References m_valid.

Referenced by setValid().

+ Here is the caller graph for this function:

◆ length()

size_t XrdCephBufferDataSimple::length ( ) const
overridevirtual

total available space

Implements XrdCephBuffer::IXrdCephBufferData.

Definition at line 54 of file XrdCephBufferDataSimple.cc.

54 {
55 return m_bufLength;
56}

References m_bufLength.

◆ raw() [1/2]

virtual const void * XrdCephBuffer::XrdCephBufferDataSimple::raw ( ) const
inlineoverridevirtual

write data into the buffer, store the external offset if provided

Implements XrdCephBuffer::IXrdCephBufferData.

Definition at line 43 of file XrdCephBufferDataSimple.hh.

43{return capacity() > 0 ? &(m_buffer[0]) : nullptr;}

References capacity(), and m_buffer.

+ Here is the call graph for this function:

◆ raw() [2/2]

virtual void * XrdCephBuffer::XrdCephBufferDataSimple::raw ( )
inlineoverridevirtual

Implements XrdCephBuffer::IXrdCephBufferData.

Definition at line 44 of file XrdCephBufferDataSimple.hh.

44{return capacity() > 0 ? &(m_buffer[0]) : nullptr;}

References capacity(), and m_buffer.

+ Here is the call graph for this function:

◆ readBuffer()

ssize_t XrdCephBufferDataSimple::readBuffer ( void * buf,
off_t offset,
size_t blen ) const
overridevirtual

set cache into an invalid state

Implements XrdCephBuffer::IXrdCephBufferData.

Definition at line 86 of file XrdCephBufferDataSimple.cc.

86 {
87 // read from the internal buffer to buf (at pos 0), from offset for blen, or max length possible
88 // returns -ve value on error, else the actual number of bytes read
89
90 if (!m_valid) {
91 return -EINVAL;
92 }
93 if (offset < 0) {
94 return -EINVAL;
95 }
96 if (offset > (ssize_t) m_bufLength) {
97 return 0;
98 }
99 ssize_t readlength = blen;
100 if (offset + blen > m_bufLength) {
101 readlength = m_bufLength - offset;
102 }
103 //std::cout << readlength << " " << blen << " " << m_bufLength << " " << offset << std::endl;
104 if (readlength <0) {
105 return -EINVAL;
106 }
107
108 if (readlength == 0) {
109 return 0;
110 }
111
112 const char* rawbufstart = m_buffer.data();
113
114 long int_ns{0};
115 {auto t = Timer_ns(int_ns);
116 // std::copy(rawbufstart + offset, rawbufstart+offset+readlength, reinterpret_cast<char*>(buf) );
117 memcpy(reinterpret_cast<char*>(buf), rawbufstart + offset, readlength);
118 } // end Timer
119 // BUFLOG("XrdCephBufferDataSimple::readBuffer: " << offset << " " << readlength << " " << int_ns );
120
121 return readlength;
122}

References m_buffer, m_bufLength, and m_valid.

◆ setLength()

void XrdCephBufferDataSimple::setLength ( size_t len)
overridevirtual

Currently occupied and valid space, which may be less than capacity.

Implements XrdCephBuffer::IXrdCephBufferData.

Definition at line 57 of file XrdCephBufferDataSimple.cc.

57 {
58 m_bufLength = len;
59}

References m_bufLength.

◆ setStartingOffset()

off_t XrdCephBufferDataSimple::setStartingOffset ( off_t offset)
overridevirtual

Implements XrdCephBuffer::IXrdCephBufferData.

Definition at line 71 of file XrdCephBufferDataSimple.cc.

71 {
72 m_externalOffset = offset;
73 return m_externalOffset;
74}

References m_externalOffset.

◆ setValid()

void XrdCephBufferDataSimple::setValid ( bool isValid)
overridevirtual

Implements XrdCephBuffer::IXrdCephBufferData.

Definition at line 63 of file XrdCephBufferDataSimple.cc.

63 {
65}
virtual bool isValid() const override
Currently occupied and valid space, which may be less than capacity.

References isValid(), and m_valid.

+ Here is the call graph for this function:

◆ startingOffset()

off_t XrdCephBufferDataSimple::startingOffset ( ) const
overridevirtual

Implements XrdCephBuffer::IXrdCephBufferData.

Definition at line 68 of file XrdCephBufferDataSimple.cc.

68 {
69 return m_externalOffset;
70}

References m_externalOffset.

◆ writeBuffer()

ssize_t XrdCephBufferDataSimple::writeBuffer ( const void * buf,
off_t offset,
size_t blen,
off_t externalOffset = 0 )
overridevirtual

set cache into an invalid state; do this before writes to be consistent

Implements XrdCephBuffer::IXrdCephBufferData.

Definition at line 125 of file XrdCephBufferDataSimple.cc.

125 {
126 // write data from buf (from pos 0), with length blen, into the buffer at position offset (local to the internal buffer)
127
128 // #TODO Add test to see if it's in use
129 //invalidate();
130
131 if (offset < 0) {
132 BUFLOG("XrdCephBufferDataSimple::writeBuffer: offset <0");
133 return -EINVAL;
134 }
135
136 ssize_t cap = capacity();
137 if ((ssize_t)blen > cap) {
138 BUFLOG("XrdCephBufferDataSimple::writeBuffer: blen > cap:" << blen << " > " << cap);
139 return -EINVAL;
140 }
141 if ((ssize_t)offset > cap) {
142 BUFLOG("XrdCephBufferDataSimple::writeBuffer: offset > cap:" << offset << " > " << cap);
143 return -EINVAL;
144 }
145 if (ssize_t(offset + blen) > cap) {
146 BUFLOG("XrdCephBufferDataSimple::writeBuffer: (offset + blen) > cap: (" << offset << " + " << blen << ") >" << cap);
147 return -EINVAL;
148 }
149
150 // std::vector<char>::iterator itstart = m_buffer.begin();
151 size_t readBytes = blen;
152 char* rawbufstart = m_buffer.data();
153
154
155 long int_ns{0};
156 {auto t = Timer_ns(int_ns); // brace for timer start/stop scoping
157 //std::copy((char*)buf, (char*)buf +readBytes ,itstart + offset );
158 memcpy(rawbufstart + offset, buf, readBytes);
159
160 } // end Timer
161
162 // BUFLOG("XrdCephBufferDataSimple::writeBuffer: " << offset << " " << readBytes << " " << int_ns);
163
164
165
166 m_externalOffset = externalOffset;
167 // Decide to set the length of the maximum value that has be written
168 // note; unless invalidate is called, then this value may not be correctly set ...
169 m_bufLength = std::max(offset+blen, m_bufLength);
170 m_valid = true;
171
172
173 return readBytes;
174}

References BUFLOG, capacity(), m_buffer, m_bufLength, m_externalOffset, and m_valid.

+ Here is the call graph for this function:

Member Data Documentation

◆ m_buffer

std::vector<char> XrdCephBuffer::XrdCephBufferDataSimple::m_buffer
protected

◆ m_bufferSize

size_t XrdCephBuffer::XrdCephBufferDataSimple::m_bufferSize
protected

Definition at line 48 of file XrdCephBufferDataSimple.hh.

Referenced by XrdCephBufferDataSimple(), and capacity().

◆ m_bufLength

size_t XrdCephBuffer::XrdCephBufferDataSimple::m_bufLength = 0
protected

what does the first byte of the buffer map to for external offsets

Definition at line 52 of file XrdCephBufferDataSimple.hh.

Referenced by XrdCephBufferDataSimple(), invalidate(), length(), readBuffer(), setLength(), and writeBuffer().

◆ m_externalOffset

off_t XrdCephBuffer::XrdCephBufferDataSimple::m_externalOffset = 0
protected

◆ m_stats_read_bytes

std::atomic< long> XrdCephBuffer::XrdCephBufferDataSimple::m_stats_read_bytes {0}
protected

Definition at line 56 of file XrdCephBufferDataSimple.hh.

◆ m_stats_read_longest

long XrdCephBuffer::XrdCephBufferDataSimple::m_stats_read_longest {0}
protected

◆ m_stats_read_req

std::atomic< long> XrdCephBuffer::XrdCephBufferDataSimple::m_stats_read_req {0}
protected

Definition at line 57 of file XrdCephBufferDataSimple.hh.

◆ m_stats_read_timer

std::atomic< long> XrdCephBuffer::XrdCephBufferDataSimple::m_stats_read_timer {0}
protected

length of valid stored data; might be less than the capacity

Definition at line 55 of file XrdCephBufferDataSimple.hh.

◆ m_stats_write_bytes

std::atomic< long> XrdCephBuffer::XrdCephBufferDataSimple::m_stats_write_bytes {0}
protected

Definition at line 56 of file XrdCephBufferDataSimple.hh.

◆ m_stats_write_longest

long XrdCephBuffer::XrdCephBufferDataSimple::m_stats_write_longest {0}
protected

Definition at line 58 of file XrdCephBufferDataSimple.hh.

◆ m_stats_write_req

std::atomic< long> XrdCephBuffer::XrdCephBufferDataSimple::m_stats_write_req {0}
protected

Definition at line 57 of file XrdCephBufferDataSimple.hh.

57{0}, m_stats_write_req{0};

◆ m_stats_write_timer

std::atomic< long> XrdCephBuffer::XrdCephBufferDataSimple::m_stats_write_timer {0}
protected

Definition at line 55 of file XrdCephBufferDataSimple.hh.

◆ m_total_memory_nbuffers

std::atomic< long > XrdCephBufferDataSimple::m_total_memory_nbuffers {0}
staticprotected

total number of buffers actively open

Definition at line 62 of file XrdCephBufferDataSimple.hh.

Referenced by XrdCephBufferDataSimple(), and ~XrdCephBufferDataSimple().

◆ m_total_memory_used

std::atomic< long > XrdCephBufferDataSimple::m_total_memory_used {0}
staticprotected

total memory of all these buffers

Definition at line 61 of file XrdCephBufferDataSimple.hh.

Referenced by XrdCephBufferDataSimple(), and ~XrdCephBufferDataSimple().

◆ m_valid

bool XrdCephBuffer::XrdCephBufferDataSimple::m_valid = false
protected

The documentation for this class was generated from the following files: