Skip to content

Commit

Permalink
[XrdEc] Ensure parallel execution of Reader::Read is thread-safe.
Browse files Browse the repository at this point in the history
  • Loading branch information
simonmichal committed Dec 17, 2021
1 parent 1201f0c commit ca390b1
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/XrdCl/XrdClParallelOperation.hh
Expand Up @@ -346,6 +346,7 @@ namespace XrdCl

void lift()
{
std::unique_lock<std::mutex> lck( mtx );
on = false;
cv.notify_all();
}
Expand Down
4 changes: 3 additions & 1 deletion src/XrdEc/XrdEcReader.cc
Expand Up @@ -506,12 +506,14 @@ namespace XrdEc
//-------------------------------------------------------------------
// Make sure we operate on a valid block
//-------------------------------------------------------------------
std::unique_lock<std::mutex> lck( blkmtx );
if( !block || block->blkid != blkid )
block = std::make_shared<block_t>( blkid, *this, objcfg );
//-------------------------------------------------------------------
// Prepare the callback for reading from single stripe
//-------------------------------------------------------------------
auto blk = block;
lck.unlock();
auto callback = [blk, rdctx, rdsize, rdmtx]( const XrdCl::XRootDStatus &st, uint32_t nbrd )
{
std::unique_lock<std::mutex> lck( *rdmtx );
Expand Down Expand Up @@ -549,7 +551,7 @@ namespace XrdEc
//-------------------------------------------------------------------
// Read data from a stripe
//-------------------------------------------------------------------
block_t::read( block, strpid, rdoff, rdsize, usrbuff, callback, timeout );
block_t::read( blk, strpid, rdoff, rdsize, usrbuff, callback, timeout );
//-------------------------------------------------------------------
// Update absolute offset, read length, and user buffer
//-------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions src/XrdEc/XrdEcReader.hh
Expand Up @@ -166,6 +166,7 @@ namespace XrdEc
urlmap_t urlmap; //> map blknb/strpnb (data chunk) to URL
missing_t missing; //> set of missing stripes
std::shared_ptr<block_t> block; //> cache for the block we are reading from
std::mutex blkmtx; //> mutex guarding the block from parallel access
size_t lstblk; //> last block number
uint64_t filesize; //> file size (obtained from xattr)
};
Expand Down

0 comments on commit ca390b1

Please sign in to comment.