Skip to content

Commit 38f3547

Browse files
committed
1.Renamed name to fname for removeTemporaryFile.
2.Replaced tempOwnerId with tempFilePrefix which includes wuid. 3.tempFilePrefix is set in EclAgent constructor. 4.Removed inline conversion to std::string() as unnecessary. 5.Ensure only tempFileSet functionality is executed after tfsect. 6.Added missing overrides. 7.Removed mutable from CriticalSection tfsect as unnecessary. Signed-off-by: Dave Streeter <dave.streeter@lexisnexisrisk.com>
1 parent c22cada commit 38f3547

3 files changed

Lines changed: 37 additions & 39 deletions

File tree

ecl/eclagent/agentctx.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,12 @@ enum class AccessMode : unsigned;
8282

8383
interface ITempFileHandler
8484
{
85+
// name is the name/id of the temporary file, not the filename on disk.
8586
virtual const char *noteTemporaryFile(const char *name) = 0;
87+
// name is the name/id of the temporary file, not the filename on disk.
8688
virtual const char *queryTemporaryFile(const char *name) = 0;
87-
virtual void removeTemporaryFile(const char *name) = 0;
89+
// fname is the temporary filename on disk returned from noteTemporaryFile or queryTemporaryFile.
90+
virtual void removeTemporaryFile(const char *fname) = 0;
8891
};
8992

9093
struct IAgentContext : extends IGlobalCodeContext, extends ITempFileHandler

ecl/eclagent/eclagent.cpp

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,9 @@ EclAgent::EclAgent(IConstWorkUnit *wu, const char *_wuid, bool _checkVersion, bo
565565
abortmonitor->setGuillotineCost(getGuillotineCost(wu));
566566
configurePreferredPlanes();
567567
agentMachineCost = getMachineCostRate();
568+
569+
getTempfileBase(tempFilePrefix);
570+
tempFilePrefix.append(PATHSEPCHAR);
568571
}
569572

570573
EclAgent::~EclAgent()
@@ -610,41 +613,30 @@ const char *EclAgent::queryTempfilePath()
610613
return agentTempDir.str();
611614
}
612615

613-
StringBuffer & EclAgent::getTempfileBase(StringBuffer & buff)
616+
StringBuffer &EclAgent::getTempfileBase(StringBuffer &buff)
614617
{
615618
return buff.append(queryTempfilePath()).append(PATHSEPCHAR).appendLower(wuid);
616619
}
617620

618621
void EclAgent::buildTempFilename(StringBuffer &tempFilename, const char *name)
619622
{
620-
/* tempOwnerId is used at the end of the temporary file name to ensure
621-
* that in the event of a crash, we can use the pid and start time to
622-
* determine if temp files are from a currently running process or not,
623-
* and therefore whether they can be safely deleted.
624-
*/
625-
if (tempOwnerId.isEmpty())
626-
{
627-
unsigned pid = (unsigned)GetCurrentProcessId();
628-
unsigned __int64 startEpoch = (unsigned __int64)time(nullptr);
629-
tempOwnerId.append('.').append(pid).append('.').append(startEpoch);
630-
}
631-
632-
getTempfileBase(tempFilename);
633-
tempFilename.append(PATHSEPCHAR).append('.').append(name).append(tempOwnerId);
623+
tempFilename.append(tempFilePrefix).append(name);
634624
}
635625

