Wednesday, January 12, 2011

Locks / Critical Sections in Multi – WFE Environment

While we are dealing Deadlocks in SharePoint 2007 case which I have blogged here
http://bharatreddybasani.blogspot.com/2010/10/deadlocks-in-sharepoint-2007_29.html
with Microsoft, One of the Microsoft representative made this statement regarding placing Locks / Critical sections in multi-WFE environments.
In multi-WFE env, this lock may not work properly, because the objLock is different instance on each WFE.
I was surprised to learn about it. I do not have a solid proof to prove the above statement. To eliminate transactions being deadlocked in multi - Web front end environments, this was the workaround given by Microsoft representative. Below statement is in the context of SharePoint.

Another portion of the workaround that you may not be familiar with is to add a property key/value pair in the SPWeb object so that the values can be queried from all servers. It is actually quite easy to use it and you can see it from here. http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spweb.allproperties.aspx. On another note, you do not have to use the SPWeb property bag to store the value. You can also use a SharePoint list at the root site level to contain both the flag and URLs mentioned in the steps below. Or you can also use a custom DB to store those. All in all, there are several options for storing these values, you can choose the one that fits your need the best.