Skip to content

Commit

Permalink
[Client] Avoid ZipArchive issuing VectorWrite which is too large duri…
Browse files Browse the repository at this point in the history
…ng CloseArchive
  • Loading branch information
smithdh authored and amadio committed May 5, 2023
1 parent be37e13 commit ba9a395
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 2 deletions.
50 changes: 50 additions & 0 deletions src/XrdCl/XrdClUtils.cc
Expand Up @@ -865,4 +865,54 @@ namespace XrdCl
if( dst_supported.count( *itr ) ) return *itr;
return std::string();
}

//----------------------------------------------------------------------------
//! Split chunks in a ChunkList into one or more ChunkLists
//----------------------------------------------------------------------------
void Utils::SplitChunks( std::vector<ChunkList> &listsvec,
const ChunkList &chunks,
const uint32_t maxcs,
const size_t maxc )
{
listsvec.clear();
if( !chunks.size() ) return;

listsvec.emplace_back();
ChunkList *c = &listsvec.back();
const size_t cs = chunks.size();
size_t idx = 0;
size_t nc = 0;
ChunkInfo tmpc;

c->reserve( cs );

while( idx < cs )
{
if( maxc && nc >= maxc )
{
listsvec.emplace_back();
c = &listsvec.back();
c->reserve( cs - idx );
nc = 0;
}

if( tmpc.length == 0 )
tmpc = chunks[idx];

if( maxcs && tmpc.length > maxcs )
{
c->emplace_back( tmpc.offset, maxcs, tmpc.buffer );
tmpc.offset += maxcs;
tmpc.length -= maxcs;
tmpc.buffer = static_cast<char*>( tmpc.buffer ) + maxcs;
}
else
{
c->emplace_back( tmpc.offset, tmpc.length, tmpc.buffer );
tmpc.length = 0;
++idx;
}
++nc;
}
}
}
12 changes: 12 additions & 0 deletions src/XrdCl/XrdClUtils.hh
Expand Up @@ -272,6 +272,18 @@ namespace XrdCl
if( !st.IsOK() ) return false;
return protver >= kXR_PROTPGRWVERSION;
}

//------------------------------------------------------------------------
//! Split chunks in a ChunkList into one or more ChunkLists
//! @param listsvec : output vector of ChunkLists
//! @param chunks : input ChunkLisits
//! @param maxcs : maximum size of a ChunkInfo in output
//! @param maxc : maximum number of ChunkInfo in each ChunkList
//------------------------------------------------------------------------
static void SplitChunks( std::vector<ChunkList> &listsvec,
const ChunkList &chunks,
const uint32_t maxcs,
const size_t maxc );
};

//----------------------------------------------------------------------------
Expand Down
13 changes: 11 additions & 2 deletions src/XrdCl/XrdClZipArchive.cc
Expand Up @@ -28,6 +28,7 @@
#include "XrdCl/XrdClLog.hh"
#include "XrdCl/XrdClDefaultEnv.hh"
#include "XrdCl/XrdClConstants.hh"
#include "XrdCl/XrdClUtils.hh"
#include "XrdZip/XrdZipZIP64EOCDL.hh"

#include <sys/stat.h>
Expand Down Expand Up @@ -626,10 +627,18 @@ namespace XrdCl
}

auto wrtbuff = std::make_shared<buffer_t>( GetCD() );
chunks.emplace_back( cdoff, wrtbuff->size(), wrtbuff->data() );
Pipeline p = XrdCl::Write( archive, cdoff,
wrtbuff->size(),
wrtbuff->data() );
wrtbufs.emplace_back( std::move( wrtbuff ) );

Pipeline p = XrdCl::VectorWrite( archive, chunks );
std::vector<ChunkList> listsvec;
XrdCl::Utils::SplitChunks( listsvec, chunks, 262144, 1024 );

for(auto itr = listsvec.rbegin(); itr != listsvec.rend(); ++itr)
{
p = XrdCl::VectorWrite( archive, *itr ) | p;
}
if( ckpinit )
p |= XrdCl::Checkpoint( archive, ChkPtCode::COMMIT );
p |= Close( archive ) >>
Expand Down

0 comments on commit ba9a395

Please sign in to comment.