Repository: rucio/rucio

Issue:
necromancer do not work if there is more than 1 thread
```
2020-05-19 13:58:12,391 22882   CRITICAL        Thread [2/3] : Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/rucio/daemons/badreplicas/necromancer.py", line 84, in necromancer
    replicas = list_bad_replicas(limit=bulk, thread=heart_beat['assign_thread'], total_threads=heart_beat['nr_threads'])
  File "/usr/lib/python2.7/site-packages/retrying.py", line 49, in wrapped_f
    return Retrying(*dargs, **dkw).call(f, *args, **kw)
  File "/usr/lib/python2.7/site-packages/retrying.py", line 206, in call
    return attempt.get(self._wrap_exception)
  File "/usr/lib/python2.7/site-packages/retrying.py", line 247, in get
    six.reraise(self.value[0], self.value[1], self.value[2])
  File "/usr/lib/python2.7/site-packages/retrying.py", line 200, in call
    attempt = Attempt(fn(*args, **kwargs), attempt_number, False)
  File "/usr/lib/python2.7/site-packages/rucio/db/sqla/session.py", line 290, in new_funct
    raise DatabaseException(str(error))
DatabaseException: Database exception.
Details: (cx_Oracle.DatabaseError) ORA-00918: column ambiguously defined
[SQL: SELECT atlas_rucio_replicas_sco_1, atlas_rucio_replicas_nam_2, atlas_rucio_replicas_rse_3 
FROM (SELECT /*+ + index(replicas REPLICAS_STATE_IDX) */ atlas_rucio.replicas.scope AS atlas_rucio_replicas_sco_1, atlas_rucio.replicas.name AS atlas_rucio_replicas_nam_2, atlas_rucio.replicas.rse_id AS atlas_rucio_replicas_rse_3 
FROM atlas_rucio.replicas JOIN atlas_rucio.dids ON atlas_rucio.dids.scope = atlas_rucio.replicas.scope AND atlas_rucio.dids.name = atlas_rucio.replicas.name 
WHERE CASE WHEN (atlas_rucio.replicas.state != 'A') THEN atlas_rucio.replicas.rse_id END IS NOT NULL AND atlas_rucio.replicas.state = :state_1 AND atlas_rucio.replicas.rse_id != :rse_id_1 AND atlas_rucio.replicas.rse_id != :rse_id_2 AND atlas_rucio.replicas.rse_id != :rse_id_3 AND ORA_HASH(name, :total_threads) = :th
read_id AND atlas_rucio.dids.availability != :availability_1) 
WHERE ROWNUM <= :param_1]
[parameters: {'thread_id': 2, u'rse_id_3': <read-only buffer for 0x7f9131874848, size -1, offset 0 at 0x7f9130094770>, u'rse_id_2': <read-only buffer for 0x7f9130090148, size -1, offset 0 at 0x7f9130094970>, u'rse_id_1': <read-only buffer for 0x7f91300901f0, size -1, offset 0 at 0x7f91300947b0>, u'param_1': 1000, 'to
tal_threads': 2, u'state_1': 'D', u'availability_1': 'L'}]
(Background on this error at: http://sqlalche.me/e/4xp6)
```





Discussion:

Resolving patch:
diff --git a/lib/rucio/core/replica.py b/lib/rucio/core/replica.py
--- a/lib/rucio/core/replica.py
+++ b/lib/rucio/core/replica.py
@@ -490,7 +490,7 @@ def list_bad_replicas(limit=10000, thread=None, total_threads=None, session=None
                               models.RSEFileAssociation.rse_id).\
             filter(models.RSEFileAssociation.state == ReplicaState.BAD)
 
-    query = filter_thread_work(session=session, query=query, total_threads=total_threads, thread_id=thread, hash_variable='name')
+    query = filter_thread_work(session=session, query=query, total_threads=total_threads, thread_id=thread, hash_variable='%sreplicas.name' % (schema_dot))
     query = query.join(models.DataIdentifier,
                        and_(models.DataIdentifier.scope == models.RSEFileAssociation.scope,
                             models.DataIdentifier.name == models.RSEFileAssociation.name)).\


Test patch: