瀏覽代碼

HPCC-13958 Revise based on code review

Signed-off-by: wangkx <kevin.wang@lexisnexis.com>
wangkx 9 年之前
父節點
當前提交
d8fcdc8739
共有 2 個文件被更改,包括 22 次插入23 次删除
  1. 9 5
      esp/services/ws_dfu/ws_dfuService.cpp
  2. 13 18
      esp/services/ws_dfu/ws_dfuService.hpp

+ 9 - 5
esp/services/ws_dfu/ws_dfuService.cpp

@@ -71,7 +71,7 @@ static const char* FEATURE_URL="DfuAccess";
 
 #define REMOVE_FILE_SDS_CONNECT_TIMEOUT (1000*15)  // 15 seconds
 
-const unsigned NODE_GROUP_CACHE_MIN_DEFAULT = 30;
+const unsigned NODE_GROUP_CACHE_DEFAULT_TIMEOUT = 30*60*1000; //30 minutes
 
 const int DESCRIPTION_DISPLAY_LENGTH = 12;
 const unsigned MAX_VIEWKEYFILE_ROWS = 1000;
@@ -100,11 +100,11 @@ CThorNodeGroup* CThorNodeGroupCache::readNodeGroup(const char* _groupName)
     return NULL;
 }
 
-CThorNodeGroup* CThorNodeGroupCache::lookup(const char* groupName, unsigned timeOutMinutes)
+CThorNodeGroup* CThorNodeGroupCache::lookup(const char* groupName, unsigned timeout)
 {
     CriticalBlock block(sect);
     CThorNodeGroup* item=SuperHashTableOf<CThorNodeGroup, const char>::find(groupName);
-    if (item && !item->checkTimeOut(timeOutMinutes))
+    if (item && !item->checkTimeout(timeout))
         return LINK(item);
 
     Owned<CThorNodeGroup> e = readNodeGroup(groupName);
@@ -148,7 +148,11 @@ void CWsDfuEx::init(IPropertyTree *cfg, const char *process, const char *service
         m_disableUppercaseTranslation = true;
 
     xpath.clear().appendf("Software/EspProcess[@name=\"%s\"]/EspService[@name=\"%s\"]/NodeGroupCacheMinutes", process, service);
-    nodeGroupCacheMinutes = cfg->getPropInt(xpath.str(), NODE_GROUP_CACHE_MIN_DEFAULT);
+    int timeout = cfg->getPropInt(xpath.str(), -1);
+    if (timeout > -1)
+        nodeGroupCacheTimeout = (unsigned) timeout*60*1000;
+    else
+        nodeGroupCacheTimeout = NODE_GROUP_CACHE_DEFAULT_TIMEOUT;
     thorNodeGroupCache.setown(new CThorNodeGroupCache());
 
     if (!daliClientActive())
@@ -1835,7 +1839,7 @@ void CWsDfuEx::getFilePartsOnClusters(IEspContext &context, const char* clusterR
             if (clusterInfo) //Should be valid. But, check it just in case.
             {
                 partsOnCluster->setReplicate(clusterInfo->queryPartDiskMapping().isReplicated());
-                Owned<CThorNodeGroup> nodeGroup = thorNodeGroupCache->lookup(clusterName, nodeGroupCacheMinutes);
+                Owned<CThorNodeGroup> nodeGroup = thorNodeGroupCache->lookup(clusterName, nodeGroupCacheTimeout);
                 if (nodeGroup)
                     partsOnCluster->setCanReplicate(nodeGroup->queryCanReplicate());
                 const char* defaultDir = fdesc->queryDefaultDir();

+ 13 - 18
esp/services/ws_dfu/ws_dfuService.hpp

@@ -32,7 +32,7 @@
 
 class CThorNodeGroup: public CInterface
 {
-    CDateTime timeCached;
+    unsigned timeCached;
     StringAttr groupName;
     unsigned keyhash;
     unsigned nodeCount;
@@ -43,23 +43,17 @@ public:
     CThorNodeGroup(const char* _groupName, unsigned _nodeCount, bool _replicateOutputs)
         : groupName(_groupName), nodeCount(_nodeCount), replicateOutputs(_replicateOutputs)
     {
-        keyhash = hashc((const byte *)groupName.get(),groupName.length(),0);
-        timeCached.setNow();
+        keyhash = hashnc((const byte *)groupName.get(),groupName.length(),0);
+        timeCached = msTick();
     }
 
-    inline unsigned queryHash() { return keyhash; }
-    inline const char *queryGroupName() { return groupName.get(); }
+    inline unsigned queryHash() const { return keyhash; }
+    inline const char *queryGroupName() const { return groupName.get(); }
 
-    inline bool queryNodeCount() { return nodeCount; };
-    inline bool queryReplicateOutputs() { return replicateOutputs; };
-    inline bool queryCanReplicate() { return replicateOutputs && (nodeCount > 1); };
-    inline bool checkTimeOut(unsigned timeOutMinutes)
-    {
-        CDateTime timeLine;
-        timeLine.setNow();
-        timeLine.adjustTime(-timeOutMinutes);
-        return timeCached <= timeLine;
-    }
+    inline unsigned queryNodeCount() const { return nodeCount; };
+    inline bool queryReplicateOutputs() const { return replicateOutputs; };
+    inline bool queryCanReplicate() const { return replicateOutputs && (nodeCount > 1); };
+    inline bool checkTimeout(unsigned timeout) const { return msTick()-timeCached >= timeout; }
 };
 
 class CThorNodeGroupCache: public SuperHashTableOf<CThorNodeGroup, const char>
@@ -79,7 +73,8 @@ public:
 
     inline void onRemove(void *e)
     {
-        // not used
+        CThorNodeGroup *g = (CThorNodeGroup *)e;
+        g->Release();
     }
 
     inline unsigned getHashFromElement(const void *e) const
@@ -89,7 +84,7 @@ public:
 
     inline unsigned getHashFromFindParam(const void *fp) const
     {
-        return hashc((const unsigned char *)fp, strlen((const char *)fp), 0);
+        return hashnc((const unsigned char *)fp, strlen((const char *)fp), 0);
     }
 
     inline const void * getFindParam(const void *e) const
@@ -121,7 +116,7 @@ class CWsDfuEx : public CWsDfu
 private:
     Owned<IXslProcessor> m_xsl;
     Mutex m_superfilemutex;
-    unsigned nodeGroupCacheMinutes;
+    unsigned nodeGroupCacheTimeout;
     Owned<CThorNodeGroupCache> thorNodeGroupCache;
 
 public: