Skip to content
Snippets Groups Projects
Commit 2f8f948a authored by Austin King's avatar Austin King
Browse files

Merge pull request #1633 from mozilla/issue1608

db.ping() must use the same application level query timing and reconnect...
parents c243137f cf283895
No related branches found
No related tags found
No related merge requests found
......@@ -39,14 +39,15 @@ exports.createClient = function(options) {
logger.warn("database connection down: " + e.toString());
});
},
ping: function(cb) {
if (stalled) {
process.nextTick(function() {
cb("database is intentionally stalled");
});
} else {
this.realClient.ping(cb);
}
ping: function(client_cb) {
// ping queries are added to the front of the pending work queue. they are
// a priority, as they are used by load balancers that want to know the health
// of the system.
queryQueue.unshift({
ping: true,
cb: client_cb
});
this._runNextQuery();
},
_runNextQuery: function() {
var self = this;
......@@ -93,25 +94,41 @@ exports.createClient = function(options) {
}
}, config.get('database.max_query_time_ms'));
this.realClient.query(work.query, work.args, function(err, r) {
// if we want to simulate a "stalled" mysql connection, we simply
// ignore the results from a query.
if (stalled) return;
if (work.ping) {
this.realClient.ping(function(err) {
if (stalled) {
return invokeCallback(work.cb, "database is intentionally stalled");
}
clearTimeout(slowQueryTimer);
slowQueryTimer = null;
consecutiveFailures = 0;
clearTimeout(slowQueryTimer);
slowQueryTimer = null;
consecutiveFailures = 0;
// report query time for all queries via statsd
var reqTime = new Date - work.startTime;
statsd.timing('query_time', reqTime);
invokeCallback(work.cb, err);
// report failed queries via statsd
if (err) statsd.increment('failed_query');
self._runNextQuery();
});
} else {
this.realClient.query(work.query, work.args, function(err, r) {
// if we want to simulate a "stalled" mysql connection, we simply
// ignore the results from a query.
if (stalled) return;
invokeCallback(work.cb, err, r);
self._runNextQuery();
});
clearTimeout(slowQueryTimer);
slowQueryTimer = null;
consecutiveFailures = 0;
// report query time for all queries via statsd
var reqTime = new Date - work.startTime;
statsd.timing('query_time', reqTime);
// report failed queries via statsd
if (err) statsd.increment('failed_query');
invokeCallback(work.cb, err, r);
self._runNextQuery();
});
}
},
query: function() {
var client_cb;
......
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