XRootD
Loading...
Searching...
No Matches
CephIOAdapterRaw.cc
Go to the documentation of this file.
1#include "CephIOAdapterRaw.hh"
2#include "../XrdCephPosix.hh"
3#include "XrdOuc/XrdOucEnv.hh"
4
5#include <iostream>
6#include <chrono>
7#include <ratio>
8
9using namespace XrdCephBuffer;
10
11using myclock = std::chrono::steady_clock;
12//using myseconds = std::chrono::duration<float,
13
15 bool useStriperlessReads) :
16 m_bufferdata(bufferdata),m_fd(fd),
17 m_useStriperlessReads(useStriperlessReads) {
18}
19
21 // nothing to specifically to do; just print out some stats
22 float read_speed{0}, write_speed{0};
23 if (m_stats_read_req.load() > 0 && m_stats_read_timer.load() > 0 ) {
24 read_speed = m_stats_read_bytes.load() / m_stats_read_timer.load() * 1e-6;
25 }
26 if (m_stats_write_req.load() > 0 && m_stats_read_timer.load() > 0 ) {
27 write_speed = m_stats_write_bytes.load() / m_stats_write_timer.load() * 1e-6;
28 }
29 BUFLOG("CephIOAdapterRaw::Summary fd:" << m_fd
30 << " nwrite:" << m_stats_write_req << " byteswritten:" << m_stats_write_bytes << " write_s:"
31 << m_stats_write_timer * 1e-6 << " writemax_s" << m_stats_write_longest * 1e-6
32 << " write_MBs:" << write_speed
33 << " nread:" << m_stats_read_req << " bytesread:" << m_stats_read_bytes << " read_s:"
34 << m_stats_read_timer * 1e-6 << " readmax_s:" << m_stats_read_longest * 1e-6
35 << " read_MBs:" << read_speed
36 << " striperlessRead: " << m_useStriperlessReads
37 );
38
39}
40
41ssize_t CephIOAdapterRaw::write(off64_t offset,size_t count) {
42 const void* buf = m_bufferdata->raw();
43 if (!buf) return -EINVAL;
44
45 auto start = std::chrono::steady_clock::now();
46 ssize_t rc = ceph_posix_pwrite(m_fd,buf,count,offset);
47 auto end = std::chrono::steady_clock::now();
48 auto int_ns = std::chrono::duration_cast<std::chrono::nanoseconds>(end-start);
49
50 // BUFLOG("CephIOAdapterRaw::write fd:" << m_fd << " " << rc << " "
51 // << offset << " " << count << " " << rc << " " << int_ms.count() );
52
53 if (rc < 0) return rc;
54 m_stats_write_longest = std::max(m_stats_write_longest,static_cast<long long>(int_ns.count()));
55 m_stats_write_timer.fetch_add(static_cast<long long>(int_ns.count()));
56 m_stats_write_bytes.fetch_add(rc);
57 ++m_stats_write_req;
58 return rc;
59}
60
61
62ssize_t CephIOAdapterRaw::read(off64_t offset, size_t count) {
63 void* buf = m_bufferdata->raw();
64 if (!buf) {
65 return -EINVAL;
66 }
67 ssize_t rc {0};
68
69 // no check is made whether the buffer has sufficient capacity
70 auto start = std::chrono::steady_clock::now();
71 rc = ceph_posix_maybestriper_pread(m_fd,buf,count,offset, m_useStriperlessReads);
72 auto end = std::chrono::steady_clock::now();
73 //auto elapsed = end-start;
74 auto int_ns = std::chrono::duration_cast<std::chrono::nanoseconds>(end-start);
75
76 if (rc < 0) {
77 BUFLOG("CephIOAdapterRaw::read: Error in read: " << rc );
78 return rc;
79 }
80
81 m_stats_read_longest = std::max(m_stats_read_longest,static_cast<long long>(int_ns.count()));
82 m_stats_read_timer.fetch_add(static_cast<long long>(int_ns.count()));
83 m_stats_read_bytes.fetch_add(rc);
84 ++m_stats_read_req;
85
86 // BUFLOG("CephIOAdapterRaw::read fd:" << m_fd << " " << rc << " " << offset
87 // << " " << count << " " << rc << " " << int_ms.count() );
88
89 if (rc>=0) {
90 m_bufferdata->setLength(rc);
91 m_bufferdata->setStartingOffset(offset);
92 m_bufferdata->setValid(true);
93 }
94 return rc;
95}
96
#define BUFLOG(x)
std::chrono::steady_clock myclock
ssize_t ceph_posix_maybestriper_pread(int fd, void *buf, size_t count, off64_t offset, bool allowStriper)
ssize_t ceph_posix_pwrite(int fd, const void *buf, size_t count, off64_t offset)
virtual ssize_t read(off64_t offset, size_t count) override
Issue a ceph_posix_pread to read to the buffer data from file offset and len count....
virtual ssize_t write(off64_t offset, size_t count) override
Take the data in the buffer and write to ceph at given offset Issues a ceph_posix_pwrite for data in ...
CephIOAdapterRaw(IXrdCephBufferData *bufferdata, int fd, bool useStriperlessReads)
Interface to the Buffer's physical representation. Allow an interface to encapsulate the requirements...
virtual const void * raw() const =0
write data into the buffer, store the external offset
virtual off_t setStartingOffset(off_t offset)=0
virtual void setLength(size_t len)=0
Currently occupied and valid space, which may be less than capacity.
virtual void setValid(bool isValid)=0
is a simple implementation of IXrdCephBufferData using std::vector<char> representation for the buffe...