What code issues this DB query: "UPDATE Orchard_Framework_ContentItemVersionRecord SET Number = @p0, Published = @p1, Latest = @p2, ContentItemRecord_id = @p3 WHERE Id = @p4"

Topics: Troubleshooting
Apr 13, 2015 at 9:16 AM
In my quest to hunt down all DB deadlocks in our application, I'm left with sporadic deadlocks where one of the locked queries is always this one:
UPDATE Orchard_Framework_ContentItemVersionRecord
SET Number = @p0,
    Published = @p1,
    Latest = @p2,
    ContentItemRecord_id = @p3
WHERE Id = @p4
My guess is that this query is auto-generated by NHibernate as part of a larger query batch but I can't figure out where exactly it is coming from.

The problem is that the above query produces a deadlock on the Orchard_Framework_ContentItemVersionRecord table together with some SELECT query, e.g.
SELECT count(*) as y0_ FROM Orchard_Framework_ContentItemVersionRecord this_
inner join Orchard_Framework_ContentItemRecord contentite1_
    on this_.ContentItemRecord_id=contentite1_.Id
inner join Discoverize_Pictures_PicturePartRecord picturepar3_
    on contentite1_.Id=picturepar3_.Id
inner join Orchard_Framework_ContentTypeRecord contenttyp2_
    on contentite1_.ContentType_id=contenttyp2_.Id
WHERE contenttyp2_.Name = @p0
and picturepar3_.Entry_id = @p1
and this_.Published = @p2
Can anyone shed some light on where those UPDATE queries are coming from?
Apr 13, 2015 at 11:51 AM
Edited Apr 13, 2015 at 11:53 AM
The UPDATE code seems to come from content manager. The only moments when Orchard_Framework_ContentItemVersionRecord table is updated are when
  • a new version of an item is created,
  • when an item is published/unpublished,
  • someone touches ContentItemVersionRecord object manually somewhere.
Please shed some more light on what the app is doing at the time of this deadlock? Heavy load, background task or workflow that is updating content items?
This sounds like a multi-threading issue.

Can you try running MiniProfiler while reproducing this issue? This could give more insight on what part of code is the culprit.