|
2 | 2 |
|
3 | 3 | # python std lib |
4 | 4 | import sys |
| 5 | +import logging |
5 | 6 |
|
6 | 7 | # rediscluster imports |
7 | 8 | from .client import RedisCluster |
|
15 | 16 | from redis.exceptions import ConnectionError, RedisError, TimeoutError |
16 | 17 | from redis._compat import imap, unicode |
17 | 18 |
|
| 19 | +from gevent import monkey; monkey.patch_all() |
| 20 | +import gevent |
| 21 | + |
| 22 | +log = logging.getLogger(__name__) |
18 | 23 |
|
19 | 24 | ERRORS_ALLOW_RETRY = (ConnectionError, TimeoutError, MovedError, AskError, TryAgainError) |
20 | 25 |
|
@@ -174,6 +179,11 @@ def send_cluster_commands(self, stack, raise_on_error=True, allow_redirections=T |
174 | 179 | # If it fails the configured number of times then raise exception back to caller of this method |
175 | 180 | raise ClusterDownError("CLUSTERDOWN error. Unable to rebuild the cluster") |
176 | 181 |
|
| 182 | + def _execute_node_commands(self, n): |
| 183 | + n.write() |
| 184 | + |
| 185 | + n.read() |
| 186 | + |
177 | 187 | def _send_cluster_commands(self, stack, raise_on_error=True, allow_redirections=True): |
178 | 188 | """ |
179 | 189 | Send a bunch of cluster commands to the redis cluster. |
@@ -227,11 +237,11 @@ def _send_cluster_commands(self, stack, raise_on_error=True, allow_redirections= |
227 | 237 | # so that we can read them all in parallel as they come back. |
228 | 238 | # we dont' multiplex on the sockets as they come available, but that shouldn't make too much difference. |
229 | 239 | node_commands = nodes.values() |
| 240 | + events = [] |
230 | 241 | for n in node_commands: |
231 | | - n.write() |
| 242 | + events.append(gevent.spawn(self._execute_node_commands, n)) |
232 | 243 |
|
233 | | - for n in node_commands: |
234 | | - n.read() |
| 244 | + gevent.joinall(events) |
235 | 245 |
|
236 | 246 | # release all of the redis connections we allocated earlier back into the connection pool. |
237 | 247 | # we used to do this step as part of a try/finally block, but it is really dangerous to |
@@ -269,6 +279,8 @@ def _send_cluster_commands(self, stack, raise_on_error=True, allow_redirections= |
269 | 279 | # If a lot of commands have failed, we'll be setting the |
270 | 280 | # flag to rebuild the slots table from scratch. So MOVED errors should |
271 | 281 | # correct themselves fairly quickly. |
| 282 | + |
| 283 | + log.debug("pipeline has failed commands: {}".format(attempt)) |
272 | 284 | self.connection_pool.nodes.increment_reinitialize_counter(len(attempt)) |
273 | 285 | for c in attempt: |
274 | 286 | try: |
|
0 commit comments