636626
const char *EclAgent::queryTemporaryFile(const char *name)
637627
{
638628
dbgassertex(!isEmptyString(name));
639629

640-
CriticalBlock crit(tfsect);
641-
642630
StringBuffer tempFilename;
643631
buildTempFilename(tempFilename, name);
644632

645-
auto it = tempFileSet.find(std::string(tempFilename.str()));
646-
if (it != tempFileSet.end())
647-
return it->c_str();
633+
{
634+
CriticalBlock crit(tfsect);
635+
636+
auto it = tempFileSet.find(tempFilename.str());
637+
if (it != tempFileSet.end())
638+
return it->c_str();
639+
}
648640

649641
VStringBuffer errmsg("Attempt to read temp file that has not yet been registered: %s", name);
650642
fail(0, errmsg.str());
@@ -655,12 +647,16 @@ const char *EclAgent::noteTemporaryFile(const char *name)
655647
{
656648
dbgassertex(!isEmptyString(name));
657649

658-
CriticalBlock crit(tfsect);
659-
660650
StringBuffer tempFilename;
661651
buildTempFilename(tempFilename, name);
662652

663-
auto inserted = tempFileSet.emplace(tempFilename.str());
653+
std::pair<std::set<std::string>::iterator, bool> inserted;
654+
{
655+
CriticalBlock crit(tfsect);
656+
657+
inserted = tempFileSet.emplace(tempFilename.str());
658+
}
659+
664660
if (!inserted.second)
665661
{
666662
VStringBuffer errmsg("Temp file already registered: %s", name);
@@ -671,13 +667,13 @@ const char *EclAgent::noteTemporaryFile(const char *name)
671667
return inserted.first->c_str();
672668
}
673669

674-
void EclAgent::removeTemporaryFile(const char *name)
670+
void EclAgent::removeTemporaryFile(const char *fname)
675671
{
676-
dbgassertex(!isEmptyString(name));
672+
dbgassertex(!isEmptyString(fname));
677673

678674
CriticalBlock crit(tfsect);
679675

680-
auto it = tempFileSet.find(std::string(name));
676+
auto it = tempFileSet.find(std::string(fname));
681677
dbgassertex(it != tempFileSet.end());
682678
if (it != tempFileSet.end())
683679
{
@@ -690,9 +686,8 @@ void EclAgent::deleteTempFiles()
690686
{
691687
CriticalBlock crit(tfsect);
692688

693-
if (!tempOwnerId.isEmpty())
694-
while (!tempFileSet.empty())
695-
removeTemporaryFile(tempFileSet.begin()->c_str());
689+
while (!tempFileSet.empty())
690+
removeTemporaryFile(tempFileSet.begin()->c_str());
696691
}
697692

698693
const char *EclAgent::loadResource(unsigned id)

ecl/eclagent/eclagent.ipp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -174,17 +174,17 @@ public:
174174
{
175175
return ctx->getTempfileBase(buff);
176176
}
177-
virtual const char *noteTemporaryFile(const char *name)
177+
virtual const char *noteTemporaryFile(const char *name) override
178178
{
179179
return ctx->noteTemporaryFile(name);
180180
}
181-
virtual const char *queryTemporaryFile(const char *name)
181+
virtual const char *queryTemporaryFile(const char *name) override
182182
{
183183
return ctx->queryTemporaryFile(name);
184184
}
185-
virtual void removeTemporaryFile(const char *name)
185+
virtual void removeTemporaryFile(const char *fname) override
186186
{
187-
ctx->removeTemporaryFile(name);
187+
ctx->removeTemporaryFile(fname);
188188
}
189189
virtual void reloadWorkUnit()
190190
{
@@ -380,8 +380,8 @@ private:
380380
unsigned __int64 stopAfter;
381381
mutable CriticalSection wusect;
382382
std::set<std::string> tempFileSet; // Set of actual temp file names on disk
383-
StringBuffer tempOwnerId; // Holds the current pid and start epoch of the process for temp files in map tempFileNameById
384-
mutable CriticalSection tfsect;
383+
StringBuffer tempFilePrefix; // Spill and WUID folder path for temp files
384+
CriticalSection tfsect;
385385
IArray persistReadLocks;
386386
StringArray processedPersists;
387387

@@ -618,9 +618,9 @@ public:
618618

619619
virtual unsigned __int64 getDatasetHash(const char * name, unsigned __int64 hash);
620620
virtual void reportProgress(const char *msg, unsigned flags=0);
621-
virtual const char *noteTemporaryFile(const char *name);
622-
virtual const char *queryTemporaryFile(const char *name);
623-
virtual void removeTemporaryFile(const char *name);
621+
virtual const char *noteTemporaryFile(const char *name) override;
622+
virtual const char *queryTemporaryFile(const char *name) override;
623+
virtual void removeTemporaryFile(const char *fname) override;
624624
virtual void deleteFile(const char * logicalName);
625625

626626
void addException(ErrorSeverity severity, const char * source, unsigned code, const char * text, const char * filename, unsigned lineno, unsigned column, bool failOnError, bool isAbort);

0 commit comments

Comments
 (0)