def _connect(self): kwd = {'db' : self.db, 'user' : self.user} if self.passwd is not None: kwd['passwd'] = self.passwd if self.socket: kwd['unix_socket'] = os.path.expanduser(self.socket) logging.info('connecting to MySQL on the database %s with user %s', self.db, self.user) if self._wait < 0: timeout_at = None else: timeout_at = time.time() + self._wait while True: try: self.conn = MySQLdb.connect(**kwd) break except Exception: if timeout_at is not None and time.time() >= timeout_at: raise logging.exception('Connection to MySQL failed, retrying.') time.sleep(1) self._active = 0 conn = self.conn conn.autocommit(False) conn.query("SET SESSION group_concat_max_len = %u" % (2**32-1)) conn.set_sql_mode("TRADITIONAL,NO_ENGINE_SUBSTITUTION") conn.query("SHOW VARIABLES WHERE variable_name='max_allowed_packet'") r = conn.store_result() (name, value), = r.fetch_row(r.num_rows()) if int(value) < self._max_allowed_packet: raise DatabaseFailure("Global variable %r is too small." " Minimal value must be %uk." % (name, self._max_allowed_packet // 1024)) self._max_allowed_packet = int(value)
def tpc_abort(self, transaction): """Abort current transaction.""" txn_context = self._txn_container.pop(transaction) if txn_context is None: return ttid = txn_context['ttid'] p = Packets.AbortTransaction(ttid) getConnForNode = self.cp.getConnForNode # cancel transaction one all those nodes nodes = txn_context['involved_nodes'] nodes |= txn_context['checked_nodes'] for node in nodes: conn = getConnForNode(node) if conn is None: continue try: conn.notify(p) except: logging.exception('Exception in tpc_abort while notifying' 'storage node %r of abortion, ignoring.', conn) conn = self.master_conn if conn is not None: conn.notify(p) # We don't need to flush queue, as it won't be reused by future # transactions (deleted on next line & indexed by transaction object # instance). self.dispatcher.forget_queue(txn_context['queue'], flush_queue=False)
def run(self): try: self._run() except Exception: logging.exception('Pre-mortem data:') self.log() logging.flush() raise
def _getFinalTID(self, ttid): try: p = Packets.AskFinalTID(ttid) while 1: try: tid = self._askPrimary(p) break except ConnectionClosed: pass if tid == MAX_TID: while 1: for _, conn in self.cp.iterateForObject( ttid, readable=True): try: return self._askStorage(conn, p) except ConnectionClosed: pass self._getMasterConnection() elif tid: return tid except Exception: logging.exception("Failed to get final tid for TXN %s", dump(ttid))