XRootD
XrdPfc::DataFsSnapshot Struct Reference

#include <XrdPfcDirStateSnapshot.hh>

+ Inheritance diagram for XrdPfc::DataFsSnapshot:
+ Collaboration diagram for XrdPfc::DataFsSnapshot:

Public Member Functions

 DataFsSnapshot ()
 
 DataFsSnapshot (const DataFsStateBase &b, time_t sshot_stats_reset_time)
 
void dump ()
 
void write_json_file (const std::string &fname, XrdOss &oss, bool include_preamble)
 

Public Attributes

std::vector< DirStateElementm_dir_states
 
time_t m_sshot_stats_reset_time = 0
 
- Public Attributes inherited from XrdPfc::DataFsStateBase
long long m_disk_total = 0
 
long long m_disk_used = 0
 
long long m_file_usage = 0
 
long long m_meta_total = 0
 
long long m_meta_used = 0
 
time_t m_usage_update_time = 0
 

Detailed Description

Definition at line 35 of file XrdPfcDirStateSnapshot.hh.

Constructor & Destructor Documentation

◆ DataFsSnapshot() [1/2]

XrdPfc::DataFsSnapshot::DataFsSnapshot ( )
inline

Definition at line 40 of file XrdPfcDirStateSnapshot.hh.

40 {}

◆ DataFsSnapshot() [2/2]

XrdPfc::DataFsSnapshot::DataFsSnapshot ( const DataFsStateBase b,
time_t  sshot_stats_reset_time 
)
inline

Definition at line 41 of file XrdPfcDirStateSnapshot.hh.

41  :
42  DataFsStateBase(b),
43  m_sshot_stats_reset_time(sshot_stats_reset_time)
44  {}

Member Function Documentation

◆ dump()

void DataFsSnapshot::dump ( )

Definition at line 153 of file XrdPfcDirStateSnapshot.cc.

154 {
155  nlohmann::ordered_json j;
156  to_json(j, *this);
157  std::cout << j.dump(3) << "\n";
158 }

◆ write_json_file()

void DataFsSnapshot::write_json_file ( const std::string &  fname,
XrdOss oss,
bool  include_preamble 
)

Definition at line 70 of file XrdPfcDirStateSnapshot.cc.

