Skip to content

Commit

Permalink
[XrdCl] Fix: xcp hangs if there are no valid sources.
Browse files Browse the repository at this point in the history
  • Loading branch information
simonmichal committed May 9, 2017
1 parent 27d6b65 commit 8fea5c8
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 9 deletions.
20 changes: 12 additions & 8 deletions src/XrdCl/XrdClXCpCtx.cc
Expand Up @@ -148,15 +148,8 @@ XRootDStatus XCpCtx::GetChunk( XrdCl::ChunkInfo &ci )
return XRootDStatus( stOK, suDone );
}

// check if there are any active sources
size_t nbRunning = 0;
std::list<XCpSrc*>::iterator itr;
for( itr = pSources.begin() ; itr != pSources.end() ; ++ itr)
if( (*itr)->IsRunning() )
++nbRunning;

// if we don't have active sources it means we failed
if( nbRunning == 0 )
if( GetRunning() == 0 )
{
XrdSysCondVarHelper lck( pDoneCV );
pDone = true;
Expand Down Expand Up @@ -191,5 +184,16 @@ bool XCpCtx::AllDone()
return pDone;
}

size_t XCpCtx::GetRunning()
{
// count active sources
size_t nbRunning = 0;
std::list<XCpSrc*>::iterator itr;
for( itr = pSources.begin() ; itr != pSources.end() ; ++ itr)
if( (*itr)->IsRunning() )
++nbRunning;
return nbRunning;
}


} /* namespace XrdCl */
20 changes: 19 additions & 1 deletion src/XrdCl/XrdClXCpCtx.hh
Expand Up @@ -126,7 +126,7 @@ class XCpCtx
int64_t GetSize()
{
XrdSysCondVarHelper lck( pFileSizeCV );
while( pFileSize < 0 ) pFileSizeCV.Wait();
while( pFileSize < 0 && GetRunning() > 0 ) pFileSizeCV.Wait();
return pFileSize;
}

Expand Down Expand Up @@ -186,8 +186,26 @@ class XCpCtx
*/
bool AllDone();

/**
* Notify those who are waiting for initialization.
* In particular the GetSize() caller will be waiting
* on the result of initialization.
*/
void NotifyInitExpectant()
{
pFileSizeCV.Broadcast();
}


private:

/**
* Returns the number of active sources
*
* @return : number of active sources
*/
size_t GetRunning();

/**
* Destructor (private).
*
Expand Down
8 changes: 8 additions & 0 deletions src/XrdCl/XrdClXCpSrc.cc
Expand Up @@ -131,6 +131,14 @@ void XCpSrc::StartDownloading()
if( !st.IsOK() )
{
pRunning = false;
// notify those who wait for the file
// size, they wont get it from this
// source
pCtx->NotifyInitExpectant();
// put a null chunk so we are sure
// the main thread doesn't get stuck
// at the sync queue
pCtx->PutChunk( 0 );
return;
}

Expand Down

0 comments on commit 8fea5c8

Please sign in to comment.