浏览代码

HPCC-25132 Remove server-side cache code from Roxie

Signed-off-by: Richard Chapman <rchapman@hpccsystems.com>
Richard Chapman 4 年之前
父节点
当前提交
8ac2d78172
共有 6 个文件被更改,包括 5 次插入304 次删除
  1. 0 4
      roxie/ccd/ccd.hpp
  2. 0 4
      roxie/ccd/ccdmain.cpp
  3. 0 45
      roxie/ccd/ccdqueue.cpp
  4. 5 237
      roxie/ccd/ccdserver.cpp
  5. 0 9
      roxie/ccd/ccdserver.hpp
  6. 0 5
      roxie/ccd/ccdstate.cpp

+ 0 - 4
roxie/ccd/ccd.hpp

@@ -247,8 +247,6 @@ interface IRoxieQueryPacket : extends IInterface
     virtual unsigned getContextLength() const = 0;
 
     virtual IRoxieQueryPacket *clonePacket(unsigned channel) const = 0;
-    virtual unsigned hash() const = 0;
-    virtual bool cacheMatch(const IRoxieQueryPacket *) const = 0; // note - this checks whether it's a repeat from server's point-of-view
     virtual IRoxieQueryPacket *insertSkipData(size32_t skipDataLen, const void *skipData) const = 0;
 };
 
@@ -314,7 +312,6 @@ extern unsigned preabortIndexReadsThreshold;
 extern bool traceStartStop;
 extern bool traceRoxiePackets;
 extern bool delaySubchannelPackets;
-extern bool traceServerSideCache;
 extern bool traceTranslations;
 extern bool defaultTimeActivities;
 extern bool defaultTraceEnabled;
@@ -335,7 +332,6 @@ extern HardwareInfo hdwInfo;
 extern unsigned parallelAggregate;
 extern bool inMemoryKeysEnabled;
 extern unsigned __int64 minFreeDiskSpace;
-extern unsigned serverSideCacheSize;
 extern bool probeAllRows;
 extern bool steppingEnabled;
 extern bool simpleLocalKeyedJoins;

+ 0 - 4
roxie/ccd/ccdmain.cpp

@@ -83,7 +83,6 @@ bool pretendAllOpt = false;
 bool traceStartStop = false;
 bool traceRoxiePackets = false;
 bool delaySubchannelPackets = false;    // For debugging/testing purposes only
-bool traceServerSideCache = false;
 bool defaultTimeActivities = true;
 bool defaultTraceEnabled = false;
 bool traceTranslations = true;
@@ -201,7 +200,6 @@ SocketEndpoint debugEndpoint;
 HardwareInfo hdwInfo;
 unsigned parallelAggregate;
 bool inMemoryKeysEnabled = true;
-unsigned serverSideCacheSize = 0;
 
 bool nodeCachePreload = false;
 unsigned nodeCacheMB = 100;
@@ -1039,7 +1037,6 @@ int CCD_API roxie_main(int argc, const char *argv[], const char * defaultYaml)
 
         traceStartStop = topology->getPropBool("@traceStartStop", false);
         watchActivityId = topology->getPropInt("@watchActivityId", 0);
-        traceServerSideCache = topology->getPropBool("@traceServerSideCache", false);
         traceRoxiePackets = topology->getPropBool("@traceRoxiePackets", false);
         delaySubchannelPackets = topology->getPropBool("@delaySubchannelPackets", false);
         IBYTIbufferSize = topology->getPropInt("@IBYTIbufferSize", roxieMulticastEnabled ? 0 : 10);
@@ -1096,7 +1093,6 @@ int CCD_API roxie_main(int argc, const char *argv[], const char * defaultYaml)
             parallelAggregate = 1;
         simpleLocalKeyedJoins = topology->getPropBool("@simpleLocalKeyedJoins", true);
         inMemoryKeysEnabled = topology->getPropBool("@inMemoryKeysEnabled", true);
-        serverSideCacheSize = topology->getPropInt("@serverSideCacheSize", 0);
 
         setKeyIndexCacheSize((unsigned)-1); // unbound
         nodeCachePreload = topology->getPropBool("@nodeCachePreload", false);

+ 0 - 45
roxie/ccd/ccdqueue.cpp

@@ -599,51 +599,6 @@ public:
         return createRoxiePacket(newdata, newDataSize);
     }
 
