XRootD
XrdOssArcBackupTask Class Reference

#include <XrdOssArcBackup.hh>

+ Collaboration diagram for XrdOssArcBackupTask:

Public Member Functions

 XrdOssArcBackupTask (XrdOssArcBackup &who, char *dsn)
 
 ~XrdOssArcBackupTask ()
 
bool BkpXeq ()
 

Public Attributes

XrdSysSemaphore btSem
 
size_t numBytes
 
int numFiles
 
XrdOssArcBackupOwner
 
bool relSpace
 
char * theDSN
 
const char * theScope
 

Detailed Description

Definition at line 47 of file XrdOssArcBackup.hh.

Constructor & Destructor Documentation

◆ XrdOssArcBackupTask()

XrdOssArcBackupTask::XrdOssArcBackupTask ( XrdOssArcBackup who,
char *  dsn 
)

Definition at line 92 of file XrdOssArcBackup.cc.

93  : Owner(who), theScope(who.Scope), theDSN(dsn),
94  numBytes(0), numFiles(0), relSpace(false),
95  btSem(0) {}
XrdOssArcBackup & Owner
XrdSysSemaphore btSem

◆ ~XrdOssArcBackupTask()

XrdOssArcBackupTask::~XrdOssArcBackupTask ( )

Definition at line 97 of file XrdOssArcBackup.cc.

98 {
99 // Remove entry of the dataset name from the owner's set
100 //
101  Owner.dsBkpSetMtx.Lock();
102  Owner.dsBkpSet.erase(theDSN);
103  Owner.dsBkpSetMtx.UnLock();
104 
105 // Release the space that this request acquired
106 //
108 
109 // Since theDSN was shared with the owner's set we can free the storage
110 //
111  free(theDSN);
112 }
void Release(size_t bytes)
XrdOssArcFSMon fsMon

References XrdOssArcGlobals::fsMon, XrdSysMutex::Lock(), numBytes, Owner, XrdOssArcFSMon::Release(), relSpace, theDSN, and XrdSysMutex::UnLock().

+ Here is the call graph for this function:

Member Function Documentation

◆ BkpXeq()

bool XrdOssArcBackupTask::BkpXeq ( )

Definition at line 118 of file XrdOssArcBackup.cc.

