Skip to content

Commit

Permalink
Merge pull request #17885 from richardkchapman/callLessSIze
Browse files Browse the repository at this point in the history
HPCC-30475 Roxie disk read calls size() too often

Reviewed-by: Gavin Halliday <[email protected]>
Merged-by: Gavin Halliday <[email protected]>
  • Loading branch information
ghalliday authored Oct 12, 2023
2 parents 9f4aa1e + 8d9f77c commit bae0f58
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
22 changes: 19 additions & 3 deletions roxie/ccd/ccdfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2353,6 +2353,7 @@ class CFileIOArray : implements IFileIOArray, public CInterface
UnsignedArray subfiles;
StringArray filenames;
Int64Array bases;
mutable Int64Array sizes; // Lazy-evaluated and cached
int actualCrc = 0;
unsigned valid = 0;
bool multipleFormatsSeen = false;
Expand Down Expand Up @@ -2418,6 +2419,7 @@ class CFileIOArray : implements IFileIOArray, public CInterface
valid++;
files.append(f);
bases.append(base);
sizes.append(-1); // Calculated if/when needed
if (_actualCrc)
{
if (actualCrc && actualCrc != _actualCrc)
Expand Down Expand Up @@ -2468,14 +2470,28 @@ class CFileIOArray : implements IFileIOArray, public CInterface
totalSize = 0;
ForEachItemIn(idx, files)
{
IFileIO *file = files.item(idx);
if (file)
totalSize += file->size();
totalSize += partSize(idx);
}
}
return totalSize;
}

virtual unsigned __int64 partSize(unsigned idx) const override
{
CriticalBlock b(crit);
__int64 fsize = sizes.item(idx);
if (fsize == -1)
{
IFileIO *file = files.item(idx);
if (file)
fsize = file->size();
else
fsize = 0;
sizes.replace(fsize, idx);
}
return (unsigned __int64) fsize;
}

virtual StringBuffer &getId(StringBuffer &ret) const override
{
CriticalBlock b(crit);
Expand Down
7 changes: 4 additions & 3 deletions roxie/ccd/ccdkey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -691,10 +691,11 @@ class BufferedDirectReader : public CDirectReaderBase
while (!_partNo && !thisPart && ++thisPartIdx < maxParts) // MORE
{
thisPart.setown(f->getFilePart(thisPartIdx, thisFileStartPos));
if (thisPart && _startPos >= thisPart->size())
offset_t thisPartSize = f->partSize(thisPartIdx);
if (thisPart && _startPos >= thisPartSize)
{
_startPos -= thisPart->size();
completedStreamsSize += thisPart->size();
_startPos -= thisPartSize;
completedStreamsSize += thisPartSize;
thisPart.clear();
}
}
Expand Down
1 change: 1 addition & 0 deletions roxie/ccd/ccdstate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ interface IFileIOArray : extends IInterface
virtual unsigned numValid() const = 0;
virtual bool isValid(unsigned partNo) const = 0;
virtual unsigned __int64 size() const = 0;
virtual unsigned __int64 partSize(unsigned partNo) const = 0;
virtual StringBuffer &getId(StringBuffer &) const = 0;
virtual const char *queryLogicalFilename(unsigned partNo) const = 0;
virtual int queryActualFormatCrc() const = 0; // Actual format on disk
Expand Down

0 comments on commit bae0f58

Please sign in to comment.