Skip to content

Commit

Permalink
[XrdCl] FileSystem get last URL.
Browse files Browse the repository at this point in the history
Add new property 'LastURL', closes #1092
  • Loading branch information
simonmichal committed Jan 21, 2020
1 parent 7d51d78 commit bf5df01
Showing 1 changed file with 75 additions and 7 deletions.
82 changes: 75 additions & 7 deletions src/XrdCl/XrdClFileSystem.cc
Expand Up @@ -889,6 +889,32 @@ namespace XrdCl
ResponseHandler *pUserHandler;
};

//----------------------------------------------------------------------------
//! Wrapper class used to assign last URL
//----------------------------------------------------------------------------
class AssignLastURLHandler: public ResponseHandler
{
public:
//------------------------------------------------------------------------
// Constructor and destructor
//------------------------------------------------------------------------
AssignLastURLHandler( FileSystemImpl *fs, ResponseHandler *userHandler ):
pFS(fs), pUserHandler(userHandler) {}

virtual ~AssignLastURLHandler() {}

//------------------------------------------------------------------------
// Response callback
//------------------------------------------------------------------------
virtual void HandleResponseWithHosts( XRootDStatus *status,
AnyObject *response,
HostList *hostList );

private:
FileSystemImpl *pFS;
ResponseHandler *pUserHandler;
};

//----------------------------------------------------------------------------
//! Implementation holding the data members
//----------------------------------------------------------------------------
Expand Down Expand Up @@ -919,6 +945,8 @@ namespace XrdCl
log->Dump( FileSystemMsg, "[0x%x@%s] Sending %s", this,
pUrl->GetHostId().c_str(), msg->GetDescription().c_str() );

handler = new AssignLastURLHandler( this, handler );

if( !pLoadBalancerLookupDone && pFollowRedirects )
handler = new AssignLBHandler( this, handler ); // TODO

Expand All @@ -927,7 +955,6 @@ namespace XrdCl
return MessageUtils::SendMessage( *pUrl, msg, handler, params, 0 );
}


//----------------------------------------------------------------------------
// Assign a load balancer if it has not already been assigned
//----------------------------------------------------------------------------
Expand All @@ -947,18 +974,33 @@ namespace XrdCl
pLoadBalancerLookupDone = true;
}

XrdSysMutex pMutex;
bool pLoadBalancerLookupDone;
bool pFollowRedirects;
URL *pUrl;
//----------------------------------------------------------------------------
// Assign last URL
//----------------------------------------------------------------------------
void AssignLastURL( const URL &url )
{
Log *log = DefaultEnv::GetLog();
XrdSysMutexHelper scopedLock( pMutex );

log->Dump( FileSystemMsg, "[0x%x@%s] Assigning %s as last URL", this,
pUrl->GetHostId().c_str(), url.GetHostId().c_str() );

pLastUrl.reset( new URL( url ) );
}

XrdSysMutex pMutex;
bool pLoadBalancerLookupDone;
bool pFollowRedirects;
URL *pUrl;
std::unique_ptr<URL> pLastUrl;
};

//------------------------------------------------------------------------
// Response callback
//------------------------------------------------------------------------
void AssignLBHandler::HandleResponseWithHosts( XRootDStatus *status,
AnyObject *response,
HostList *hostList )
AnyObject *response,
HostList *hostList )
{
if( status->IsOK() )
{
Expand All @@ -977,6 +1019,22 @@ namespace XrdCl
delete this;
}

//------------------------------------------------------------------------
// Response callback
//------------------------------------------------------------------------
void AssignLastURLHandler::HandleResponseWithHosts( XRootDStatus *status,
AnyObject *response,
HostList *hostList )
{
if( status->IsOK() && hostList )
pFS->AssignLastURL( hostList->front().url );

bool finalrsp = !( status->IsOK() && status->code == suContinue );
pUserHandler->HandleResponseWithHosts( status, response, hostList );
if( finalrsp )
delete this;
}

//----------------------------------------------------------------------------
// Constructor
//----------------------------------------------------------------------------
Expand Down Expand Up @@ -2023,6 +2081,16 @@ namespace XrdCl
else value = "false";
return true;
}
else if( name == "LastURL" )
{
if( pImpl->pLastUrl )
{
value = pImpl->pLastUrl->GetURL();
return true;
}
else return false;
}

return false;
}

Expand Down

0 comments on commit bf5df01

Please sign in to comment.