xrootd
Main Page
Namespaces
Classes
Files
File List
File Members
src
XrdFileCache
XrdFileCache.hh
Go to the documentation of this file.
1
#ifndef __XRDFILECACHE_CACHE_HH__
2
#define __XRDFILECACHE_CACHE_HH__
3
//----------------------------------------------------------------------------------
4
// Copyright (c) 2014 by Board of Trustees of the Leland Stanford, Jr., University
5
// Author: Alja Mrak-Tadel, Matevz Tadel, Brian Bockelman
6
//----------------------------------------------------------------------------------
7
// XRootD is free software: you can redistribute it and/or modify
8
// it under the terms of the GNU Lesser General Public License as published by
9
// the Free Software Foundation, either version 3 of the License, or
10
// (at your option) any later version.
11
//
12
// XRootD is distributed in the hope that it will be useful,
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
// GNU General Public License for more details.
16
//
17
// You should have received a copy of the GNU Lesser General Public License
18
// along with XRootD. If not, see <http://www.gnu.org/licenses/>.
19
//----------------------------------------------------------------------------------
20
#include <string>
21
#include <list>
22
23
#include "
XrdSys/XrdSysPthread.hh
"
24
#include "
XrdOuc/XrdOucCache.hh
"
25
#include "
XrdCl/XrdClDefaultEnv.hh
"
26
27
namespace
XrdCl {
28
class
Log;
29
}
30
namespace
XrdFileCache {
31
class
Prefetch
;
32
}
33
34
namespace
XrdFileCache
35
{
36
//----------------------------------------------------------------------------
38
//----------------------------------------------------------------------------
39
class
Cache
:
public
XrdOucCache
40
{
41
friend
class
IOEntireFile
;
42
friend
class
IOFileBlock
;
43
44
public
:
45
//---------------------------------------------------------------------
47
//---------------------------------------------------------------------
48
Cache
(
XrdOucCacheStats
&);
49
50
//---------------------------------------------------------------------
52
//---------------------------------------------------------------------
53
virtual
XrdOucCacheIO
*
Attach
(
XrdOucCacheIO
*,
int
Options=0);
54
55
//---------------------------------------------------------------------
57
//---------------------------------------------------------------------
58
virtual
int
isAttached
();
59
60
//---------------------------------------------------------------------
63
//---------------------------------------------------------------------
64
virtual
XrdOucCache
*
Create
(
XrdOucCache::Parms
&,
XrdOucCacheIO::aprParms
*)
65
{
return
NULL; }
66
67
//---------------------------------------------------------------------
69
//---------------------------------------------------------------------
70
static
void
AddWriteTask
(
Prefetch
* p,
int
ramBlockidx,
size_t
size,
bool
fromRead);
71
72
//---------------------------------------------------------------------
74
//---------------------------------------------------------------------
75
static
bool
HaveFreeWritingSlots
();
76
77
//---------------------------------------------------------------------
80
//---------------------------------------------------------------------
81
static
void
RemoveWriteQEntriesFor
(
Prefetch
*p);
82
83
//---------------------------------------------------------------------
85
//---------------------------------------------------------------------
86
static
void
ProcessWriteTasks
();
87
88
private
:
90
void
Detach
(
XrdOucCacheIO
*);
91
93
bool
getFilePathFromURL
(
const
char
* url, std::string& res)
const
;
94
96
XrdCl::Log*
clLog
()
const
{
return
XrdCl::DefaultEnv::GetLog
(); }
97
98
XrdSysMutex
m_io_mutex
;
99
unsigned
int
m_attached
;
100
XrdOucCacheStats
&
m_stats
;
101
102
struct
WriteTask
103
{
104
Prefetch
*
prefetch
;
105
int
ramBlockIdx
;
106
size_t
size
;
107
WriteTask
(
Prefetch
* p,
int
ri,
size_t
s):
prefetch
(p),
ramBlockIdx
(ri),
size
(s){}
108
};
109
110
struct
WriteQ
111
{
112
WriteQ
() :
condVar
(0),
size
(0) {}
113
XrdSysCondVar
condVar
;
114
size_t
size
;
115
std::list<WriteTask>
queue
;
116
};
117
118
static
WriteQ
s_writeQ
;
119
120
};
121
122
//----------------------------------------------------------------------------
124
//----------------------------------------------------------------------------
125
class
IO
:
public
XrdOucCacheIO
126
{
127
friend
class
Prefetch
;
128
129
public
:
130
IO
(
XrdOucCacheIO
&io,
XrdOucCacheStats
&stats,
Cache
&cache) :
131
m_io
(io),
m_statsGlobal
(stats),
m_cache
(cache) {}
132
134
virtual
XrdOucCacheIO
*
Base
() {
return
&
m_io
; }
135
137
virtual
long
long
FSize
() {
return
m_io
.
FSize
(); }
138
140
virtual
const
char
*
Path
() {
return
m_io
.
Path
(); }
141
142
virtual
int
Sync
() {
return
0; }
143
144
virtual
int
Trunc
(
long
long
Offset) { errno = ENOTSUP;
return
-1; }
145
146
virtual
int
Write
(
char
*Buffer,
long
long
Offset,
int
Length)
147
{ errno = ENOTSUP;
return
-1; }
148
149
virtual
void
StartPrefetch
() {}
150
151
protected
:
152
XrdCl::Log*
clLog
()
const
{
return
XrdCl::DefaultEnv::GetLog
(); }
153
154
XrdOucCacheIO
&
m_io
;
155
XrdOucCacheStats
&
m_statsGlobal
;
156
Cache
&
m_cache
;
157
};
158
}
159
160
#endif
Generated by
1.8.3.1