Skip to content

Commit

Permalink
Merge pull request #18427 from ghalliday/issue31497
Browse files Browse the repository at this point in the history
HPCC-31497 Improve error details if unexpected node type read from index

Reviewed-By: Richard Chapman <[email protected]>
Merged-by: Gavin Halliday <[email protected]>
  • Loading branch information
ghalliday authored Mar 21, 2024
2 parents af503e8 + 2f3546f commit c58ede5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
11 changes: 9 additions & 2 deletions system/jhtree/jhtree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2441,7 +2441,7 @@ class CLazyKeyIndex : implements IKeyIndex, public CInterface
virtual IKeyIndex *queryPart(unsigned idx) { return idx ? NULL : this; }
virtual unsigned queryScans() { return realKey ? realKey->queryScans() : 0; }
virtual unsigned querySeeks() { return realKey ? realKey->querySeeks() : 0; }
virtual const char *queryFileName() { return keyfile.get(); }
virtual const char *queryFileName() const { return keyfile.get(); }
virtual offset_t queryBlobHead() { return checkOpen().queryBlobHead(); }
virtual void resetCounts() { if (realKey) realKey->resetCounts(); }
virtual offset_t queryLatestGetNodeOffset() const { return realKey ? realKey->queryLatestGetNodeOffset() : 0; }
Expand Down Expand Up @@ -2659,7 +2659,14 @@ const CJHTreeNode *CNodeCache::getNode(const INodeLoader *keyIndex, unsigned iD,
if (!ownedCacheEntry->isReady())
{
const CJHTreeNode *node = keyIndex->loadNode(&fetchCycles, pos);
assertex(type == node->getNodeType());
if (unlikely(type != node->getNodeType()))
{
//This should never happen, but if it does, report as much information as possible to diagnose the issue.
StringBuffer msg;
msg.appendf("Node type mismatch for node %s@%llx (expected %s, got %s)", keyIndex->queryFileName(), pos, cacheTypeText[type], cacheTypeText[node->getNodeType()]);
node->Release();
throwUnexpectedX(msg);
}

//Update the associated size of the entry in the hash table before setting isReady (never evicted until isReady is set)
curCache.noteReady(*node);
Expand Down
2 changes: 1 addition & 1 deletion system/jhtree/jhtree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ interface jhtree_decl IKeyIndex : public IKeyIndexBase
virtual unsigned querySeeks() = 0;
virtual size32_t keyedSize() = 0;
virtual bool hasPayload() = 0;
virtual const char *queryFileName() = 0;
virtual const char *queryFileName() const = 0;
virtual offset_t queryBlobHead() = 0;
virtual void resetCounts() = 0;
virtual offset_t queryLatestGetNodeOffset() const = 0;
Expand Down
7 changes: 5 additions & 2 deletions system/jhtree/jhtree.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ interface INodeLoader
virtual const CJHTreeNode *loadNode(cycle_t * fetchCycles, offset_t offset) const = 0;
virtual const CJHSearchNode *locateFirstLeafNode(IContextLogger *ctx) const = 0;
virtual const CJHSearchNode *locateLastLeafNode(IContextLogger *ctx) const = 0;
virtual const char *queryFileName() const = 0;
};

class jhtree_decl CKeyIndex : implements IKeyIndex, implements INodeLoader, public CInterface
Expand Down Expand Up @@ -161,6 +162,8 @@ public:
virtual const CJHSearchNode *locateLastLeafNode(IContextLogger *ctx) const override;

virtual void mergeStats(CRuntimeStatisticCollection & stats) const override {}

virtual const char *queryFileName() const = 0;
};

class jhtree_decl CMemKeyIndex : public CKeyIndex
Expand All @@ -170,7 +173,7 @@ private:
public:
CMemKeyIndex(unsigned _iD, IMemoryMappedFile *_io, const char *_name, bool _isTLK);

virtual const char *queryFileName() { return name.get(); }
virtual const char *queryFileName() const { return name.get(); }
virtual const IFileIO *queryFileIO() const override { return nullptr; }
// INodeLoader impl.
virtual const CJHTreeNode *loadNode(cycle_t * fetchCycles, offset_t offset) const override;
Expand All @@ -186,7 +189,7 @@ private:
public:
CDiskKeyIndex(unsigned _iD, IFileIO *_io, const char *_name, bool _isTLK);

virtual const char *queryFileName() { return name.get(); }
virtual const char *queryFileName() const { return name.get(); }
virtual const IFileIO *queryFileIO() const override { return io; }
// INodeLoader impl.
virtual const CJHTreeNode *loadNode(cycle_t * fetchCycles, offset_t offset) const override;
Expand Down

0 comments on commit c58ede5

Please sign in to comment.