浏览代码

HPCC-14833 Reduce reallocation of hashtables when freeing

Signed-off-by: Gavin Halliday <gavin.halliday@lexisnexis.com>
Gavin Halliday 9 年之前
父节点
当前提交
ce51b37b1a

+ 1 - 1
common/remote/rmtfile.cpp

@@ -397,7 +397,7 @@ public:
     }
     ~CDafsOsCache()
     {
-        SuperHashTableOf<CDafsOsCacheEntry,SocketEndpoint>::releaseAll();
+        SuperHashTableOf<CDafsOsCacheEntry,SocketEndpoint>::_releaseAll();
     }
     DAFS_OS lookup(const SocketEndpoint &ep,ISocket *sock)
     {

+ 2 - 2
common/remote/sockfile.cpp

@@ -713,7 +713,7 @@ public:
         numsockets = 0;
     }
     ~CConnectionTable() { 
-        releaseAll(); 
+        _releaseAll();
     }
 
     ISocket *lookup(const SocketEndpoint &ep)
@@ -3067,7 +3067,7 @@ public:
     }
     ~CClientStatsTable()
     {
-        kill();
+        _releaseAll();
     }
     CClientStats *getClientReference(RemoteFileCommandType cmd, const char *client)
     {

+ 1 - 1
common/thorhelper/layouttrans.ipp

@@ -259,7 +259,7 @@ class CRecordLayoutTranslatorCache : public CacheTable, public IRecordLayoutTran
 {
 public:
     IMPLEMENT_IINTERFACE;
-    virtual ~CRecordLayoutTranslatorCache() { releaseAll(); }
+    virtual ~CRecordLayoutTranslatorCache() { _releaseAll(); }
     virtual IRecordLayoutTranslator * get(size32_t diskMetaSize, void const  * diskMetaData, size32_t activityMetaSize, void const * activityMetaData, IDefRecordMeta const * activityMeta = NULL);
     virtual unsigned count() const { return CacheTable::count(); }
 

+ 1 - 1
common/thorhelper/thorcommon.cpp

@@ -61,7 +61,7 @@ void RowAggregator::reset()
         if (n)
             n->Release();
     }
-    SuperHashTable::releaseAll();
+    SuperHashTable::_releaseAll();
     eof = false;
     cursor = NULL;
     rowAllocator.clear();

+ 1 - 1
dali/base/dalock.cpp

@@ -182,7 +182,7 @@ public:
 
     ~CLockStateTable()
     {
-        releaseAll();
+        _releaseAll();
     }
 
     bool lock(DistributedLockId id,SessionId owner,bool excl,unsigned timeout)

+ 3 - 3
dali/base/dasds.cpp

@@ -828,7 +828,7 @@ typedef OwningStringSuperHashTableOf<CSubscriberContainerList> CSubscriberXPathT
 class CSubscriberTable : public ThreadSafeSimpleHashTableOf<CSubscriberContainer, SubscriptionId>
 {
 public:
-    ~CSubscriberTable() { kill(); }
+    ~CSubscriberTable() { _releaseAll(); }
 
     virtual void onAdd(void *et)
     {
@@ -2360,7 +2360,7 @@ class CServerRemoteTree : public CRemoteTreeBase
     {
     public:
         COrphanHandler() : ChildMap() { }
-        ~COrphanHandler() { kill(); }
+        ~COrphanHandler() { _releaseAll(); }
         static void setOrphans(CServerRemoteTree &tree, bool tf)
         {
             if (tf)
@@ -4664,7 +4664,7 @@ void CLock::clearLastRef()
 class ConnectionIdHashTable : public SuperHashTableOf<ConnectionId, ConnectionId>
 {
 public:
-    ~ConnectionIdHashTable() { kill(); }
+    ~ConnectionIdHashTable() { _releaseAll(); }
     IMPLEMENT_SUPERHASHTABLEOF_REF_FIND(ConnectionId, ConnectionId);
     virtual void onAdd(void *et) { }
     virtual void onRemove(void *et) { delete (ConnectionId *)et; }

+ 1 - 1
dali/base/dasds.ipp

@@ -122,7 +122,7 @@ private:
 class ChangeInfoMap : public SuperHashTableOf<ChangeInfo, IPropertyTree *>
 {
 public:
-    ~ChangeInfoMap() { kill(); }
+    ~ChangeInfoMap() { _releaseAll(); }
     virtual void onAdd(void *et) { }
     virtual void onRemove(void *et) { ((ChangeInfo *)et)->Release(); }
 

+ 2 - 2
dali/base/dasess.cpp

@@ -216,7 +216,7 @@ public:
     }
     ~CSessionStateTable() { 
         CHECKEDCRITICALBLOCK(sessstatesect,60000);
-        releaseAll(); 
+        _releaseAll();
     }
     bool add(CSessionState *e) // takes ownership
     {
@@ -340,7 +340,7 @@ public:
     ~CMapProcessToSession()
     {
         CHECKEDCRITICALBLOCK(mapprocesssect,60000);
-        releaseAll();
+        _releaseAll();
     }
 
     bool add(CProcessSessionState *e) 

+ 1 - 1
dali/daliadmin/daliadmin.cpp

@@ -768,7 +768,7 @@ class CIpTable: public SuperHashTableOf<CIpItem,IpAddress>
 public:
     ~CIpTable()
     {
-        releaseAll();
+        _releaseAll();
     }
 
     void onAdd(void *)

+ 2 - 2
dali/dfuXRefLib/dfuxreflib.cpp

@@ -165,7 +165,7 @@ class CFileEntryMap : public SuperHashTableOf<CFileEntry, const char>
 public:
     ~CFileEntryMap()
     {
-        releaseAll();
+        _releaseAll();
     }
     virtual void onAdd(void *e) 
     { 
@@ -359,7 +359,7 @@ class CEndpointTable: public SuperHashTableOf<CEndpointItem,SocketEndpoint>
 public:
     ~CEndpointTable()
     {
-        releaseAll();
+        _releaseAll();
     }
 
     void onAdd(void *)

+ 1 - 1
dali/sasha/packetstore.cpp

@@ -131,7 +131,7 @@ public:
     void clear()
     {
         CriticalBlock block(sect);
-        releaseAll();
+        _releaseAll();
     }
 
 protected:

+ 1 - 1
dali/sasha/saverify.cpp

@@ -130,7 +130,7 @@ class CIpTable: public SuperHashTableOf<CIpItem,IpAddress>
 public:
     ~CIpTable()
     {
-        releaseAll();
+        _releaseAll();
     }
 
     void onAdd(void *)

+ 1 - 1
ecl/hql/hqlexpr.ipp

@@ -106,7 +106,7 @@ class HQL_API UsedExpressionHashTable : public SuperHashTableOf<IHqlExpression,
 {
 public:
     UsedExpressionHashTable() : SuperHashTableOf<IHqlExpression,IHqlExpression>(false) {}
-    ~UsedExpressionHashTable() { releaseAll(); }
+    ~UsedExpressionHashTable() { _releaseAll(); }
 
     inline void zap(IHqlExpression & expr) { remove(&expr); }
 

+ 1 - 1
ecl/hql/hqlutil.hpp

@@ -416,7 +416,7 @@ public:
     IHqlExpression * find(IHqlExpression * e) const { return (IHqlExpression *)SuperHashTable::find(e); }
     void remove(IHqlExpression * e) { SuperHashTable::removeExact(e); }
 
-    ~HqlExprHashTable() { releaseAll(); }
+    ~HqlExprHashTable() { _releaseAll(); }
 
 private:
     virtual void     onAdd(void *et);

+ 1 - 1
ecl/hqlcpp/hqlregex.ipp

@@ -94,7 +94,7 @@ class HqlRegexHashTable : public SuperHashTable
 public:
     using SuperHashTable::add;
     using SuperHashTable::find;
-    ~HqlRegexHashTable() { releaseAll(); }
+    ~HqlRegexHashTable() { _releaseAll(); }
 
 private:
     virtual void     onAdd(void *et);

+ 1 - 1
ecl/hqlcpp/hqlstmt.ipp

@@ -76,7 +76,7 @@ class HQLCPP_API AssociationCache : public SuperHashTableOf<HqlExprAssociation,
 {
 public:
     AssociationCache() {}
-    ~AssociationCache() { releaseAll(); }
+    ~AssociationCache() { _releaseAll(); }
 
     IMPLEMENT_SUPERHASHTABLEOF_REF_FIND(HqlExprAssociation, IHqlExpression);
 

+ 1 - 1
ecl/hthor/hthor.ipp

@@ -550,7 +550,7 @@ public:
     }
     virtual ~HashDedupTable()
     { 
-        releaseAll();
+        _releaseAll();
     }
     virtual void onAdd(void *et)    {}
     virtual void onRemove(void *et)

+ 1 - 1
esp/services/ws_dfu/ws_dfuService.hpp

@@ -64,7 +64,7 @@ class CThorNodeGroupCache: public SuperHashTableOf<CThorNodeGroup, const char>
 public:
     IMPLEMENT_IINTERFACE;
 
-    ~CThorNodeGroupCache() { releaseAll(); }
+    ~CThorNodeGroupCache() { _releaseAll(); }
 
     inline void onAdd(void *e)
     {

+ 1 - 1
roxie/ccd/ccdcontext.cpp

@@ -2344,7 +2344,7 @@ public:
     {
         // NOTE: This is needed to ensure that owned activities are destroyed BEFORE I am,
         // to avoid pure virtual calls when they come to call noteProcessed()
-        childGraphs.kill();
+        childGraphs.releaseAll();
     }
 
     virtual IRoxieServerContext *queryServerContext()

+ 1 - 1
roxie/ccd/ccdserver.cpp

@@ -7140,7 +7140,7 @@ class CRoxieServerHashDedupActivity : public CRoxieServerActivity
               keySize(helper.queryKeySize())
         {
         }
-        virtual ~HashDedupTable() { releaseAll(); }
+        virtual ~HashDedupTable() { _releaseAll(); }
 
         virtual unsigned getHashFromElement(const void *et) const       
         {

+ 1 - 1
system/jhtree/keybuild.cpp

@@ -40,7 +40,7 @@ class CRC32HT : public SuperHashTableOf<CRC32HTE, offset_t>
 public:
     CRC32HT(void) : SuperHashTableOf<CRC32HTE, offset_t>() { }
     CRC32HT(unsigned initsize) : SuperHashTableOf<CRC32HTE, offset_t>(initsize) { }
-    ~CRC32HT() { CRC32HT::kill(); }
+    ~CRC32HT() { _releaseAll(); }
     CRC32HTE *find(offset_t & fp) const { return SuperHashTableOf<CRC32HTE, offset_t>::find(&fp); }
     virtual void onAdd(void *et) { }
     virtual void onRemove(void *et) { }

+ 1 - 1
system/jlib/javahash.hpp

@@ -60,7 +60,7 @@ private:
   public:
     JavaHashTableOf(bool _keep = true)
         : SuperHashTableOf<ELEMENT, ELEMENT>(), keep(_keep) {}
-    ~JavaHashTableOf() { _SELF::releaseAll(); }
+    ~JavaHashTableOf() { _SELF::_releaseAll(); }
 
     IMPLEMENT_IINTERFACE
 

+ 3 - 3
system/jlib/jhash.hpp

@@ -80,7 +80,7 @@ class jlib_decl HashTable
     HashTable(unsigned initsize, int _keysize, bool _ignorecase)
         : SuperHashTableOf<IMapping, const void>(initsize),
         keysize(_keysize), ignorecase(_ignorecase) {}
-    ~HashTable() { releaseAll(); }
+    ~HashTable() { _releaseAll(); }
 
     IMPLEMENT_IINTERFACE
 
@@ -127,7 +127,7 @@ public:
         : HashTable(_keysize, _ignorecase) {}
     KeptHashTable(unsigned _initsize, int _keysize, bool _ignorecase)
         : HashTable(_initsize, _keysize, _ignorecase) {}
-    ~KeptHashTable() { releaseAll(); }
+    ~KeptHashTable() { _releaseAll(); }
 
     IMapping * create(const void *key);
 
@@ -143,7 +143,7 @@ public:
         : HashTable(_keysize, _ignorecase) {}
     ObservedHashTable(unsigned _initsize, int _keysize, bool _ignorecase)
         : HashTable(_initsize, _keysize, _ignorecase) {}
-    ~ObservedHashTable() { releaseAll(); }
+    ~ObservedHashTable() { _releaseAll(); }
 
 private:
     void       onAdd(void *et);

+ 1 - 1
system/jlib/jptree.ipp

@@ -79,7 +79,7 @@ public:
     }
     ~ChildMap() 
     { 
-        kill(); 
+        _releaseAll();
     }
     virtual unsigned numChildren();
     virtual IPropertyTreeIterator *getIterator(bool sort);

+ 1 - 1
system/jlib/jsocket.cpp

@@ -5944,7 +5944,7 @@ public:
     IMPLEMENT_IINTERFACE;
 
     CSocketEndpointHashTable() {}
-    ~CSocketEndpointHashTable() { kill(); }
+    ~CSocketEndpointHashTable() { _releaseAll(); }
     
     void add(const SocketEndpoint &ep, IInterface *i)
     {

+ 1 - 1
system/jlib/jstats.cpp

@@ -1032,7 +1032,7 @@ typedef StructArrayOf<Statistic> StatsArray;
 class CollectionHashTable : public SuperHashTableOf<CStatisticCollection, StatsScopeId>
 {
 public:
-    ~CollectionHashTable() { releaseAll(); }
+    ~CollectionHashTable() { _releaseAll(); }
     virtual void     onAdd(void *et);
     virtual void     onRemove(void *et);
     virtual unsigned getHashFromElement(const void *et) const;

+ 25 - 15
system/jlib/jsuperhash.cpp

@@ -481,28 +481,38 @@ void SuperHashTable::doKill(void)
     free(table);
 }
 
-void SuperHashTable::releaseAll(void)
+void SuperHashTable::_releaseAll(void)
 {
-    unsigned i;
-    for (i = 0; i < tablesize; i++)
+    if (tablecount)
     {
-        void * et = table[i];
-        table[i] = NULL;
-        if (et)
-            onRemove(et);
+        unsigned i;
+        for (i = 0; i < tablesize; i++)
+        {
+            void * et = table[i];
+            table[i] = NULL;
+            if (et)
+                onRemove(et);
+        }
+        tablecount = 0;
+        setCache(0);
     }
-    tablecount = 0;
+}
+
+void SuperHashTable::releaseAll()
+{
+    _releaseAll();
 }
 
 void SuperHashTable::kill(void)
 {
-    releaseAll();
-    doKill();
-    tablesize = InitialTableSize;
-    tablecount = 0;
-    setCache(0);
-    table = (void * *) checked_malloc(InitialTableSize*sizeof(void *),-604);
-    memset(table,0,InitialTableSize*sizeof(void *));
+    _releaseAll();
+    if (tablesize != InitialTableSize)
+    {
+        doKill();
+        tablesize = InitialTableSize;
+        table = (void * *)checked_malloc(InitialTableSize*sizeof(void *), -604);
+        memset(table, 0, InitialTableSize*sizeof(void *));
+    }
 }
 
 void *SuperHashTable::addOrFind(void * donor)

+ 13 - 6
system/jlib/jsuperhash.hpp

@@ -37,7 +37,7 @@ public:
     SuperHashTable(void);
     SuperHashTable(unsigned initsize);
     ~SuperHashTable();
-    // Derived class destructor expected to call releaseAll()
+    // Derived class destructor expected to call _releaseAll()
     
     void             reinit(unsigned initsize);
     void             kill(void);
@@ -46,6 +46,7 @@ public:
     inline memsize_t queryMem() const { return tablesize * sizeof(void *); } // hash table table memory size
     void *           next(const void *et) const;
     void             ensure(unsigned mincount);
+    void             releaseAll(); // like kill(), but does not resize the table
 
 #ifdef TRACE_HASH
     void dumpStats();
@@ -53,7 +54,7 @@ public:
 
 protected:
     void             init(unsigned initsize);
-    void             releaseAll(void);
+    void             _releaseAll(void); // not guaranteed to be thread safe, typically called from destructor
     inline bool      add(void * et) { return doAdd(et, false); }
     inline bool      replace(void * et) { return doAdd(et, true); }
     void             addNew(void * et); //use this when you are sure the key does not already exist in the table (saves some needless matching)
@@ -321,12 +322,14 @@ class ThreadSafeSimpleHashTableOf : private SuperHashTable
     {
         return *(FP *)((const ET *)et)->queryFindParam() == *(FP *)fp;
     }
+protected:
+    using SuperHashTable::_releaseAll;
 public:
     mutable CriticalSection crit;
 
     ThreadSafeSimpleHashTableOf(void) : SuperHashTable() { }
     ThreadSafeSimpleHashTableOf(unsigned initsize) : SuperHashTable(initsize) { }
-    ~ThreadSafeSimpleHashTableOf() { SELF::kill(); }
+    ~ThreadSafeSimpleHashTableOf() { _releaseAll(); }
 
     ET *find(FP & fp) const
     {
@@ -340,7 +343,11 @@ public:
         CriticalBlock block(crit);
         SuperHashTable::kill();
     }
-
+    void releaseElements()
+    {
+        CriticalBlock block(crit);
+        SuperHashTable::releaseAll();
+    }
     bool add(ET & et)
     { 
         CriticalBlock block(crit);
@@ -388,7 +395,7 @@ class ThreadSafeOwningSimpleHashTableOf : public ThreadSafeSimpleHashTableOf<ET,
 {
     typedef ThreadSafeOwningSimpleHashTableOf<ET, FP> SELF;
 public:
-    ~ThreadSafeOwningSimpleHashTableOf<ET, FP>() { SELF::kill(); }
+    ~ThreadSafeOwningSimpleHashTableOf<ET, FP>() { SELF::_releaseAll(); }
     virtual void onRemove(void *et) { ((ET *)et)->Release(); }
 };
 
@@ -495,7 +502,7 @@ public:
     IMPLEMENT_SUPERHASHTABLEOF_REF_FIND(HashKeyElement, constcharptr);
 
     AtomRefTable(bool _nocase=false) : SuperHashTableOf<HashKeyElement, constcharptr>(3000), nocase(_nocase) { }
-    ~AtomRefTable() { kill(); }
+    ~AtomRefTable() { _releaseAll(); }
 
     inline HashKeyElement *findLink(const char *_key)
     {

+ 1 - 1
system/mp/mpbase.cpp

@@ -64,7 +64,7 @@ class MPNodeCache: public SuperHashTableOf<MPNode,SocketEndpoint>
 public:
     ~MPNodeCache()
     {
-        releaseAll();
+        _releaseAll();
     }
 
     void onAdd(void *)

+ 1 - 1
system/mp/mpcomm.cpp

@@ -2155,7 +2155,7 @@ CMPServer::~CMPServer()
     if (buf.length())
         LOG(MCdebugInfo(100), unknownJob, "MP: Orphan check\n%s",buf.str());
 #endif
-    releaseAll();
+    _releaseAll();
     selecthandler->Release();
     notifyclosedthread->stop();
     notifyclosedthread->Release();

+ 2 - 2
thorlcr/graph/thgraph.cpp

@@ -1160,10 +1160,10 @@ void CGraphBase::clean()
     ::Release(doneBarrier);
     localResults.clear();
     graphLoopResults.clear();
-    childGraphsTable.kill();
+    childGraphsTable.releaseAll();
     childGraphs.kill();
     disconnectActivities();
-    containers.kill();
+    containers.releaseAll();
     sinks.kill();
     activeSinks.kill();
 }