Hi All,
Recently I had been assigned a bz where rescheduling a large number of
failed actions (~5000) would take a very very long time and in the end
would time out for me. Looking at the code it was basically looping
over a set of ServerActions and setting a couple of object attributes
depending on certain conditions, which meant it had to load every
object. I started to go about using a write-mode query in data source,
but there is a better way.
Hibernate update statements:
<query name="Action.rescheduleFailedActions">
<![CDATA[ update
com.redhat.rhn.domain.action.server.ServerAction sa
set sa.status = :queued,
sa.remainingTries = :tries
where sa.status = :failed and
sa.parentAction
= :action ]]>
</query>
Which can be executed as so:
public static void rescheduleFailedServerActions(Action action,
Long tries) {
singleton.getSession().getNamedQuery("Action.rescheduleFailedActions")
.setParameter("action", action)
.setParameter("tries", tries)
.setParameter("failed", ActionFactory.STATUS_FAILED)
.setParameter("queued",
ActionFactory.STATUS_QUEUED).executeUpdate();
}
Currently there isn't a useful function like listObjectsByNamedQuery but
I'll probably be adding one soon. The performance seems equivalent to
the raw sql update (~ 2 seconds).
It doesn't look like we've ever used this in our hibernate usage and I'm
not sure how new it is, but it seems to work great!
-Justin
_______________________________________________
Spacewalk-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/spacewalk-devel