Bug #27370 Potential inconsistent blob reads for ReadCommitted reads
Submitted: 22 Mar 2007 12:15 Modified: 30 Apr 2007 9:40
Reporter: Kristian Nielsen Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Cluster: NDB API Severity:S2 (Serious)
Version:5.0-bk, 5.1-bk OS:Any (Any)
Assigned to: Kristian Nielsen CPU Architecture:Any

[22 Mar 2007 12:15] Kristian Nielsen
Description:
For blob reads on operations with lock mode LM_CommittedRead, the NdbBlob code is
supposed to upgrade the lock mode to LM_Read. This to avoid inconstistent blob
reads, where half the read see data committed by another transaction, and the
other half does not.

However, the code does not work. It changes the lock mode, but at that point,
the NdbOperation::readTuple() method has already computed these fields from the
old lock mode:

    NdbTransaction::theSimpleState
    NdbOperation::theSimpleIndicator
    NdbOperation::theDirtyIndicator

Since these are not recomputed, the old lock mode is the one that is send in the
signal to the kernel. The situation is similar for
NdbScanOperation::readTuples() and NdbIndexScanOperation::readTuples().

How to repeat:
Source code inspection, or check a signal trace from testBlobs.

Suggested fix:
Will commit a patch.
[26 Mar 2007 10:18] Kristian Nielsen
I think this bug only affects NDB API programs, as the mysqld ha_ndbcluster.cc
seems to set the lock mode to LM_Read itself for blob access:

int ha_ndbcluster::get_ndb_lock_type(enum thr_lock_type type)
{
  if (type >= TL_WRITE_ALLOW_WRITE)
    return(NdbOperation::LM_Exclusive);
  else if (type ==  TL_READ_WITH_SHARED_LOCKS ||
	   uses_blob_value(m_retrieve_all_fields))
    return(NdbOperation::LM_Read);
  else
    return(NdbOperation::LM_CommittedRead);
}

So only NDB API programs that read blobs with non-default LM_CommittedRead would  be affected.
[28 Mar 2007 9:33] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/23125

ChangeSet@1.2417, 2007-03-28 11:29:13+02:00, knielsen@ymer.(none) +7 -0
  BUG#27370: Potential inconsistent blob reads for ReadCommitted reads.
  
  The old blob implementation had code that attempted to upgrade the lock mode for
  LM_CommittedRead operations, but it did not work properly as it did not recompute
  the operation flags properly.
  
  As a consequence, reading a blob with LM_CommittedRead could return inconsistent
  data, with different part of the read data being from different commits done by
  other transactions.
  
  The fix is to correctly recompute all necessary flags when upgrading lock mode.
[24 Apr 2007 6:19] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/25224

ChangeSet@1.2417, 2007-04-24 08:15:31+02:00, knielsen@ymer.(none) +8 -0
  BUG#27370: Potential inconsistent blob reads for ReadCommitted reads.
  
  The old blob implementation had code that attempted to upgrade the lock mode for
  LM_CommittedRead operations, but it did not work properly as it did not recompute
  the operation flags.
  
  As a consequence, reading a blob with LM_CommittedRead could return inconsistent
  data, with different part of the read data being from different commits done by
  other transactions.
  
  The fix is to correctly recompute all necessary flags when upgrading lock mode.
[25 Apr 2007 7:30] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/25370

ChangeSet@1.2401, 2007-04-25 09:30:15+02:00, knielsen@ymer.(none) +8 -0
  BUG#27370: Potential inconsistent blob reads for ReadCommitted reads.
  
  The old blob implementation had code that attempted to upgrade the lock mode for
  LM_CommittedRead operations, but it did not work properly as it did not recompute
  the operation flags.
  
  As a consequence, reading a blob with LM_CommittedRead could return inconsistent
  data, with different part of the read data being from different commits done by
  other transactions.
  
  The fix is to correctly recompute all necessary flags when upgrading lock mode.
[25 Apr 2007 19:11] Kristian Nielsen
Pushed to mysql-5.0-ndb and mysql-5.1-new-ndb.
[28 Apr 2007 19:35] Bugs System
Pushed into 5.1.18-beta
[28 Apr 2007 19:36] Bugs System
Pushed into 5.0.42
[30 Apr 2007 9:40] Jon Stephens
Thank you for your bug report. This issue has been committed to our source repository of that product and will be incorporated into the next release.

If necessary, you can access the source repository and build the latest available version, including the bug fix. More information about accessing the source trees is available at

    http://dev.mysql.com/doc/en/installing-source.html

Documented bugfix in 5.0.42 and 5.1.18 changelogs.