119 {
120 // The first step it to setup the staging area to create an archive. This is
121 // done using a scipt. The script returns the total number of files and bytes
122 // that will need to be backed up.
123 
124 // Construct the staging path for archive creation management
125 //
126  TraceInfo("BkpTask", 0);
127  XrdOucStream cmdSup;
128  char dsnDir[MAXPATHLEN], manPFN[MAXPATHLEN];
129  int n, rc;
130 
131 // We create an instance of the stop monitor. If a stop is in effect, it
132 // will not complete construction until the stop file is removed.
133 //
134  XrdOssArcStopMon stopMon(Config.stopMon);
135 
136 // Compose the arena path. Note that our arena path already ends with a slash
137 //
138  n = snprintf(dsnDir, sizeof(dsnDir), "%s%s/", Owner.Arena(),
140  if (n >= (int)sizeof(dsnDir))
141  {Elog.Emsg("Backup",ENAMETOOLONG,"create arena path for dataset",theDSN);
142  return false;
143  }
144 
145 // We now must create the directory path to the arena
146 //
147  if ((rc = XrdOucUtils::makePath(dsnDir, S_IRWXU|S_IRGRP|S_IXGRP)))
148  {Elog.Emsg("Backup", rc, "create dataset backup arena", dsnDir);
149  return false;
150  }
151 
152 // Generate name of the manifest file. This is needed by the preparc and
153 // postarc utilities plus we want to add it to the zip archive as provenance.
154 //
155  n = snprintf(manPFN, sizeof(manPFN), "%sManifest", dsnDir);
156  if (n >= (int)sizeof(manPFN))
157  {Elog.Emsg("Backup",ENAMETOOLONG,"create bkp manifest for dataset",
158  theDSN);
159  return false;
160  }
161 
162 // Construct the argument list
163 //
164  const char* supArgv[] = {"setup", Config.srcRSE, theScope, theDSN, dsnDir,
165  Config.srcData, manPFN};
166  int supArgc = sizeof(supArgv)/sizeof(char*);
167 
168 // Do some tracing
169 //
170  DEBUG("Running "<<Config.BkpUtilName<<' '<<supArgv[0]<<' '<<supArgv[1]<<
171  ' '<<supArgv[2]<<' '<<supArgv[3]<<' '<<supArgv[4]<<
172  ' '<<supArgv[5]<<' '<<supArgv[6]);
173 
174 // Run the setup script which prepares the dataset for archiving. It should
175 // output a single line: <files> <bytes>
176 //
177  if (!(rc = Config.BkpUtilProg->Run(&cmdSup, supArgv, supArgc)))
178  {char *lp, *retStr = 0;
179  size_t vb;
180  int vf;
181  bool isOK = false;
182  while((lp = cmdSup.GetLine())) if (!retStr) retStr = strdup(lp);
183 
184  if (retStr)
185  {n = sscanf(retStr, "%d %zu", &vf, &vb);
186  if (n == 2) {numFiles = vf, numBytes = vb; isOK = true;}
187  else {char etxt[1024];
188  snprintf(etxt, sizeof(etxt),
189  "%s setup returned bad output '",
190  Config.BkpUtilName);
191  Elog.Emsg("Backup", etxt, retStr,"'");
192  }
193  free(retStr);
194  } else {
195  Elog.Emsg("Backup",Config.BkpUtilName,"setup returned no output");
196  return false;
197  }
198 
199  Config.BkpUtilProg->RunDone(cmdSup); // This may kill the process
200  if (!isOK) return false;
201  } else {
202  Elog.Emsg("Backup",rc, "run setup via", Config.BkpUtilName);
203  return false;
204  }
205 
206 // We can only proceed if there is enough space to hold the backup. This only
207 // applies to local backups. Remote backups have unlimited space.
208 //
209  if (Config.bkpLocal)
210  while(!fsMon.Permit(this))
211  {char buff[1024];
212  snprintf(buff,sizeof(buff),"Insufficient free space; defering "
213  "archiving of %s:%s", theScope, theDSN);
214  Elog.Emsg("BkpXeq", buff);
215  stopMon.Deactivate();
216  btSem.Wait();
217  stopMon.Activate();
218  snprintf(buff,sizeof(buff),"Retrying to archive %s:%s",
219  theScope, theDSN);
220  }
221 
222 // bBefore we create the archive, check if we must run a pre-archive utility.
223 // These utilities usually pre-fetch the files that we will be archiving.
224 //
225  if (Config.PrepArcProg)
226  {XrdOucStream prpSup;
227  const char* prpArgv[] = {"prepare", theScope, manPFN};
228  int prpArgc = sizeof(prpArgv)/sizeof(char*);
229 
230  DEBUG("Running "<<Config.PrepArcName<<' '<<prpArgv[0]<<' '<<prpArgv[1]
231  <<' '<<prpArgv[2]);
232 
233  if (!(rc = Config.PrepArcProg->Run(&prpSup, prpArgv, prpArgc)))
234  {char* lp;
235  while((lp = prpSup.GetLine())) {}
236  Config.PrepArcProg->RunDone(prpSup); // This may kill the process
237  } else {
238  Elog.Emsg("Backup", rc, "run preparc", Config.PrepArcName);
239  return false;
240  }
241  }
242 
243 // Run the archive script
244 //
245  if (!Owner.Archive(theDSN, dsnDir)) return false;
246 
247 // Run post-archive script if we need to
248 //
249  if (Config.PostArcProg)
250  {XrdOucStream pstSup;
251  const char* pstArgv[] = {"dispose", theScope, manPFN};
252  int pstArgc = sizeof(pstArgv)/sizeof(char*);
253 
254  DEBUG("Running "<<Config.PrepArcName<<' '<<pstArgv[0]<<' '<<pstArgv[1]
255  <<' '<<pstArgv[2]);
256 
257  if (!(rc = Config.PostArcProg->Run(&pstSup, pstArgv, pstArgc)))
258  {char* lp;
259  while((lp = pstSup.GetLine())) {}
260  Config.PostArcProg->RunDone(pstSup); // This may kill the process
261  } else {
262  Elog.Emsg("Backup", rc, "run postarc", Config.PostArcName);
263  return false;
264  }
265  }
266 
267 // We can now safely mark this dataset as having been backed up
268 //
269  XrdOucStream cmdFin;
270  const char* finArgv[] = {"finish", Config.srcRSE, theScope, theDSN, dsnDir,
271  Config.metaBKP, Config.doneBKP};
272  int finArgc = sizeof(finArgv)/sizeof(char*);
273 
274 // If the debug setting indicates we need to save the setup, disallow delete
275 //
276  if (TRACING(TRACE_Save)) finArgv[4] = "";
277 
278 // Do some tracing
279 //
280  DEBUG("Running "<<Config.BkpUtilName<<' '<<finArgv[0]<<' '<<finArgv[1]<<
281  ' '<<finArgv[2]<<' '<<finArgv[3]<<' '<<
282  (*finArgv[4] ? finArgv[4] : "n/d")<<
283  ' '<<finArgv[5]<<' '<<finArgv[6]);
284 
285 // Run the setup script which sets the dataset backup metadata to completed
286 //
287  if (!(rc = Config.BkpUtilProg->Run(&cmdFin, finArgv, finArgc)))
288  {while((cmdFin.GetLine())) {}
289  Config.BkpUtilProg->RunDone(cmdFin); // This may kill the process
290  } else {
291  Elog.Emsg("Backup",rc, "run finish via", Config.BkpUtilName);
292  return false;
293  }
294 
295 // All done
296 //
297  return true;
298 }
#define DEBUG(x)
Definition: XrdBwmTrace.hh:54
#define TraceInfo(x, y)
#define TRACE_Save
#define TRACING(x)
Definition: XrdTrace.hh:70
const char * Arena()
bool Archive(const char *dsName, const char *dsDir)
static std::string DSN2Dir(const char *dsn)
bool Permit(XrdOssArcBackupTask *btP)
char * GetLine()
static int makePath(char *path, mode_t mode, bool reset=false)
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)
Definition: XrdSysError.cc:116
XrdCmsConfig Config
XrdSysError Elog(0, "OssArc_")

