863 except Exception: |
863 except Exception: |
864 assert session.cnxset, 'session has no connections set' |
864 assert session.cnxset, 'session has no connections set' |
865 self.exception('failed to query entities table for eid %s', eid) |
865 self.exception('failed to query entities table for eid %s', eid) |
866 raise UnknownEid(eid) |
866 raise UnknownEid(eid) |
867 |
867 |
868 def eid_type_source(self, session, eid): |
868 def eid_type_source(self, session, eid): # pylint: disable=E0202 |
869 """return a tuple (type, source, extid) for the entity with id <eid>""" |
869 """return a tuple (type, source, extid) for the entity with id <eid>""" |
870 sql = 'SELECT type, source, extid, asource FROM entities WHERE eid=%s' % eid |
870 sql = 'SELECT type, source, extid, asource FROM entities WHERE eid=%s' % eid |
871 res = self._eid_type_source(session, eid, sql) |
871 res = self._eid_type_source(session, eid, sql) |
872 if res[-2] is not None: |
872 if res[-2] is not None: |
873 if not isinstance(res, list): |
873 if not isinstance(res, list): |
922 for sql in self.dbhelper.sqls_increment_sequence('entities_id_seq'): |
922 for sql in self.dbhelper.sqls_increment_sequence('entities_id_seq'): |
923 cursor = self.doexec(session, sql) |
923 cursor = self.doexec(session, sql) |
924 return cursor.fetchone()[0] |
924 return cursor.fetchone()[0] |
925 |
925 |
926 |
926 |
927 def create_eid(self, session): |
927 def create_eid(self, session): # pylint: disable=E0202 |
928 # lock needed to prevent 'Connection is busy with results for another |
928 # lock needed to prevent 'Connection is busy with results for another |
929 # command (0)' errors with SQLServer |
929 # command (0)' errors with SQLServer |
930 with self._eid_cnx_lock: |
930 with self._eid_cnx_lock: |
931 return self._create_eid() |
931 return self._create_eid() # pylint: disable=E1102 |
932 |
932 |
933 def _create_eid(self): |
933 def _create_eid(self): # pylint: disable=E0202 |
934 # internal function doing the eid creation without locking. |
934 # internal function doing the eid creation without locking. |
935 # needed for the recursive handling of disconnections (otherwise we |
935 # needed for the recursive handling of disconnections (otherwise we |
936 # deadlock on self._eid_cnx_lock |
936 # deadlock on self._eid_cnx_lock |
937 if self._eid_creation_cnx is None: |
937 if self._eid_creation_cnx is None: |
938 self._eid_creation_cnx = self.get_connection() |
938 self._eid_creation_cnx = self.get_connection() |
944 eid = cursor.fetchone()[0] |
944 eid = cursor.fetchone()[0] |
945 except (self.OperationalError, self.InterfaceError): |
945 except (self.OperationalError, self.InterfaceError): |
946 # FIXME: better detection of deconnection pb |
946 # FIXME: better detection of deconnection pb |
947 self.warning("trying to reconnect create eid connection") |
947 self.warning("trying to reconnect create eid connection") |
948 self._eid_creation_cnx = None |
948 self._eid_creation_cnx = None |
949 return self._create_eid() |
949 return self._create_eid() # pylint: disable=E1102 |
950 except (self.DbapiError,), exc: |
950 except (self.DbapiError,), exc: |
951 # We get this one with pyodbc and SQL Server when connection was reset |
951 # We get this one with pyodbc and SQL Server when connection was reset |
952 if exc.args[0] == '08S01': |
952 if exc.args[0] == '08S01': |
953 self.warning("trying to reconnect create eid connection") |
953 self.warning("trying to reconnect create eid connection") |
954 self._eid_creation_cnx = None |
954 self._eid_creation_cnx = None |
955 return self._create_eid() |
955 return self._create_eid() # pylint: disable=E1102 |
956 else: |
956 else: |
957 raise |
957 raise |
958 except Exception: # WTF? |
958 except Exception: # WTF? |
959 cnx.rollback() |
959 cnx.rollback() |
960 self._eid_creation_cnx = None |
960 self._eid_creation_cnx = None |