-    virtual unsigned hash() const
-    {
-        // This is used for Roxie server-side caching. The hash includes some of the header and all of the payload.
-        unsigned hash = 0;
-        if (continuationLength)
-            hash = hashc((const unsigned char *) continuationData, continuationLength, hash);
-        if (smartStepInfoLength)
-            hash = hashc((const unsigned char *) smartStepInfoData, smartStepInfoLength, hash);
-        // NOTE - don't hash the trace info!
-        hash = hashc((const unsigned char *) contextData, contextLength, hash);
-        hash = hashc((const unsigned char *) &data->channel, sizeof(data->channel), hash);
-        hash = hashc((const unsigned char *) &data->overflowSequence, sizeof(data->overflowSequence), hash); 
-        hash = hashc((const unsigned char *) &data->continueSequence, sizeof(data->continueSequence), hash); 
-        // MORE - sequence fields should always be zero for anything we are caching I think... (?)
-        // Note - no point hashing activityId (as cache is local to one activity) or serverIP (likewise)
-        return hash;
-    }
-
-    virtual bool cacheMatch(const IRoxieQueryPacket *c) const 
-    {
-        // note - this checks whether it's a repeat from Roxie server's point-of-view
-        // So fields that are compared are the same as the ones that are hashed....
-        RoxiePacketHeader &h = c->queryHeader();
-        if (data->channel == h.channel && data->overflowSequence == h.overflowSequence && data->continueSequence == h.continueSequence)
-        {
-            if (continuationLength) // note - we already checked that sequences match
-            {
-                if (continuationLength != c->getContinuationLength())
-                    return false;
-                if (memcmp(continuationData,c->queryContinuationData(),continuationLength)!=0)
-                    return false;
-            }
-            if (smartStepInfoLength)
-            {
-                if (smartStepInfoLength != c->getSmartStepInfoLength())
-                    return false;
-                if (memcmp(smartStepInfoData,c->querySmartStepInfoData(),smartStepInfoLength)!=0)
-                    return false;
-            }
-            // NOTE - trace info NOT compared
-            if (contextLength == c->getContextLength() && memcmp(contextData, c->queryContextData(), contextLength)==0)
-                return true;
-        }
-        return false;
-    }
 };
 
 extern IRoxieQueryPacket *createRoxiePacket(void *_data, unsigned _len)

+ 5 - 237
roxie/ccd/ccdserver.cpp

@@ -595,11 +595,6 @@ public:
         return graph.getClear();
     }
 
-    virtual IRoxieServerSideCache *queryServerSideCache() const
-    {
-        return NULL; // Activities that wish to support server-side caching will need to do better....
-    }
-
     virtual void getXrefInfo(IPropertyTree &reply, const IRoxieContextLogger &logctx) const
     {
         // Most activities have nothing to say...
@@ -1626,11 +1621,6 @@ public:
     {
     }
 
-    virtual IRoxieServerSideCache *queryServerSideCache() const
-    {
-        return factory->queryServerSideCache();
-    }
-
     virtual const IRoxieServerActivityFactory *queryFactory() const
     {
         return factory;
@@ -3100,189 +3090,6 @@ public:
     }
 };
 
