Skip to content

Commit

Permalink
fixed cleanup of temp files at the interrupter secondary index build;…
Browse files Browse the repository at this point in the history
… fixed dev#3035
  • Loading branch information
tomatolog committed Dec 19, 2022
1 parent 0ad0e8c commit 2757b99
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
30 changes: 28 additions & 2 deletions secondary/builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class RawWriter_i
virtual void Done() = 0;

virtual SIWriter_i * GetWriter ( std::string & sError ) = 0;
virtual std::string GetFilename() const = 0;
};

template<typename VALUE>
Expand Down Expand Up @@ -171,6 +172,10 @@ struct RawWriter_T : public RawWriter_i
void SetAttr ( uint32_t tRowID, const int64_t * pData, int iLength ) final;

SIWriter_i * GetWriter ( std::string & sError ) final;
std::string GetFilename() const final
{
return m_tFile.GetFilename();
}

private:
Settings_t m_tSettings;
Expand Down Expand Up @@ -604,6 +609,21 @@ bool SIWriter_T<SRC_VALUE, DST_VALUE>::Process ( FileWriter_c & tDstFile, FileWr

/////////////////////////////////////////////////////////////////////

struct ScopedFilesRemoval_t
{
~ScopedFilesRemoval_t()
{
for ( const std::string & sFile : m_dFiles )
{
if ( IsFileExists ( sFile ))
::unlink ( sFile.c_str() );
}
}
std::vector<std::string> m_dFiles;
};

/////////////////////////////////////////////////////////////////////

class Builder_c final : public Builder_i
{
public:
Expand All @@ -624,6 +644,7 @@ class Builder_c final : public Builder_i
std::vector<std::shared_ptr<SIWriter_i>> m_dCidWriter;

std::vector<ColumnInfo_t> m_dAttrs;
ScopedFilesRemoval_t m_tCleanup;

void Flush();
bool WriteMeta ( const std::string & sPgmName, const std::string & sBlocksName, const std::vector<uint64_t> & dBlocksOffStart, const std::vector<uint64_t> & dBlocksCount, uint64_t uMetaOff, std::string & sError ) const;
Expand Down Expand Up @@ -688,8 +709,13 @@ bool Builder_c::Setup ( const Settings_t & tSettings, const Schema_t & tSchema,
m_iMaxRows = std::max ( 1000, iMemoryLimit / 3 / iRowSize );

for ( auto & pWriter : m_dRawWriter )
if ( pWriter )
pWriter->SetItemsCount ( m_iMaxRows );
{
if ( !pWriter )
continue;

pWriter->SetItemsCount ( m_iMaxRows );
m_tCleanup.m_dFiles.push_back ( pWriter->GetFilename() );
}

return true;
}
Expand Down
14 changes: 14 additions & 0 deletions util/reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,20 @@ int64_t GetFileSize ( int iFD, std::string * sError )
return st.st_size;
}

bool IsFileExists ( const std::string & sName )
{
struct_stat st = {0};
if( stat( sName.c_str(), &st ) != 0 )
{
return false;
} else if ( st.st_mode & S_IFDIR )
{
return false;
}

return true;
}

class MappedBuffer_c : public MappedBuffer_i
{
public:
Expand Down
1 change: 1 addition & 0 deletions util/reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ void ReadVectorData ( VEC & dData, FileReader_c & tReader )
}

int64_t GetFileSize ( int iFD, std::string * sError );
bool IsFileExists ( const std::string & sName );

class MappedBuffer_i
{
Expand Down

0 comments on commit 2757b99

Please sign in to comment.