Description:
When multiple processes or threads in parallel are doing the same ordered scan with exclusive lock and update the retrieved records, sometimes the scan can skip some number of records and the skipped records are not updated as the result.
How to repeat:
Please see the attached test program. The cluster configuration file config.ini is also provided. The program was tested on a 64-bit Linux and on a HP-UX 11.11 systems. In both cases it reproduced the problem.
The program creates and populates the table mytablename in test_db_1 database, then creates two threads, passing them two different Ndb objects representing two different connections to the test_db_1 database. The threads in parallel repeat the following operations:
1. Start a transaction;
2. Define an NdbIndexScanOperation for the primary key of the mytablename
table;
3. Call readTuples with NdbOperation::LM_Exclusive parameter to request exclusive locks to be used, and with NdbScanOperation::SF_OrderBy option to request the result set to be ordered;
4. Define the attributes to be retrieved with getValues;
5. Execute the transaction;
6. Call NdbIndexScanOperation::nextResult(true);
7. Create a separate update transaction;
8. In a cycle, for each record retrieved with the nextResult(true), do steps 8.1 and 8.2:
8.1. Create an update operation using NdbIndexScanOperation::updateCurrentTuple(updateTrans). This call requests the record to be taken over to the update transaction;
8.2. Set a value of an attribute in the update operation;
9. Execute the update transaction;
10. Close the update transaction;
11. Close the NdbIndexScanOperation;
12. Close the transaction used for the scan.
The program shows that approximately every 4-th of the scans start not from the first record, as every scan is supposed to start, but from the 124-th (on HP-UX) or 125-th (on 64-bit Linux) record.
The example output of the program is:
64-bit Linux:
Populating the table
Thread: 1084578144 - updating records 0 through 123
Thread: 1084578144 - updating records 0 through 123
Thread: 1084578144 - updating records 0 through 119
Thread: 1095068000 - updating records 124 through 241
Thread: 1084578144 - updating records 0 through 123
Thread: 1084578144 - updating records 0 through 123
Thread: 1084578144 - updating records 0 through 119
Thread: 1095068000 - updating records 124 through 241
Thread: 1084578144 - updating records 0 through 123
Thread: 1084578144 - updating records 0 through 123
Thread: 1084578144 - updating records 0 through 119
Thread: 1095068000 - updating records 124 through 241
Thread: 1084578144 - updating records 0 through 123
Thread: 1084578144 - updating records 0 through 123
Thread: 1084578144 - updating records 0 through 119
Thread: 1095068000 - updating records 124 through 241
Thread: 1084578144 - updating records 0 through 123
Thread: 1084578144 - updating records 0 through 123
Thread: 1084578144 - updating records 0 through 119
Thread: 1095068000 - updating records 124 through 241
Thread: 1084578144 - updating records 0 through 123
Thread: 1084578144 - updating records 0 through 123
Thread: 1084578144 - updating records 0 through 119
Thread: 1095068000 - updating records 124 through 241
Thread: 1084578144 - updating records 0 through 123
Thread: 1084578144 - updating records 0 through 123
Thread: 1084578144 - updating records 0 through 119
Thread: 1095068000 - updating records 124 through 241
Thread: 1084578144 - updating records 0 through 123
Thread: 1084578144 - updating records 0 through 123
Thread: 1084578144 - updating records 0 through 119
Thread: 1095068000 - updating records 124 through 241
Thread: 1084578144 - updating records 0 through 123
Thread: 1084578144 - updating records 0 through 123
Thread: 1084578144 - updating records 0 through 119
Thread: 1095068000 - updating records 124 through 241
Thread: 1084578144 - updating records 0 through 123
Thread: 1084578144 - updating records 0 through 123
Thread: 1084578144 - updating records 0 through 119
Thread: 1095068000 - updating records 124 through 241
Thread: 1084578144 - updating records 0 through 123
Thread: 1095068000 - updating records 124 through 241
Thread: 1084578144 - updating records 0 through 119
Thread: 1095068000 - updating records 0 through 123
Thread: 1095068000 - updating records 0 through 123
Thread: 1095068000 - updating records 0 through 119
...
HP-UX 11.11:
Populating the table
Thread: 7 - updating records 0 through 122
Thread: 7 - updating records 0 through 122
Thread: 7 - updating records 0 through 118
Thread: 8 - updating records 123 through 234
Thread: 7 - updating records 0 through 122
Thread: 7 - updating records 0 through 122
Thread: 7 - updating records 0 through 118
Thread: 8 - updating records 123 through 234
Thread: 7 - updating records 0 through 122
Thread: 7 - updating records 0 through 122
Thread: 7 - updating records 0 through 118
Thread: 8 - updating records 123 through 234
Thread: 7 - updating records 0 through 122
Thread: 7 - updating records 0 through 122
Thread: 7 - updating records 0 through 118
Thread: 8 - updating records 123 through 234
Thread: 7 - updating records 0 through 122
Thread: 7 - updating records 0 through 118
Thread: 8 - updating records 123 through 234
Thread: 8 - updating records 0 through 122
Thread: 8 - updating records 0 through 118
Thread: 7 - updating records 123 through 234
Thread: 8 - updating records 0 through 122
Thread: 8 - updating records 0 through 122
...