-class CRoxieServerSideCache : implements IRoxieServerSideCache, implements ILRUChain
-{
-protected:
-    unsigned cacheTableSize;
-    unsigned cacheTableSpace;
-    IRoxieServerQueryPacket **cacheTable;
-    mutable ILRUChain *prev;
-    mutable ILRUChain *next;
-    mutable CriticalSection crit;
-
-    virtual ILRUChain *queryPrev() const { return prev; }
-    virtual ILRUChain *queryNext() const { return next; }
-    virtual void setPrev(ILRUChain *p) { prev = p; }
-    virtual void setNext(ILRUChain *n) { next = n; }
-    virtual void unchain()
-    {
-        prev->setNext(next);
-        next->setPrev(prev);
-        next = NULL;
-        prev = NULL;
-    }
-
-    void moveToHead(IRoxieServerQueryPacket *mru)
-    {
-        mru->unchain();
-
-        mru->setNext(next);
-        next->setPrev(mru);
-        mru->setPrev(this);
-        next = mru;
-    }
-
-    IRoxieServerQueryPacket *removeLRU()
-    {
-        if (next==this)
-            assertex(next != this);
-        IRoxieServerQueryPacket *goer = (IRoxieServerQueryPacket *) next;
-        goer->unchain(); // NOTE - this will modify the value of next
-        return goer;
-    }
-
-    void removeEntry(IRoxieServerQueryPacket *goer)
-    {
-        unsigned v = goer->queryHash() % cacheTableSize;
-        for (;;)
-        {
-            IRoxieServerQueryPacket *found = cacheTable[v];
-            assertex(found);
-            if (found == goer)
-            {
-                cacheTable[v] = NULL;
-                unsigned vn = v;
-                for (;;)
-                {
-                    vn++;
-                    if (vn==cacheTableSize) vn = 0;
-                    IRoxieServerQueryPacket *found2 = cacheTable[vn];
-                    if (!found2)
-                        break;
-                    unsigned vm = found2->queryHash() % cacheTableSize;
-                    if (((vn+cacheTableSize-vm) % cacheTableSize)>=((vn+cacheTableSize-v) % cacheTableSize))  // diff(vn,vm)>=diff(vn,v)
-                    {
-                        cacheTable[v] = found2;
-                        v = vn;
-                        cacheTable[v] = NULL;
-                    }
-                }
-                cacheTableSpace++;
-                break;
-            }
-            v++;
-            if (v==cacheTableSize)
-                v = 0;
-        }
-        goer->Release();
-    }
-
-public:
-    CRoxieServerSideCache(unsigned _cacheSize)
-    {
-        cacheTableSize = (_cacheSize*4)/3;
-        cacheTable = new IRoxieServerQueryPacket *[cacheTableSize];
-        memset(cacheTable, 0, cacheTableSize * sizeof(IRoxieServerQueryPacket *));
-        cacheTableSpace = _cacheSize;
-        prev = this;
-        next = this;
-    }
-    ~CRoxieServerSideCache()
-    {
-        for (unsigned i = 0; i < cacheTableSize; i++)
-        {
-            ::Release(cacheTable[i]);
-        }
-        delete [] cacheTable;
-    }
-
-    virtual IRoxieServerQueryPacket *findCachedResult(const IRoxieContextLogger &logctx, IRoxieQueryPacket *p) const
-    {
-        unsigned hash = p->hash();
-        unsigned et = hash % cacheTableSize;
-        if (traceServerSideCache)
-        {
-            StringBuffer s; 
-            logctx.CTXLOG("CRoxieServerSideCache::findCachedResult hash %x slot %d %s", hash, et, p->queryHeader().toString(s).str());
-        }
-        CriticalBlock b(crit);
-        for (;;)
-        {
-            IRoxieServerQueryPacket *found = cacheTable[et];
-            if (!found)
-                return NULL;
-            if (found->queryHash() == hash && found->queryPacket()->cacheMatch(p))
-            {
-                const_cast<CRoxieServerSideCache *>(this)->moveToHead(found);
-                if (traceServerSideCache)
-                    logctx.CTXLOG("CRoxieServerSideCache::findCachedResult cache hit");
-                logctx.noteStatistic(StNumServerCacheHits, 1);
-                return NULL;
-                // Because IMessageResult cannot be replayed, this scheme is flawed. I'm leaving the code here just as a stats gatherer to see how useful it would have been....
-                //IRoxieServerQueryPacket *ret = new CRoxieServerQueryPacket(p);
-                //ret->setResult(found->getResult());
-                //return ret;
-            }
-            et++;
-            if (et == cacheTableSize)
-                et = 0;
-        }
-    }
-
-    virtual void noteCachedResult(IRoxieServerQueryPacket *out, IMessageResult *in)
-    {
-        if (true) //!in->getLength()) // MORE - separate caches for hits and nohits
-        {
-            unsigned hash = out->queryPacket()->hash();
-            out->setHash(hash);
-            unsigned et = hash % cacheTableSize;
-            if (traceServerSideCache)
-            {
-                StringBuffer s; 
-                DBGLOG("CRoxieServerSideCache::noteCachedResult hash %x slot %d %s", hash, et, out->queryPacket()->queryHeader().toString(s).str());
-            }
-            CriticalBlock b(crit);
-            for (;;)
-            {
-                IRoxieServerQueryPacket *found = cacheTable[et];
-                if (!found)
-                {
-                    if (cacheTableSpace)
-                    {
-                        out->setResult(LINK(in)); 
-                        cacheTable[et] = LINK(out);
-                        cacheTableSpace--;
-                        moveToHead(out);
-                        break;
-                    }
-                    else
-                    {
-                        IRoxieServerQueryPacket *goer = removeLRU();
-                        removeEntry(goer);
-                        et = hash % cacheTableSize;
-                        continue;
-                    }
-                }
-                else if (found->queryHash()==hash && found->queryPacket()->cacheMatch(out->queryPacket()))
-                {
-                    moveToHead(found);
-                    return; // already in the cache. Because we don't cache until we have result, this can happen where 
-                    // multiple copies of a agent query are in-flight at once.
-                }
-                et++;
-                if (et == cacheTableSize)
-                    et = 0;
-            }
-        }
-        // MORE - do we need to worry about the attachment between the MessageUnpacker and the current row manager. May all fall out ok...
-        // Can I easily spot a null result? Do I want to cache null results separately? only?
-    }
-
-    // Note that this caching mechanism (unlike the old keyed-join specific one) does not common up cases where multiple 
-    // identical queries are in-flight at the same time. But if we can make it persistent between queries that will
-    // more than make up for it
-};
-
 class CRowArrayMessageUnpackCursor : implements IMessageUnpackCursor, public CInterface
 {
     ConstPointerArray &data;
@@ -3812,19 +3619,8 @@ class CRemoteResultAdaptor : implements IEngineRowStream, implements IFinalRoxie
 
     };
 
