8 #ifndef SRC_XRDCL_XRDCLECHANDLER_HH_
9 #define SRC_XRDCL_XRDCLECHANDLER_HH_
56 std::vector<FreeSpace> ServerList;
57 std::vector<std::string> ExportPaths;
58 time_t lastUpdateT = 0;
61 bool initExportPaths =
false;
63 void TryInitExportPaths();
64 uint64_t GetFreeSpace(
const std::string addr);
66 void UpdateSpaceInfo();
93 std::vector<uint32_t> cksums;
97 cksums.reserve( nbpages );
99 size_t size = chunk->
length;
100 char *buffer =
reinterpret_cast<char*
>( chunk->
buffer );
102 for(
size_t pg = 0; pg < nbpages; ++pg )
105 if( pgsize > size ) pgsize = size;
107 cksums.push_back( crcval );
115 response->
Set( pages );
127 std::unique_ptr<CheckSumHelper> cksHelper ) : redir( redir ),
131 cksHelper( std::move( cksHelper ) )
151 if( objcfg->plgr.empty() )
154 if( !st.
IsOK() )
return st;
157 writer->Open( handler, timeout );
166 if( objcfg->plgr.empty() )
169 if( !st.
IsOK() )
return st;
172 reader->Open( handler, timeout );
185 (void)url; (void)mode;
186 return Open( flags, handler, timeout );
201 if( st->
IsOK() &&
bool( cksHelper ) )
203 std::string commit = redir.GetPath()
204 +
"?xrdec.objid=" + objcfg->obj
205 +
"&xrdec.close=true&xrdec.size=" + std::to_string( curroff );
208 std::string ckstype = cksHelper->GetType();
210 auto st = cksHelper->GetCheckSum( cksval, ckstype );
213 handler->HandleResponse( new XRootDStatus( st ), nullptr );
216 commit +=
"&xrdec.cksum=" + cksval;
233 handler->HandleResponse( st, rsp );
235 return XRootDStatus();
249 if( !objcfg->nomtfile )
250 return fs.Stat( redir.GetPath(), handler, timeout );
252 if( !force && statcache )
254 auto rsp = StatRsp( statcache->GetSize() );
255 Schedule( handler, rsp );
262 statcache->SetSize( writer->GetSize() );
263 auto rsp = StatRsp( statcache->GetSize() );
264 Schedule( handler, rsp );
271 statcache->SetSize( reader->GetSize() );
272 auto rsp = StatRsp( statcache->GetSize() );
273 Schedule( handler, rsp );
291 reader->Read( offset, size, buffer, handler, timeout );
318 cksHelper->Update( buffer, size );
322 writer->Write( size, buffer, handler );
333 std::vector<uint32_t> &cksums,
335 uint16_t timeout = 0 )
337 if(! cksums.empty() )
339 const char *data =
static_cast<const char*
>( buffer );
340 std::vector<uint32_t> local_cksums;
342 if (data)
delete data;
343 if (local_cksums != cksums)
346 return Write(offset, size, buffer, handler, timeout);
354 return writer || reader;
363 std::unique_ptr<LocationInfo> ptr( infoAll );
364 if( !st.
IsOK() )
return st;
367 std::unique_ptr<LocationInfo> ptr1( info );
372 if( info->
GetSize() < objcfg->nbchunks )
374 unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
375 shuffle (info->
Begin(), info->
End(), std::default_random_engine(seed));
376 for(
size_t i = 0; i < objcfg->nbchunks; ++i )
378 auto &location = info->
At( i );
379 objcfg->plgr.emplace_back(
"root://" + location.GetAddress() +
'/' );
381 return XRootDStatus();
384 inline XRootDStatus LoadPlacement(
const std::string &path )
386 LocationInfo *info =
nullptr;
388 std::unique_ptr<LocationInfo> ptr( info );
389 if( !st.IsOK() )
return st;
391 if( info->GetSize() < objcfg->nbdata )
394 uint64_t verNumMax = 0;
395 std::vector<uint64_t> verNums;
396 std::vector<std::string> xattrkeys;
397 std::vector<XrdCl::XAttr> xattrvals;
398 xattrkeys.push_back(
"xrdec.strpver");
399 for(
size_t i = 0; i < info->GetSize(); ++i )
401 FileSystem *fs_i =
new FileSystem(info->At( i ).GetAddress());
403 st = fs_i->GetXAttr(path, xattrkeys, xattrvals, 0);
404 if (st.IsOK() && ! xattrvals[0].value.empty())
406 std::stringstream sstream(xattrvals[0].value);
409 verNums.push_back(verNum);
410 if (verNum > verNumMax)
414 verNums.push_back(0);
419 for(
size_t i = 0; i < info->GetSize(); ++i )
421 if ( verNums.at(i) == 0 || verNums.at(i) != verNumMax )
425 auto &location = info->At( i );
426 objcfg->plgr.emplace_back(
"root://" + location.GetAddress() +
'/' );
428 if (n < objcfg->nbdata )
430 return XRootDStatus();
433 inline static AnyObject* StatRsp( uint64_t size )
435 StatInfo *info =
new StatInfo();
436 info->SetSize( size );
437 AnyObject *rsp =
new AnyObject();
442 inline static void Schedule( ResponseHandler *handler, AnyObject *rsp )
444 ResponseJob *job =
new ResponseJob( handler,
new XRootDStatus(), rsp,
nullptr );
450 std::unique_ptr<XrdEc::ObjCfg> objcfg;
451 std::unique_ptr<XrdEc::StrmWriter> writer;
452 std::unique_ptr<XrdEc::Reader> reader;
454 std::unique_ptr<CheckSumHelper> cksHelper;
455 std::unique_ptr<StatInfo> statcache;
469 std::vector<std::string> && plgr ) :
470 nbdta( nbdta ), nbprt( nbprt ), chsz( chsz ), plgr( std::move( plgr ) )
489 objcfg->
plgr = std::move( plgr );
490 return new EcHandler( url, objcfg,
nullptr );
505 std::vector<std::string> plgr;
508 EcHandler*
GetEcHandler(
const URL &headnode,
const URL &redirurl );
void Set(Type object, bool own=true)
void Get(Type &object)
Retrieve the object being held.
Binary blob representation.
void FromString(const std::string str)
Fill the buffer from a string.
static PostMaster * GetPostMaster()
Get default post master.
XRootDStatus Close(ResponseHandler *handler, uint16_t timeout)
XRootDStatus PgWrite(uint64_t offset, uint32_t size, const void *buffer, std::vector< uint32_t > &cksums, ResponseHandler *handler, uint16_t timeout=0)
XRootDStatus Open(const std::string &url, OpenFlags::Flags flags, Access::Mode mode, ResponseHandler *handler, uint16_t timeout)
XRootDStatus Write(uint64_t offset, uint32_t size, const void *buffer, ResponseHandler *handler, uint16_t timeout)
XRootDStatus Stat(bool force, ResponseHandler *handler, uint16_t timeout)
XRootDStatus Read(uint64_t offset, uint32_t size, void *buffer, ResponseHandler *handler, uint16_t timeout)
XRootDStatus PgRead(uint64_t offset, uint32_t size, void *buffer, ResponseHandler *handler, uint16_t timeout)
XRootDStatus Open(uint16_t flags, ResponseHandler *handler, uint16_t timeout)
EcHandler(const URL &redir, XrdEc::ObjCfg *objcfg, std::unique_ptr< CheckSumHelper > cksHelper)
EcPgReadResponseHandler(ResponseHandler *a)
void HandleResponse(XRootDStatus *status, AnyObject *rdresp)
EcPlugInFactory(uint8_t nbdta, uint8_t nbprt, uint64_t chsz, std::vector< std::string > &&plgr)
Constructor.
virtual FilePlugIn * CreateFile(const std::string &u)
Create a file plug-in for the given URL.
virtual FileSystemPlugIn * CreateFileSystem(const std::string &url)
Create a file system plug-in for the given URL.
virtual ~EcPlugInFactory()
Destructor.
An interface for file plug-ins.
An interface for file plug-ins.
XRootDStatus Query(QueryCode::Code queryCode, const Buffer &arg, ResponseHandler *handler, uint16_t timeout=0) XRD_WARN_UNUSED_RESULT
bool operator<(const FreeSpace &a) const
void QueueJob(Job *job, void *arg=0)
Add a job to be run.
uint32_t GetSize() const
Get number of locations.
Iterator Begin()
Get the location begin iterator.
Location & At(uint32_t index)
Get the location at index.
Iterator End()
Get the location end iterator.
JobManager * GetJobManager()
Get the job manager object user by the post master.
Handle an async response.
static ResponseHandler * Wrap(std::function< void(XRootDStatus &, AnyObject &)> func)
virtual void HandleResponse(XRootDStatus *status, AnyObject *response)
void SelectLocations(XrdCl::LocationInfo &oldList, XrdCl::LocationInfo &newList, uint32_t n)
const std::string & GetPath() const
Get the path.
static Config & Instance()
Singleton access.
static uint32_t Calc32C(const void *data, size_t count, uint32_t prevcs=0)
static void csCalc(const char *data, off_t offs, size_t count, uint32_t *csval)
WriteImpl< false > Write(Ctx< File > file, Arg< uint64_t > offset, Arg< uint32_t > size, Arg< const void * > buffer, uint16_t timeout=0)
Factory for creating WriteImpl objects.
const uint16_t stError
An error occurred that could potentially be retried.
ReadImpl< false > Read(Ctx< File > file, Arg< uint64_t > offset, Arg< uint32_t > size, Arg< void * > buffer, uint16_t timeout=0)
Factory for creating ReadImpl objects.
const uint16_t errInternal
Internal error.
const uint16_t errInvalidOp
EcHandler * GetEcHandler(const URL &headnode, const URL &redirurl)
const uint16_t errInvalidArgs
const uint16_t errNotSupported
static const int PageSize
Describe a data chunk for vector read.
void * buffer
length of the chunk
uint32_t length
offset in the file
Flags
Open flags, may be or'd when appropriate.
@ Read
Open only for reading.
@ Write
Open only for writing.
@ Update
Open for reading and writing.
@ OpaqueFile
Implementation dependent.
bool IsOK() const
We're fine.
std::vector< std::string > plgr