71 {
72  // Create the data file.const
73  const Configuration &conf = Cache::Conf();
74  const char *myUser = conf.m_username.c_str();
75  XrdOucEnv myEnv;
76 
77  const char* size_str = "524288";
78  myEnv.Put("oss.asize", size_str); // advisory size
79  myEnv.Put("oss.cgroup", conf.m_data_space.c_str()); // AMT: data or metadata space
80 
81  mode_t mode = 0644;
82 
83  int cret;
84  if ((cret = oss.Create(myUser, file_path.c_str(), mode, myEnv, XRDOSS_mkpath)) != XrdOssOK)
85  {
86  TRACE(Error, "Create failed for data file " << file_path << ERRNO_AND_ERRSTR(-cret));
87  return;
88  }
89 
90  XrdOssDF *myFile = oss.newFile(myUser);
91  if ((cret = myFile->Open(file_path.c_str(), O_RDWR, mode, myEnv)) != XrdOssOK)
92  {
93  TRACE(Error, "Open failed for data file " << file_path << ERRNO_AND_ERRSTR(-cret));
94  delete myFile;
95  return;
96  }
97 
98  // Fill the data file.
99  std::ostringstream os;
100 
101  if (include_preamble)
102  {
103  os << "{ \"dirstate_snapshot\": ";
104  }
105 
106  nlohmann::ordered_json j;
107  to_json(j, *this);
108 
109  os << std::setw(1);
110  os << j;
111 
112  if (include_preamble)
113  {
114  os << " }";
115  }
116 
117  os << "\n";
118  myFile->Ftruncate(0);
119  myFile->Write(os.str().c_str(), 0, os.str().size());
120  myFile->Close(); delete myFile;
121 
122  // Create the info file.
123 
124  std::string cinfo_path(file_path + Info::s_infoExtension);
125 
126  if ((cret = oss.Create(myUser, cinfo_path.c_str(), mode, myEnv, XRDOSS_mkpath)) != XrdOssOK)
127  {
128  TRACE(Error, "Create failed for info file " << cinfo_path << ERRNO_AND_ERRSTR(-cret));
129  myFile->Close(); delete myFile;
130  return;
131  }
132 
133  XrdOssDF *myInfoFile = oss.newFile(myUser);
134  if ((cret = myInfoFile->Open(cinfo_path.c_str(), O_RDWR, mode, myEnv)) != XrdOssOK)
135  {
136  TRACE(Error, "Open failed for info file " << cinfo_path << ERRNO_AND_ERRSTR(-cret));
137  delete myInfoFile;
138  myFile->Close(); delete myFile;
139  return;
140  }
141 
142  // Fill up cinfo.
143 
144  Info myInfo(GetTrace(), false);
145  myInfo.SetBufferSizeFileSizeAndCreationTime(512*1024, os.str().size());
146  myInfo.SetAllBitsSynced();
147 
148  myInfo.Write(myInfoFile, cinfo_path.c_str());
149  myInfoFile->Close();
150  delete myInfoFile;
151 }
#define XrdOssOK
Definition: XrdOss.hh:50
#define XRDOSS_mkpath
Definition: XrdOss.hh:466
#define ERRNO_AND_ERRSTR(err_code)
Definition: XrdPfcTrace.hh:46
#define TRACE(act, x)
Definition: XrdTrace.hh:63
virtual int Ftruncate(unsigned long long flen)
Definition: XrdOss.hh:164
virtual int Close(long long *retsz=0)=0
virtual int Open(const char *path, int Oflag, mode_t Mode, XrdOucEnv &env)
Definition: XrdOss.hh:200
virtual ssize_t Write(const void *buffer, off_t offset, size_t size)
Definition: XrdOss.hh:345
virtual int Create(const char *tid, const char *path, mode_t mode, XrdOucEnv &env, int opts=0)=0
virtual XrdOssDF * newFile(const char *tident)=0
void Put(const char *varname, const char *value)
Definition: XrdOucEnv.hh:85
static const Configuration & Conf()
Definition: XrdPfc.cc:134
Status of cached file. Can be read from and written into a binary file.
Definition: XrdPfcInfo.hh:41
static const char * s_infoExtension
Definition: XrdPfcInfo.hh:309
Contains parameters configurable from the xrootd config file.
Definition: XrdPfc.hh:64
std::string m_data_space
oss space for data files
Definition: XrdPfc.hh:88
std::string m_username
username passed to oss plugin
Definition: XrdPfc.hh:87

References XrdOssDF::Close(), XrdPfc::Cache::Conf(), XrdOss::Create(), ERRNO_AND_ERRSTR, Macaroons::Error, XrdOssDF::Ftruncate(), XrdPfc::Configuration::m_data_space, XrdPfc::Configuration::m_username, XrdOss::newFile(), XrdOssDF::Open(), XrdOucEnv::Put(), XrdPfc::Info::s_infoExtension, XrdPfc::Info::SetAllBitsSynced(), XrdPfc::Info::SetBufferSizeFileSizeAndCreationTime(), TRACE, XrdOssDF::Write(), XrdPfc::Info::Write(), XRDOSS_mkpath, and XrdOssOK.

Referenced by XrdPfc::ResourceMonitor::heart_beat().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ m_dir_states

std::vector<DirStateElement> XrdPfc::DataFsSnapshot::m_dir_states

Definition at line 37 of file XrdPfcDirStateSnapshot.hh.

Referenced by XrdPfc::ResourceMonitor::heart_beat().

◆ m_sshot_stats_reset_time

time_t XrdPfc::DataFsSnapshot::m_sshot_stats_reset_time = 0

Definition at line 38 of file XrdPfcDirStateSnapshot.hh.


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