XRootD
Loading...
Searching...
No Matches
XrdCephBufferDataSimple.hh
Go to the documentation of this file.
1#ifndef __XRD_CEPH_BUFFER_DATA_SIMPLE_HH__
2#define __XRD_CEPH_BUFFER_DATA_SIMPLE_HH__
3//------------------------------------------------------------------------------
5//------------------------------------------------------------------------------
6
7#include <sys/types.h>
9#include "BufferUtils.hh"
10#include <vector>
11#include <atomic>
12#include <chrono>
13
14namespace XrdCephBuffer {
15
24 {
25 public:
26 XrdCephBufferDataSimple(size_t bufCapacity);
28 virtual size_t capacity() const override;
29 virtual size_t length() const override;
30 virtual void setLength(size_t len) override;
31 virtual bool isValid() const override;
32 virtual void setValid(bool isValid) override;
33
34 virtual off_t startingOffset() const override;
35 virtual off_t setStartingOffset(off_t offset) override;
36
37
38 virtual ssize_t readBuffer(void* buf, off_t offset, size_t blen) const override;
39
40 virtual ssize_t invalidate() override;
41 virtual ssize_t writeBuffer(const void* buf, off_t offset, size_t blen, off_t externalOffset=0) override;
42
43 virtual const void* raw() const override {return capacity() > 0 ? &(m_buffer[0]) : nullptr;}
44 virtual void* raw() override {return capacity() > 0 ? &(m_buffer[0]) : nullptr;}
45
46
47 protected:
48 size_t m_bufferSize;
49 bool m_valid = false;
50 std::vector<char> m_buffer; // actual physical buffer
51 off_t m_externalOffset = 0;
52 size_t m_bufLength = 0;
53
54 // timer and counter info
55 std::atomic< long> m_stats_read_timer{0}, m_stats_write_timer{0};
56 std::atomic< long> m_stats_read_bytes{0}, m_stats_write_bytes{0};
57 std::atomic< long> m_stats_read_req{0}, m_stats_write_req{0};
59
60 // staric vars to store the total useage of memory across this class
61 static std::atomic<long> m_total_memory_used;
62 static std::atomic<long> m_total_memory_nbuffers;
63
64}; // XrdCephBufferDataSimple
65
66} // namespace
67#endif
Interface to the Buffer's physical representation. Allow an interface to encapsulate the requirements...
Implementation of a buffer using a simple vector<char> Simplest implementation of a buffer using vect...
virtual ssize_t readBuffer(void *buf, off_t offset, size_t blen) const override
set cache into an invalid state
virtual off_t setStartingOffset(off_t offset) override
virtual bool isValid() const override
Currently occupied and valid space, which may be less than capacity.
virtual off_t startingOffset() const override
virtual const void * raw() const override
write data into the buffer, store the external offset if provided
size_t m_bufLength
what does the first byte of the buffer map to for external offsets
virtual ssize_t invalidate() override
copy data from the internal buffer to buf
virtual void setValid(bool isValid) 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
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
virtual size_t length() const override
total available space
virtual void setLength(size_t len) override
Currently occupied and valid space, which may be less than capacity.
std::atomic< long > m_stats_read_timer
length of valid stored data; might be less than the capacity
is a simple implementation of IXrdCephBufferData using std::vector<char> representation for the buffe...