Skip to content
Snippets Groups Projects
Commit 86802cc6 authored by Peter Rotich's avatar Peter Rotich
Browse files

Merge pull request #1424 from greezybacon/issue/cluster-deadlocks


Rollback to auto commit, except for sequence  iteration

Reviewed-By: default avatarPeter Rotich <peter@osticket.com>
parents bae22151 d1581026
No related branches found
No related tags found
No related merge requests found
......@@ -151,6 +151,9 @@ class Sequence extends VerySimpleModel {
* and assured to be session-wise atomic before the value is returned.
*/
function __next($digits=false) {
// Ensure this block is executed in a single transaction
db_autocommit(false);
// Lock the database object -- this is important to handle concurrent
// requests for new numbers
static::objects()->filter(array('id'=>$this->id))->lock()->one();
......@@ -161,6 +164,8 @@ class Sequence extends VerySimpleModel {
$this->updated = SqlFunction::NOW();
$this->save();
db_autocommit(true);
return $next;
}
......
......@@ -76,18 +76,7 @@ function db_connect($host, $user, $passwd, $options = array()) {
@db_set_variable('sql_mode', '');
// Start a new transaction -- for performance. Transactions are always
// committed at shutdown (below)
$__db->autocommit(false);
// Auto commit the transaction at shutdown and re-enable statement-level
// autocommit
register_shutdown_function(function() {
global $__db, $err;
if (!$__db->commit())
$err = 'Unable to save changes to database';
$__db->autocommit(true);
});
$__db->autocommit(true);
// Use connection timing to seed the random number generator
Misc::__rand_seed((microtime(true) - $start) * 1000000);
......@@ -95,6 +84,12 @@ function db_connect($host, $user, $passwd, $options = array()) {
return $__db;
}
function db_autocommit($enable=true) {
global $__db;
return $__db->autocommit($enable);
}
function db_close() {
global $__db;
return @$__db->close();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment