Bug #112391 Faulty ndbassert in DblqhMain.cpp
Submitted: 20 Sep 2023 9:18 Modified: 20 Sep 2023 19:37
Reporter: Mikael Ronström Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Cluster: Cluster (NDB) storage engine Severity:S3 (Non-critical)
Version:8.0.34 OS:Any
Assigned to: CPU Architecture:Any

[20 Sep 2023 9:18] Mikael Ronström
Description:
The ndbassert:
    ndbassert(useStat.m_scanFragReqCount > 0);

is faulty

The m_scanFragReqCount is a union with m_fragCopyRowIns that tracks
the number of rows inserted during the Copy fragment process.
This variable is set to 0 by the signal COPY_ACTIVEREQ after completing
the copy fragment process for the fragment. Coming here we should have
increased m_scanFragReqCount after receiving SCAN_FRAGREQ, however a
COPY_ACTIVEREQ arriving after SCAN_FRAGREQ will set this variable to 0.

Normally this behaviour would never happen since COPY_ACTIVEREQ is
sent long before the fragment is allowed to be used for scans.
However scans on ordered index actually uses the table distribution
of the primary table. This table is usually handled before the
ordered index table. Thus COPY_ACTIVEREQ on an ordered index table
could see a value of 0 in the execution of a SCAN_NEXTREQ or
CONTINUEB signal. But for the base table it should never be 0.

How to repeat:
daily-basic--10 in Autotest

Suggested fix:
#if defined(VM_TRACE) || defined(ERROR_INSERT)
    TablerecPtr tablePtr;
    tablePtr.i = regTcPtr->tableref;
    ptrCheckGuard(tablePtr, ctabrecFileSize, tablerec);
    ndbassert(useStat.m_scanFragReqCount > 0 ||
              DictTabInfo::isOrderedIndex(tablePtr.p->tableType));
#endif

The faulty ndbassert is found in 3 places in DblqhMain.cpp
[20 Sep 2023 19:37] MySQL Verification Team
Hi Mikael,

Thanks for the report and explanation

all best