16 if (getenv(
"XrdCl_EC_X_RATIO"))
18 xRatio = atoi(getenv(
"XrdCl_EC_X_RATIO"));
35 if (oldList.
GetSize() > n && ! BlindSelect())
37 for (uint32_t j=0; j<ServerList.size(); j++)
39 for (uint32_t i=0; i<oldList.
GetSize(); i++)
41 if (ServerList[j].address == oldList.
At(i).
GetAddress() &&
44 newList.
Add(oldList.
At(i));
56 for (uint32_t i=0; i<oldList.
GetSize(); i++)
58 if (Exists(oldList.
At(i)) &&
61 newList.
Add(oldList.
At(i));
70 for (uint32_t j=0; j<ServerList.size(); j++)
76 void ServerSpaceInfo::TryInitExportPaths()
78 if (initExportPaths)
return;
80 if (! initExportPaths && getenv(
"XRDEXPORTS"))
82 std::istringstream p(getenv(
"XRDEXPORTS"));
86 ExportPaths.push_back(s);
88 initExportPaths =
true;
93 uint64_t ServerSpaceInfo::GetFreeSpace(
const std::string addr)
98 for (uint32_t i=0; i<ExportPaths.size(); i++)
104 std::string resp = queryResp->
ToString();
105 int b = resp.find(
"oss.free=", 0);
106 int e = resp.find(
"&", b);
108 std::stringstream sstream0( resp.substr(b+9, e-(b+9)) );
110 if (queryResp)
delete queryResp;
113 if (queryResp)
delete queryResp;
118 bool ServerSpaceInfo::BlindSelect() {
119 auto ms_since_epoch = std::chrono::system_clock::now().time_since_epoch() /
120 std::chrono::nanoseconds(1);
121 return (ms_since_epoch % 10 > xRatio ?
true :
false);
124 void ServerSpaceInfo::UpdateSpaceInfo()
126 if (! initExportPaths)
return;
127 time_t t = time(NULL);
128 if (t < lastUpdateT + 300)
return;
130 if (t > lastUpdateT + 300)
132 for (uint32_t j=0; j<ServerList.size(); j++)
133 ServerList[j].freeSpace = GetFreeSpace(ServerList[j].address);
134 std::sort(ServerList.begin(), ServerList.end());
142 for (uint32_t j=0; j<ServerList.size(); j++)
143 if (loc.
GetAddress() == ServerList[j].address)
151 for (uint32_t i=0; i<locInfo.
GetSize(); i++)
153 if (Exists(locInfo.
At(i)))
continue;
158 s.freeSpace = GetFreeSpace( s.address );
159 ServerList.push_back(s);
160 std::sort(ServerList.begin(), ServerList.end());
170 URL::ParamsMap::const_iterator itr = params.find(
"xrdec.nbdta" );
171 if( itr == params.end() )
return nullptr;
172 uint8_t nbdta = std::stoul( itr->second );
174 itr = params.find(
"xrdec.nbprt" );
175 if( itr == params.end() )
return nullptr;
176 uint8_t nbprt = std::stoul( itr->second );
178 itr = params.find(
"xrdec.blksz" );
179 if( itr == params.end() )
return nullptr;
180 uint64_t blksz = std::stoul( itr->second );
182 itr = params.find(
"xrdec.plgr" );
183 if( itr == params.end() )
return nullptr;
184 std::vector<std::string> plgr;
186 if( plgr.size() < nbdta + nbprt )
return nullptr;
188 itr = params.find(
"xrdec.objid" );
189 if( itr == params.end() )
return nullptr;
190 std::string objid = itr->second;
192 itr = params.find(
"xrdec.format" );
193 if( itr == params.end() )
return nullptr;
194 size_t format = std::stoul( itr->second );
195 if( format != 1 )
return nullptr;
197 std::vector<std::string> dtacgi;
198 itr = params.find(
"xrdec.dtacgi" );
199 if( itr != params.end() )
202 if( plgr.size() != dtacgi.size() )
return nullptr;
205 std::vector<std::string> mdtacgi;
206 itr = params.find(
"xrdec.mdtacgi" );
207 if( itr != params.end() )
210 if( plgr.size() != mdtacgi.size() )
return nullptr;
213 itr = params.find(
"xrdec.cosc" );
214 if( itr == params.end() )
return nullptr;
215 std::string cosc_str = itr->second;
216 if( cosc_str !=
"true" && cosc_str !=
"false" )
return nullptr;
217 bool cosc = cosc_str ==
"true";
220 itr = params.find(
"xrdec.cksum" );
221 if( cosc && itr == params.end() )
return nullptr;
223 ckstype = itr->second;
225 std::string chdigest;
226 itr = params.find(
"xrdec.chdigest" );
227 if( itr == params.end() )
230 chdigest = itr->second;
231 bool usecrc32c = ( chdigest ==
"crc32c" );
233 bool nomtfile =
false;
234 itr = params.find(
"xrdec.nomtfile" );
235 if( itr != params.end() )
236 nomtfile = ( itr->second ==
"true" );
239 objcfg->
plgr = std::move( plgr );
240 objcfg->
dtacgi = std::move( dtacgi );
241 objcfg->
mdtacgi = std::move( mdtacgi );
244 std::unique_ptr<CheckSumHelper> cksHelper( cosc ?
new CheckSumHelper(
"", ckstype ) :
nullptr );
247 auto st = cksHelper->Initialize();
248 if( !st.
IsOK() )
return nullptr;
251 return new EcHandler( headnode, objcfg, std::move( cksHelper ) );
void getline(uchar *buff, int blen)
Binary blob representation.
void FromString(const std::string str)
Fill the buffer from a string.
std::string ToString() const
Convert the buffer to a string.
Check sum helper for stdio.
Send file/filesystem queries to an XRootD cluster.
LocationType GetType() const
Get location type.
const std::string & GetAddress() const
Get address.
uint32_t GetSize() const
Get number of locations.
Location & At(uint32_t index)
Get the location at index.
void Add(const Location &location)
Add a location.
@ ServerOnline
server node where the file is online
void SelectLocations(XrdCl::LocationInfo &oldList, XrdCl::LocationInfo &newList, uint32_t n)
std::map< std::string, std::string > ParamsMap
const ParamsMap & GetParams() const
Get the URL params.
static void splitString(Container &result, const std::string &input, const std::string &delimiter)
Split a string.
EcHandler * GetEcHandler(const URL &headnode, const URL &redirurl)
@ Space
Query logical space stats.
bool IsOK() const
We're fine.
std::vector< std::string > mdtacgi
std::vector< std::string > plgr
std::vector< std::string > dtacgi