-    IRoxieServerQueryPacket *createRoxieServerQueryPacket(IRoxieQueryPacket *p, bool &cached)
+    IRoxieServerQueryPacket *createRoxieServerQueryPacket(IRoxieQueryPacket *p)
     {
-        if (serverSideCache && !debugContext)
-        {
-            IRoxieServerQueryPacket *ret = serverSideCache->findCachedResult(activity.queryLogCtx(), p);
-            if (ret)
-            {
-                p->Release();
-                cached = true;
-                return ret;
-            }
-        }
-        cached = false;
         return new CRoxieServerQueryPacket(p);
     }
 
@@ -4082,7 +3878,6 @@ private:
     IHThorArg *colocalArg;
     IArrayOf<IRoxieServerQueryPacket> pending;
     CriticalSection pendingCrit;
-    IRoxieServerSideCache *serverSideCache;
     unsigned sentSequence;
     Owned<IOutputRowDeserializer> deserializer;
     Owned<IEngineRowAllocator> rowAllocator;
@@ -4245,7 +4040,6 @@ public:
         sentSequence = 0;
         resendSequence = 0;
         totalCycles = 0;
-        serverSideCache = activity.queryServerSideCache();
         bufferStream.setown(createMemoryBufferSerialStream(tempRowBuffer));
         rowSource.setStream(bufferStream);
         timeActivities = defaultTimeActivities;
@@ -4312,8 +4106,7 @@ public:
 
             if (p->queryHeader().channel)
             {
-                bool cached = false;
-                IRoxieServerQueryPacket *rsqp = createRoxieServerQueryPacket(p, cached);
+                IRoxieServerQueryPacket *rsqp = createRoxieServerQueryPacket(p);
                 if (deferredStart)
                     rsqp->setDelayed(true);
                 rsqp->setSequence(sentSequence++);
@@ -4323,8 +4116,7 @@ public:
                 }
                 if (!deferredStart)
                 {
-                    if (!cached)
-                        ROQ->sendPacket(p, activity.queryLogCtx());
+                    ROQ->sendPacket(p, activity.queryLogCtx());
                     sentsome.signal();
                 }
             }
@@ -4333,14 +4125,10 @@ public:
                 // Care is needed here. If I send the packet before I add to the pending there is a danger that I'll get results that I discard 
                 // Need to add first, then send
                 unsigned i;
-                bool allCached = true;
                 for (i = 1; i <= numChannels; i++)
                 {
                     IRoxieQueryPacket *q = p->clonePacket(i);
-                    bool thisChannelCached;
-                    IRoxieServerQueryPacket *rsqp = createRoxieServerQueryPacket(q, thisChannelCached);
-                    if (!thisChannelCached)
-                        allCached = false;
+                    IRoxieServerQueryPacket *rsqp = createRoxieServerQueryPacket(q);
                     rsqp->setSequence(sentSequence++);
                     if (deferredStart)
                     {
@@ -4353,7 +4141,7 @@ public:
                     if (!deferredStart)
                             sentsome.signal();
                 }
-                if (!allCached && !deferredStart)
+                if (!deferredStart)
                     ROQ->sendPacket(p, activity.queryLogCtx());
                 buffers[0]->signal(); // since replies won't come back on that channel...
                 p->Release();
@@ -5045,12 +4833,6 @@ public:
                                 ROQ->sendPacket(resend, activity.queryLogCtx());
                                 sentsome.signal();
                             }
