不要怂,就是干,撸起袖子干!

Commit 0d0e4c04 by Jan Aagaard Meier

only one write

1 parent 609295b0
Showing with 9 additions and 14 deletions
......@@ -29,8 +29,8 @@ module.exports = (function() {
writes = 0;
// Init configs with options from config if not present
for (var i in config.replication.reads) {
config.replication.reads[i] = Utils._.defaults(config.replication.reads[i], {
for (var i in config.replication.read) {
config.replication.read[i] = Utils._.defaults(config.replication.read[i], {
host: this.config.host,
port: this.config.port,
user: this.config.username,
......@@ -38,20 +38,18 @@ module.exports = (function() {
database: this.config.database
});
}
for (var j in config.replication.writes) {
config.replication.writes[j] = Utils._.defaults(config.replication.writes[j], {
config.replication.write = Utils._.defaults(config.replication.write, {
host: this.config.host,
port: this.config.port,
user: this.config.username,
password: this.config.password,
database: this.config.database
});
}
// I'll make my own pool, with blackjack and hookers!
this.pool = {
release: function (client) {
if (client.queryType == 'SELECT') {
if (client.queryType == 'read') {
return this.read.release(client);
} else {
return this.write.release(client);
......@@ -71,10 +69,11 @@ module.exports = (function() {
read: Pooling.Pool({
name: 'sequelize-read',
create: function (done) {
if (reads >= self.config.replication.reads.length) reads = 0;
var config = self.config.replication.reads[reads++];
if (reads >= self.config.replication.read.length) reads = 0;
var config = self.config.replication.read[reads++];
var connection = mysql.createConnection(config)
connection.queryType = 'read';
self.isConnecting = false
done(null, connection)
......@@ -89,10 +88,8 @@ module.exports = (function() {
write: Pooling.Pool({
name: 'sequelize-write',
create: function (done) {
if (writes >= self.config.replication.writes.length) writes = 0;
var config = self.config.replication.writes[writes++];
var connection = mysql.createConnection(config)
var connection = mysql.createConnection(self.config.replication.write)
connection.queryType = 'write';
self.isConnecting = false
done(null, connection)
......@@ -171,7 +168,6 @@ module.exports = (function() {
this.pool.acquire(function(err, client) {
if (err) return query.emit('error', err);
client.queryType = options.type;
query.client = client;
query.run(sql);
return;
......@@ -254,7 +250,6 @@ module.exports = (function() {
}
//we set the client here, asynchronously, when getting a pooled connection
//allowing the ConnectorManager.query method to remain synchronous
client.queryType = options.type;
queueItem.query.client = client
queueItem.client = client
execQueueItem.call(self, queueItem)
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!