XRootD
XrdPfcIO.cc
Go to the documentation of this file.
1 #include "XrdPfcIO.hh"
2 #include "XrdPfcTrace.hh"
3 #include "XrdCl/XrdClURL.hh"
4 
5 using namespace XrdPfc;
6 
7 IO::IO(XrdOucCacheIO *io, Cache &cache) :
8  m_cache (cache),
9  m_traceID ("IO"),
10  m_active_read_reqs(0),
11  m_io (io),
12  m_read_seqid (0u)
13 {}
14 
15 //==============================================================================
16 
18 {
19  SetInput(&iocp);
21  TRACE_PC(Info, const char* loc = GetLocation(),
22  "Update() " << Path() << " location: " <<
23  ((loc && loc[0] != 0) ? loc : "<not set>"));
24 }
25 
26 void IO::SetInput(XrdOucCacheIO* x)
27 {
28  m_io = x;
29 }
30 
32 {
33  return m_io;
34 }
35 
36 std::string IO::GetFilename()
37 {
38  return XrdCl::URL(GetPath()).GetPath();
39 }
40 
41 //==============================================================================
42 
44 {
45  // Called from XrdPosixFile when local connection is closed.
46 
47  if ( ! ioActive())
48  {
50 
51  return true;
52  }
53  else
54  {
55  class FutureDetach : public XrdJob
56  {
57  IO *f_io;
58  XrdOucCacheIOCD *f_detach_cb;
59  time_t f_wait_time;
60 
61  public:
62  FutureDetach(IO *io, XrdOucCacheIOCD *cb, time_t wt) :
63  f_io (io),
64  f_detach_cb (cb),
65  f_wait_time (wt)
66  {}
67 
68  void DoIt()
69  {
70  if (f_io->ioActive())
71  {
72  // Reschedule up to 120 sec in the future.
73  f_wait_time = std::min(2 * f_wait_time, (time_t) 120);
74  Schedule();
75  }
76  else
77  {
78  f_io->DetachFinalize();
79  f_detach_cb->DetachDone();
80 
81  delete this;
82  }
83  }
84 
85  void Schedule()
86  {
87  Cache::schedP->Schedule(this, time(0) + f_wait_time);
88  }
89  };
90 
91  (new FutureDetach(this, &iocdP, 10))->Schedule();
92 
93  return false;
94  }
95 }
int DoIt(int argpnt, int argc, char **argv, bool singleshot)
Definition: XrdAccTest.cc:262
#define TRACE_PC(act, pre_code, x)
Definition: XrdPfcTrace.hh:59
URL representation.
Definition: XrdClURL.hh:31
const std::string & GetPath() const
Get the path.
Definition: XrdClURL.hh:217
Definition: XrdJob.hh:43
virtual void DetachDone()=0
Indicate that the CacheIO object has been detached.
Attaches/creates and detaches/deletes cache-io objects for disk based cache.
Definition: XrdPfc.hh:152
static XrdScheduler * schedP
Definition: XrdPfc.hh:290
Base cache-io class that implements some XrdOucCacheIO abstract methods.
Definition: XrdPfcIO.hh:16
const char * GetPath()
Definition: XrdPfcIO.hh:53
IO(XrdOucCacheIO *io, Cache &cache)
Definition: XrdPfcIO.cc:7
XrdOucCacheIO * GetInput()
Definition: XrdPfcIO.cc:31
const char * Path() override
Original data source URL.
Definition: XrdPfcIO.hh:24
const char * RefreshLocation()
Definition: XrdPfcIO.hh:55
bool Detach(XrdOucCacheIOCD &iocdP) final
Definition: XrdPfcIO.cc:43
virtual bool ioActive()=0
const char * GetLocation()
Definition: XrdPfcIO.hh:44
void Update(XrdOucCacheIO &iocp) override
Definition: XrdPfcIO.cc:17
virtual void DetachFinalize()=0
std::string GetFilename()
Definition: XrdPfcIO.cc:36
Status of cached file. Can be read from and written into a binary file.
Definition: XrdPfcInfo.hh:41
void Schedule(XrdJob *jp)
Definition: XrdPfc.hh:41