References XrdOssArcStopMon::Activate(), XrdOssArcBackup::Archive(), XrdOssArcBackup::Arena(), btSem, XrdCms::Config, XrdOssArcStopMon::Deactivate(), DEBUG, XrdOssArcCompose::DSN2Dir(), XrdOssArcGlobals::Elog, XrdSysError::Emsg(), XrdOssArcGlobals::fsMon, XrdOucStream::GetLine(), XrdOucUtils::makePath(), numBytes, numFiles, Owner, XrdOssArcFSMon::Permit(), theDSN, theScope, TRACE_Save, TraceInfo, TRACING, and XrdSysSemaphore::Wait().

+ Here is the call graph for this function:

Member Data Documentation

◆ btSem

XrdSysSemaphore XrdOssArcBackupTask::btSem

Definition at line 57 of file XrdOssArcBackup.hh.

Referenced by BkpXeq(), and XrdOssArcFSMon::Release().

◆ numBytes

size_t XrdOssArcBackupTask::numBytes

◆ numFiles

int XrdOssArcBackupTask::numFiles

Definition at line 55 of file XrdOssArcBackup.hh.

Referenced by BkpXeq().

◆ Owner

XrdOssArcBackup& XrdOssArcBackupTask::Owner

Definition at line 51 of file XrdOssArcBackup.hh.

Referenced by ~XrdOssArcBackupTask(), and BkpXeq().

◆ relSpace

bool XrdOssArcBackupTask::relSpace

Definition at line 56 of file XrdOssArcBackup.hh.

Referenced by ~XrdOssArcBackupTask(), and XrdOssArcFSMon::Permit().

◆ theDSN

char* XrdOssArcBackupTask::theDSN

Definition at line 53 of file XrdOssArcBackup.hh.

Referenced by ~XrdOssArcBackupTask(), and BkpXeq().

◆ theScope

const char* XrdOssArcBackupTask::theScope

Definition at line 52 of file XrdOssArcBackup.hh.

Referenced by BkpXeq().


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