-                            // Note that we don't attempt to cache results that have continuation records - too tricky !
-                        }
-                        else
-                        {
-                            if (serverSideCache)
-                                serverSideCache->noteCachedResult(original, mr);
                         }
                         unsigned channel = header.channel;
                         {
@@ -23100,8 +22882,6 @@ public:
     unsigned maxSeekLookahead;
     Owned<const IResolvedFile> indexfile;
 
-    CRoxieServerSideCache *cache;
-
     CRoxieServerBaseIndexActivityFactory(unsigned _id, unsigned _subgraphId, IQueryFactory &_queryFactory, HelperFactory *_helperFactory, ThorActivityKind _kind, IPropertyTree &_graphNode, const RemoteActivityId &_remoteId)
         : CRoxieServerActivityFactory(_id, _subgraphId, _queryFactory, _helperFactory, _kind, _graphNode), remoteId(_remoteId)
     {
@@ -23134,16 +22914,9 @@ public:
             if (thisBase->numParts()==1 && !thisBase->queryPart(0)->isTopLevelKey() && !_queryFactory.queryOptions().disableLocalOptimizations)
                 isSimple = true;
         }
-        int cacheSize = _graphNode.getPropInt("hint[@name='cachehits']/@value", serverSideCacheSize);
-        cache = cacheSize ? new CRoxieServerSideCache(cacheSize) : NULL;
         maxSeekLookahead = _graphNode.getPropInt("hint[@name='maxseeklookahead']/@value", 0);
     }
 
-    ~CRoxieServerBaseIndexActivityFactory()
-    {
-        delete cache;
-    }
-
     virtual void getXrefInfo(IPropertyTree &reply, const IRoxieContextLogger &logctx) const
     {
         if (indexfile)
@@ -23166,11 +22939,6 @@ public:
         throw MakeStringException(ROXIE_SET_INPUT, "Internal error: setInput() should not be called for indexread activity");
     }
 
-    virtual IRoxieServerSideCache *queryServerSideCache() const
-    {
-        return cache;
-    }
-
     virtual const StatisticsMapping &queryStatsMapping() const
     {
         return indexStatistics;

+ 0 - 9
roxie/ccd/ccdserver.hpp

@@ -137,12 +137,6 @@ interface IRoxieServerErrorHandler
     virtual const void *createLimitFailRow(bool isKeyed) = 0;
 };
 
-interface IRoxieServerSideCache
-{
-    virtual IRoxieServerQueryPacket *findCachedResult(const IRoxieContextLogger &logctx, IRoxieQueryPacket *p) const = 0;
-    virtual void noteCachedResult(IRoxieServerQueryPacket *out, IMessageResult *in) = 0;
-};
-
 interface IRoxieServerActivityFactory;
 interface IRoxiePackage;
 
@@ -178,8 +172,6 @@ interface IRoxieServerActivity : extends IActivityBase
     virtual void resetOutputsUsed() = 0;        // use for adjusting correct number of uses for a splitter
     virtual void noteOutputUsed() = 0;
     virtual bool isPassThrough() = 0;
-// Roxie server-side caching
-    virtual IRoxieServerSideCache *queryServerSideCache() const = 0;
 // Dynamic file support
     virtual const IResolvedFile *resolveLFN(const char *fileName, bool isOpt, bool isPrivilegedUser) = 0;
     virtual const IResolvedFile *queryVarFileInfo() const = 0;
@@ -221,7 +213,6 @@ interface IRoxieServerActivityFactory : extends IActivityFactory
     virtual IActivityGraph * createChildGraph(IRoxieAgentContext * ctx, IHThorArg *colocalArg, unsigned childId, IRoxieServerActivity *parentActivity, IProbeManager * _probeManager, const IRoxieContextLogger &_logctx) const = 0;
     virtual unsigned __int64 queryLocalTimeNs() const = 0;
     virtual bool isGraphInvariant() const = 0;
-    virtual IRoxieServerSideCache *queryServerSideCache() const = 0;
     virtual unsigned numInputs() const = 0;
     virtual const StatisticsMapping &queryStatsMapping() const = 0;
     virtual bool isInputOrdered(bool consumerOrdered, unsigned idx) const = 0;

+ 0 - 5
roxie/ccd/ccdstate.cpp

@@ -2803,11 +2803,6 @@ private:
                     traceLevel = MAXTRACELEVEL;
                 topology->setPropInt("@traceLevel", traceLevel);
             }
-            else if (stricmp(queryName, "control:traceServerSideCache")==0)
-            {
-                traceServerSideCache = control->getPropBool("@val", true);
-                topology->setPropInt("@traceServerSideCache", traceServerSideCache);
-            }
             else if (stricmp(queryName, "control:traceSmartStepping")==0)
             {
                 traceSmartStepping = control->getPropBool("@val", true);