From: rgrosso Date: Mon, 27 Aug 2012 15:40:57 +0000 (+0000) Subject: Adding the possibility to specify SEs for mirroring when putting an object on AliEn X-Git-Url: http://git.uio.no/git/?a=commitdiff_plain;h=06eeadea3b2458dea3ced52bd202c1603ce3863e;p=u%2Fmrichter%2FAliRoot.git Adding the possibility to specify SEs for mirroring when putting an object on AliEn --- diff --git a/STEER/CDB/AliCDBDump.cxx b/STEER/CDB/AliCDBDump.cxx index ae2bf61fe6a..275b6747864 100644 --- a/STEER/CDB/AliCDBDump.cxx +++ b/STEER/CDB/AliCDBDump.cxx @@ -648,7 +648,7 @@ TList* AliCDBDump::GetEntries(const AliCDBId& queryId) { } //_____________________________________________________________________________ -Bool_t AliCDBDump::PutEntry(AliCDBEntry* entry) { +Bool_t AliCDBDump::PutEntry(AliCDBEntry* entry, const char* mirrors) { // put an AliCDBEntry object into the database TDirectory::TContext context(gDirectory, fFile); @@ -663,6 +663,10 @@ Bool_t AliCDBDump::PutEntry(AliCDBEntry* entry) { return kFALSE; } + TString mirrorsString(mirrors); + if(!mirrorsString.IsNull()) + AliError("AliCDBDump storage cannot take mirrors into account."); + AliCDBId& id = entry->GetId(); if (!gDirectory->cd(id.GetPath())) { diff --git a/STEER/CDB/AliCDBDump.h b/STEER/CDB/AliCDBDump.h index aeca641f779..a339f57f5ff 100644 --- a/STEER/CDB/AliCDBDump.h +++ b/STEER/CDB/AliCDBDump.h @@ -35,7 +35,7 @@ protected: virtual AliCDBEntry* GetEntry(const AliCDBId& query); virtual AliCDBId* GetEntryId(const AliCDBId& query); virtual TList* GetEntries(const AliCDBId& query); - virtual Bool_t PutEntry(AliCDBEntry* entry); + virtual Bool_t PutEntry(AliCDBEntry* entry, const char* mirrors=""); virtual TList* GetIdListFromFile(const char* fileName); private: diff --git a/STEER/CDB/AliCDBGrid.cxx b/STEER/CDB/AliCDBGrid.cxx index 7b712820a8c..85d63b64e36 100644 --- a/STEER/CDB/AliCDBGrid.cxx +++ b/STEER/CDB/AliCDBGrid.cxx @@ -709,7 +709,7 @@ TList* AliCDBGrid::GetEntries(const AliCDBId& queryId) { } //_____________________________________________________________________________ -Bool_t AliCDBGrid::PutEntry(AliCDBEntry* entry) { +Bool_t AliCDBGrid::PutEntry(AliCDBEntry* entry, const char* mirrors) { // put an AliCDBEntry object into the database AliCDBId& id = entry->GetId(); @@ -731,35 +731,59 @@ Bool_t AliCDBGrid::PutEntry(AliCDBEntry* entry) { TDirectory* saveDir = gDirectory; TString fullFilename = Form("/alien%s", filename.Data()); + TString seMirrors(mirrors); // specify SE to filename - if (fSE != "default") fullFilename += Form("?se=%s",fSE.Data()); + // if a list of SEs was passed, set the first as SE for opening the file. The others will be used in cascade in case of + // failure in opening the file. The remaining will be used to create replicas. + TObjArray *arraySEs = seMirrors.Tokenize(','); + Int_t nSEs = arraySEs->GetEntries(); + Int_t remainingSEs = 1; + if(nSEs == 0){ + if (fSE != "default") fullFilename += Form("?se=%s",fSE.Data()); + }else{ + remainingSEs = nSEs; + } - Int_t nsleep = fInitRetrySeconds; // open file TFile *file=0; AliDebug(2, Form("fNretry = %d, fInitRetrySeconds = %d",fNretry,fInitRetrySeconds)); - for(Int_t i=0; i<=fNretry; ++i) { - AliDebug(2, Form("Putting the file in the OCDB: Retry n. %d",i)); + TString targetSE(""); + while(remainingSEs>0){ + if(nSEs!=0){ + TObjString *target = (TObjString*) arraySEs->At(nSEs-remainingSEs); + targetSE=target->String(); + if ( !(targetSE.BeginsWith("ALICE::") && targetSE.CountChar(':')==4) ) { + AliError(Form("\"%s\" is an invalid storage element identifier.",targetSE.Data())); + continue; + } + fullFilename.Remove(fullFilename.Last('?')); + fullFilename += Form("?se=%s",targetSE.Data()); + } + Int_t remainingAttempts=fNretry; + Int_t nsleep = fInitRetrySeconds; // number of seconds between attempts. We let it increase exponentially + while(remainingAttempts > 0) { + AliDebug(2, Form("Putting the file in the OCDB - Attempt n. %d",fNretry-remainingAttempts+1)); file = TFile::Open(fullFilename,"CREATE"); + remainingAttempts--; if(!file || !file->IsWritable()){ - AliError(Form("Can't open file <%s>!", filename.Data())); - if(file && !file->IsWritable()) file->Close(); delete file; file=0; - if(i==fNretry) { - AliError(Form("After %d retries, failing putting the object in the OCDB - returning...",i)); - return kFALSE; - } - else { - AliDebug(2,Form("Retry %d failed, sleeping for %d seconds",i,nsleep)); - sleep(nsleep); - } - } - else { - AliDebug(2, " Successful!"); - break; + AliError(Form("Can't open file <%s>!", filename.Data())); + if(file && !file->IsWritable()) file->Close(); delete file; file=0; + AliDebug(2,Form("Attempt %d failed, sleeping for %d seconds",fNretry-remainingAttempts+1,nsleep)); + if(remainingAttempts>0) sleep(nsleep); + }else{ + remainingAttempts=0; } nsleep*=fInitRetrySeconds; + } + remainingSEs--; + if(file) break; + } + if(!file){ + AliError(Form("All %d attempts have failed on all %d SEs. Returning...",fNretry,nSEs)); + return kFALSE; } + file->cd(); //SetTreeToFile(entry, file); @@ -787,7 +811,25 @@ Bool_t AliCDBGrid::PutEntry(AliCDBEntry* entry) { } AliInfo(Form("CDB object stored into file %s", filename.Data())); - AliInfo(Form("Storage Element: %s", fSE.Data())); + if(nSEs==0) + AliInfo(Form("Storage Element: %s", fSE.Data())); + else + AliInfo(Form("Storage Element: %s", targetSE.Data())); + + //In case of other SEs specified by the user, mirror the file to the remaining SEs + while(remainingSEs>0){ + TString mirrorCmd("mirror "); + mirrorCmd += filename; + mirrorCmd += " "; + TObjString *target = (TObjString*) arraySEs->At(nSEs-remainingSEs); + TString mirrorSE(target->String()); + mirrorCmd += mirrorSE; + AliDebug(5,Form("mirror command: \"%s\"",mirrorCmd.Data())); + AliInfo(Form("Mirroring to storage element: %s", mirrorSE.Data())); + gGrid->Command(mirrorCmd.Data()); + remainingSEs--; + } + return result; } //_____________________________________________________________________________ diff --git a/STEER/CDB/AliCDBGrid.h b/STEER/CDB/AliCDBGrid.h index 24f18da394f..155d1771547 100644 --- a/STEER/CDB/AliCDBGrid.h +++ b/STEER/CDB/AliCDBGrid.h @@ -33,7 +33,7 @@ protected: virtual AliCDBEntry* GetEntry(const AliCDBId& queryId); virtual AliCDBId* GetEntryId(const AliCDBId& queryId); virtual TList* GetEntries(const AliCDBId& queryId); - virtual Bool_t PutEntry(AliCDBEntry* entry); + virtual Bool_t PutEntry(AliCDBEntry* entry, const char* mirrors=""); virtual TList* GetIdListFromFile(const char* fileName); private: diff --git a/STEER/CDB/AliCDBLocal.cxx b/STEER/CDB/AliCDBLocal.cxx index d3f046cc9b3..d2ea6bbb7aa 100644 --- a/STEER/CDB/AliCDBLocal.cxx +++ b/STEER/CDB/AliCDBLocal.cxx @@ -720,7 +720,7 @@ TList* AliCDBLocal::GetEntries(const AliCDBId& queryId) { } //_____________________________________________________________________________ -Bool_t AliCDBLocal::PutEntry(AliCDBEntry* entry) { +Bool_t AliCDBLocal::PutEntry(AliCDBEntry* entry, const char* mirrors) { // put an AliCDBEntry object into the database AliCDBId& id = entry->GetId(); @@ -737,6 +737,10 @@ Bool_t AliCDBLocal::PutEntry(AliCDBEntry* entry) { return kFALSE; } + TString mirrorsString(mirrors); + if(!mirrorsString.IsNull()) + AliError("AliCDBLocal storage cannot take mirrors into account."); + // open file TFile file(filename, "CREATE"); if (!file.IsOpen()) { diff --git a/STEER/CDB/AliCDBLocal.h b/STEER/CDB/AliCDBLocal.h index 193eb3fdf20..fc206efaf75 100644 --- a/STEER/CDB/AliCDBLocal.h +++ b/STEER/CDB/AliCDBLocal.h @@ -32,7 +32,7 @@ protected: virtual AliCDBEntry* GetEntry(const AliCDBId& queryId); virtual AliCDBId* GetEntryId(const AliCDBId& queryId); virtual TList* GetEntries(const AliCDBId& queryId); - virtual Bool_t PutEntry(AliCDBEntry* entry); + virtual Bool_t PutEntry(AliCDBEntry* entry, const char* mirrors=""); virtual TList* GetIdListFromFile(const char* fileName); private: diff --git a/STEER/CDB/AliCDBManager.cxx b/STEER/CDB/AliCDBManager.cxx index e3065d1c56b..d9524b76936 100644 --- a/STEER/CDB/AliCDBManager.cxx +++ b/STEER/CDB/AliCDBManager.cxx @@ -1217,13 +1217,13 @@ Bool_t AliCDBManager::Put(TObject* object, const AliCDBId& id, AliCDBMetaData* m } AliCDBEntry anEntry(object, id, metaData); - return Put(&anEntry, type); + return Put(&anEntry, "", type); } //_____________________________________________________________________________ -Bool_t AliCDBManager::Put(AliCDBEntry* entry, DataType type){ +Bool_t AliCDBManager::Put(AliCDBEntry* entry, const char* mirrors, DataType type){ // store an AliCDBEntry object into the database if(type == kPrivate && !fDefaultStorage) { @@ -1276,7 +1276,7 @@ Bool_t AliCDBManager::Put(AliCDBEntry* entry, DataType type){ AliDebug(2,Form("Storing object into storage: %s", aStorage->GetURI().Data())); - Bool_t result = aStorage->Put(entry, type); + Bool_t result = aStorage->Put(entry, mirrors, type); if(fRun >= 0) QueryCDB(); diff --git a/STEER/CDB/AliCDBManager.h b/STEER/CDB/AliCDBManager.h index 9ac4d58f741..c1ae71ed438 100644 --- a/STEER/CDB/AliCDBManager.h +++ b/STEER/CDB/AliCDBManager.h @@ -89,7 +89,7 @@ class AliCDBManager: public TObject { Bool_t Put(TObject* object, const AliCDBId& id, AliCDBMetaData* metaData, const DataType type=kPrivate); - Bool_t Put(AliCDBEntry* entry, DataType type=kPrivate); + Bool_t Put(AliCDBEntry* entry, const char* mirrors="", DataType type=kPrivate); void SetCacheFlag(Bool_t cacheFlag) {fCache=cacheFlag;} Bool_t GetCacheFlag() const {return fCache;} diff --git a/STEER/CDB/AliCDBStorage.cxx b/STEER/CDB/AliCDBStorage.cxx index f36a9c76381..301f61f6f26 100644 --- a/STEER/CDB/AliCDBStorage.cxx +++ b/STEER/CDB/AliCDBStorage.cxx @@ -385,11 +385,11 @@ Bool_t AliCDBStorage::Put(TObject* object, AliCDBId& id, AliCDBMetaData* metaDat AliCDBEntry anEntry(object, id, metaData); - return Put(&anEntry, type); + return Put(&anEntry, "", type); } //_____________________________________________________________________________ -Bool_t AliCDBStorage::Put(AliCDBEntry* entry, AliCDBManager::DataType type) { +Bool_t AliCDBStorage::Put(AliCDBEntry* entry, const char* mirrors, AliCDBManager::DataType type) { // store an AliCDBEntry object into the database if (!entry){ @@ -423,7 +423,7 @@ Bool_t AliCDBStorage::Put(AliCDBEntry* entry, AliCDBManager::DataType type) { return 0; } - return PutEntry(entry); + return PutEntry(entry,mirrors); } //_____________________________________________________________________________ diff --git a/STEER/CDB/AliCDBStorage.h b/STEER/CDB/AliCDBStorage.h index 30f844b987d..72bab165746 100644 --- a/STEER/CDB/AliCDBStorage.h +++ b/STEER/CDB/AliCDBStorage.h @@ -86,7 +86,7 @@ public: Bool_t Put(TObject* object, AliCDBId& id, AliCDBMetaData* metaData, AliCDBManager::DataType type=AliCDBManager::kPrivate); - Bool_t Put(AliCDBEntry* entry, AliCDBManager::DataType type=AliCDBManager::kPrivate); + Bool_t Put(AliCDBEntry* entry, const char* mirrors="", AliCDBManager::DataType type=AliCDBManager::kPrivate); virtual Bool_t IsReadOnly() const = 0; virtual Bool_t HasSubVersion() const = 0; @@ -109,7 +109,7 @@ protected: virtual AliCDBEntry* GetEntry(const AliCDBId& query) = 0; virtual AliCDBId* GetEntryId(const AliCDBId& query) = 0; virtual TList* GetEntries(const AliCDBId& query) = 0; - virtual Bool_t PutEntry(AliCDBEntry* entry) = 0; + virtual Bool_t PutEntry(AliCDBEntry* entry, const char* mirrors="") = 0; virtual TList *GetIdListFromFile(const char* fileName)=0; virtual void QueryValidFiles() = 0; void LoadTreeFromFile(AliCDBEntry* entry) const;