Open george-lorch opened 5 years ago
email discussions with @lth and some additional testing tells us that the logic here https://github.com/facebook/mysql-5.6/blob/fb-mysql-5.6.35/storage/rocksdb/ha_rocksdb.cc#L11540-LL11541 is slightly off. We get into a situation where new_val is equal to ullong_max, thus new_val + 1 rolls us over to 0, which is what gets stored as the new auto_inc value for the table and then eventually leads to the assertion on the next time through get_auto_increment.
A simple change to this logic solves the problem and prevents us from either underflowing or from giving out any more values. We change:
while (!auto_incr.compare_exchange_weak(last_val, std::min(new_val + 1, max_val)));
to
while (!auto_incr.compare_exchange_weak(last_val, std::min(new_val, max_val - 1) + 1));
The following. simple test case illustrates the issue:
The first insert after the "SET @@session.auto_increment_increment=2;" will get this expected error
The next insert hits the assertion with the following call stack: