cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cassandra-node.apache-extras....@codespot.com
Subject [cassandra-node] 2 new revisions pushed by tomaz.muraus on 2011-11-11 21:10 GMT
Date Fri, 11 Nov 2011 21:11:24 GMT
2 new revisions:

Revision: 13d6ce57e0ae
Author:   Tomaz Muraus <tomaz@tomaz.me>
Date:     Fri Nov 11 11:26:49 2011
Log:      Use async for login, learn, use.
http://code.google.com/a/apache-extras.org/p/cassandra-node/source/detail?r=13d6ce57e0ae

Revision: 9a4cff4f04a8
Author:   Tomaz Muraus <tomaz@tomaz.me>
Date:     Fri Nov 11 13:07:28 2011
Log:      Use async in PooledConnection.execute.
http://code.google.com/a/apache-extras.org/p/cassandra-node/source/detail?r=9a4cff4f04a8

==============================================================================
Revision: 13d6ce57e0ae
Author:   Tomaz Muraus <tomaz@tomaz.me>
Date:     Fri Nov 11 11:26:49 2011
Log:      Use async for login, learn, use.

http://code.google.com/a/apache-extras.org/p/cassandra-node/source/detail?r=13d6ce57e0ae

Modified:
  /lib/driver.js

=======================================
--- /lib/driver.js	Fri Nov 11 08:57:42 2011
+++ /lib/driver.js	Fri Nov 11 11:26:49 2011
@@ -26,6 +26,7 @@
  var EventEmitter = require('events').EventEmitter;

  var thrift = require('thrift');
+var async = require('async');
  var Cassandra = require('./gen-nodejs/Cassandra');
  var ttypes = require('./gen-nodejs/cassandra_types');

@@ -402,30 +403,19 @@
          cb(err);
        });
      };
-
-    // put it all together, checking for errors along the way.
-    login(function(loginErr) {
-      if (loginErr) {
-        callback(loginErr);
+
+    async.series([
+      login,
+      learn,
+      use
+    ],
+
+    function(err) {
+      if (err) {
          self.close();
-      } else {
-        learn(function(learnErr) {
-          if (learnErr) {
-            callback(learnErr);
-            self.close();
-          } else {
-            use(function(useErr) {
-              if (useErr) {
-                callback(useErr);
-                self.close();
-              } else {
-                // this connection is finally ready to use.
-                callback(null);
-              }
-            });
-          }
-        });
-      }
+      }
+
+      callback(err);
      });

    });

==============================================================================
Revision: 9a4cff4f04a8
Author:   Tomaz Muraus <tomaz@tomaz.me>
Date:     Fri Nov 11 13:07:28 2011
Log:      Use async in PooledConnection.execute.
http://code.google.com/a/apache-extras.org/p/cassandra-node/source/detail?r=9a4cff4f04a8

Modified:
  /lib/driver.js

=======================================
--- /lib/driver.js	Fri Nov 11 11:26:49 2011
+++ /lib/driver.js	Fri Nov 11 13:07:28 2011
@@ -278,47 +278,59 @@
  PooledConnection.prototype.execute = function(query, args, callback) {
    var self = this;
    var seen = false;
-
+
    var exe = function(errback) {
-    self.pool.acquire(function(err, conn) {
-      if (err) {
-        log.err("Unable to acquire connection from the pool: " +  
err.toString());
-        callback(amendError(err));
-      } else {
+    async.waterfall([
+      function acquireConnFromPool(callback) {
+        self.pool.acquire(function(err, conn) {
+          callback(err, conn);
+        });
+      },
+
+      function executeQuery(conn, callback) {
          conn.execute(query, args, function(err, res) {
-          if (err) {
-            if (contains(appExceptions, err.name)) {
-              self.pool.release(conn);
-              callback(err, null);
-            } else {
-              if (!seen) {
-                errback();
-              } else {
-                self.pool.release(conn);
-                callback(err, null);
-              }
-            }
-          } else {
-            self.pool.release(conn);
+          callback(err, res, conn);
+        });
+      }
+    ],
+
+    function(err, res, conn) {
+      if (conn) {
+        self.pool.release(conn);
+      }
+
+      if (err) {
+        if (err.hasOwnProperty('name') && contains(appExceptions,  
err.name)) {
+          callback(err, null);
+        }
+        else {
+          if (!seen) {
+            errback();
+          }
+          else {
+            err = amendError(err);
              callback(err, res);
            }
-        });
+        }
+      }
+      else {
+        callback(err, res);
        }
      });
    };
-
+
    var retry = function() {
      seen = true;
      exe(retry);
    };
-
+
    exe(retry);
  };

  /**
   * Signal the pool to shutdown.  Once called, no new requests (read:  
execute())
   * can be made. When all pending requests have terminated, the callback is  
run.
- *
+ *
   * @param callback called when the pool is fully shutdown
   */
  PooledConnection.prototype.shutdown = function(callback) {

Mime
View raw message