<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xsl" href="RSS_xslt_style.asp" version="1.0" ?>
<rss version="2.0" xmlns:WebWizForums="http://syndication.webwiz.co.uk/rss_namespace/">
 <channel>
  <title>DevForce Community Forum : A couple of questions on Concurrency</title>
  <link>http://www.ideablade.com/forum/</link>
  <description>This is an XML content feed of; DevForce Community Forum : DevForce Classic : A couple of questions on Concurrency</description>
  <pubDate>Tue, 14 Apr 2026 16:27:18 -700</pubDate>
  <lastBuildDate>Fri, 20 Jul 2007 15:10:03 -700</lastBuildDate>
  <docs>http://blogs.law.harvard.edu/tech/rss</docs>
  <generator>Web Wiz Forums 9.69</generator>
  <ttl>360</ttl>
  <WebWizForums:feedURL>www.ideablade.com/forum/RSS_post_feed.asp?TID=322</WebWizForums:feedURL>
  <image>
   <title>DevForce Community Forum</title>
   <url>http://www.ideablade.com/forum/forum_images/IdeaBlade_logo_tm.png</url>
   <link>http://www.ideablade.com/forum/</link>
  </image>
  <item>
   <title>A couple of questions on Concurrency :  Yes, this is fundamentally harder...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=322&amp;PID=744#744</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=21" rel="nofollow">IdeaBlade</a><br /><strong>Subject:</strong> 322<br /><strong>Posted:</strong> 20-Jul-2007 at 3:10pm<br /><br /><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><?:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p>&nbsp;<P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">Yes, this is fundamentally harder than it seems. In this it is like multi-threaded programming - the simple and obvious answer works 99.99% ... but that rare -&nbsp;often undetected -&nbsp;failure causes enormous heartburn somewhere far from the source of the original injury.<o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">&nbsp;<o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">I would like to be able to follow the thread of your reasoning. That would take time and I'd like to get back to you right away on your final two questions:<o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">&nbsp;<o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">"<SPAN style="COLOR: #1f497d">If we want to do optimistic locking, we must have a “changed” field that you can track.&nbsp; If we don’t have that today, we’ll need to add it to most of our tables.&nbsp; Yes?</SPAN> <SPAN style="COLOR: #1f497d"><o:p></o:p></SPAN></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT face="Times New Roman"><SPAN style="FONT-SIZE: 11pt; COLOR: #1f497d; FONT-FAMILY: Calibri">If we don’t make that change, all of our updates will be last one wins (because you won’t hold locks)? (oops, two questions)</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Calibri">"<SPAN style="COLOR: #1f497d"><o:p></o:p></SPAN></SPAN></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Calibri"><FONT face="Times New Roman">&nbsp;<o:p></o:p></FONT></SPAN></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">You don't have to have a concurrency column on every table - only on those tables that you use to detect and signal concurrency violations. DevForce will apply optimistic concurrency checking on those tables and "last one wins" on the others.<SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Calibri"><o:p></o:p></SPAN></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Calibri"><FONT face="Times New Roman">&nbsp;<o:p></o:p></FONT></SPAN></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">Let me illustrate: Suppose I have such a column on Order but not on OrderDetail. <SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Calibri"><o:p></o:p></SPAN></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">Scenario #1: I change an order; you change the same order; I save, you save;&nbsp;DF detects the problem and tells you. <SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Calibri"><o:p></o:p></SPAN></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Calibri"><FONT face="Times New Roman">&nbsp;<o:p></o:p></FONT></SPAN></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">Scenario #2: I change an orderDetail; you change the same orderDetail; I save, you save;&nbsp;DF is oblivious and your save trumps mine.<SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Calibri"><o:p></o:p></SPAN></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">Is this bad? Not necessarily!<SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Calibri"><o:p></o:p></SPAN></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Calibri"><FONT face="Times New Roman">&nbsp;<o:p></o:p></FONT></SPAN></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT face="Times New Roman"><FONT size=3>Let me add another rule: "Everytime I&nbsp;change an orderDetail, I must also change its parent Order." This rule&nbsp;implies that a change to an order's detail items is tantamount to a change to the order itself.</FONT><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Calibri">&nbsp;<o:p></o:p></SPAN></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Calibri"><FONT face="Times New Roman">&nbsp;<o:p></o:p></FONT></SPAN></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">I happen to like that logic as I'll explain in a minute. But let's just run with this for now and replay Scenario #2:<SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Calibri"><o:p></o:p></SPAN></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">Scenario #2b: I change an orderDetail which changes the parent order; you change the same orderDetail which changes the same parent order; I save, you save;&nbsp;DF detects the collision on order, fails your transaction, neither the order nor the detail are saved, and you hear all about it.<o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">This is exactly what I want and, in fact, catches another slippery bug that neither of us considered in the discussion below (I left it out deliberately because there was enough to worry about).<o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">Scenario #3:&nbsp; I change an orderDetail ; you change&nbsp;its parent order; I save, you save;&nbsp;DF detects the collision on order, fails your transaction, your order change is rejected.<o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">Observe that, in the absence of the rule, "changing an OrderDetail changes its parent Order", none of the mechanisms either of us described below would have caught that particular&nbsp;concurrency violation. Yet surely the Order is fundamentally changed if I modify/add/delete any of its OrderDetails. I should be wondering what you are doing changing RequiredDate&nbsp;on <B><I>my order</I></B>&nbsp;while I was changing the quantity of Acme Widgets?<o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">&nbsp;<o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">We (you and I as sales reps working on the order) are clearly out-of-sync and the application should alert us to that fact.<o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">&nbsp;<o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">In my solution, I've made Order the "master" object in a dependent object graph (there's a UML term for this but let's not be pedantic). Order is "soft locking" its OrderDetails. The master object provides effective concurrency control over objects in its dependent graph. Therefore, those dependent objects do not need their own concurrency column.<o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">&nbsp;<o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">This works as long as all processes that can save data to the database play by the rules:<o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">Always save member of the object graph within a transaction (i.e., can't save an orderDetail on its own). <o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">Always "dirty" the parent when you modify/add/delete a child (or grandchild).<o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">&nbsp;<o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">It follows that&nbsp;any object can play the "master" object role.<o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">&nbsp;<o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">Suppose you couldn't add a concurrency column&nbsp;to Order. Fortunately, you can create a table to hold some kind of&nbsp;object to serve as "the master of the master".<o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">&nbsp;<o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">Let's abstract this and dedicate a table dedicated to soft locking of any table in our database. Each of it's rows is a tuple: {ObjectType, ObjectPrimaryKey, RowVersion, UserId, ...}. <o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">&nbsp;<o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">Every time I update an order, I try to acquire the&nbsp;SoftLock object for that order. If there isn't one, I create one. I now include this in my transaction with the Order and OrderDetail changes.<o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">&nbsp;<o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">You see where this leads.<o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">&nbsp;<o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">P.S.: This technique imposes a miniscule performance impact and is a small addition to the business logic that can be encapsulated in one place, either in a base entity class or via some kind of "mix-in" approach.<o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">&nbsp;<o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">===<o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">&nbsp;<o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">You may also see that there is an opportunity to use the SoftLock table as a non-blocking CheckOut mechanism.&nbsp; Joe can check out the Order before working on it. Sam's client detects the checkout and tells Sam that Joe has it.&nbsp; Sam can move on to something else, call Joe, or ... steal it from Joe by overwriting his SoftLock object.<o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">&nbsp;<o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">This last alternative may seem sneaky. It may also be necessary:<o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">Joe is at lunch; there's a crisis; Sam pitches in and gets it done; Joe returns ... tries to finish the order ... and discovers that Sam stole the order. He may be pissed but ... that's another story.<o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">At least one of our customers uses this technique with considerable satisfaction. It provides safety and information ... and is non-blocking.<o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">&nbsp;<o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">===<o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">&nbsp;<o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">So that's my "quick" answer. To summarize:<o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">optimistic concurrency only works for tables that have a suitable concurrency column <o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">not every table has to be under concurrency control <o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">if you can't modify a table, you can check it for concurrency by subordinating it in a transaction to another table <o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">you can implement "master/detail" concurrency checking and "CheckOut" control via this mechanism<o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">&nbsp;<o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">Hope this all makes sense.<o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><o:p><FONT face="Times New Roman" size=3>&nbsp;</FONT></o:p></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><o:p><FONT face="Times New Roman" size=3>&nbsp;</FONT></o:p></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"></o:p></SPAN><FONT face="Times New Roman" size=3>&nbsp;</FONT></P><P>&nbsp;</P>]]>
   </description>
   <pubDate>Fri, 20 Jul 2007 15:10:03 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=322&amp;PID=744#744</guid>
  </item> 
  <item>
   <title>A couple of questions on Concurrency : Thanks for the response. How could...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=322&amp;PID=743#743</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=20" rel="nofollow">Customer</a><br /><strong>Subject:</strong> 322<br /><strong>Posted:</strong> 20-Jul-2007 at 3:07pm<br /><br /><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><?:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p>&nbsp;<SPAN style="COLOR: #1f497d">Thanks for the response.&nbsp; How could we have so many problems that you point out? This made me think more carefully about the details of what we are requiring to happen underneath the interface I described.&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #1f497d"><o:p>&nbsp;</o:p></SPAN><P =Ms&#111;normal><SPAN style="COLOR: #1f497d">At the heart of the matter are a some rather important requirements for our interface to work.&nbsp; One of them is that the implementation has to run in a transaction.&nbsp; I’m now wondering if its ever possible to have a middle tier do “absolute” business logic verification outside a transaction?<o:p></o:p></SPAN></P><P =Ms&#111;normal><SPAN style="COLOR: #1f497d"><o:p></o:p></SPAN></P><P =Ms&#111;normal><SPAN style="COLOR: #1f497d">Anyway, here are my rules:</SPAN><SPAN style="COLOR: #1f497d"><o:p>&nbsp;</o:p></SPAN></P><P =MsoListParagraph style="TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1"><SPAN style="COLOR: #1f497d"><SPAN style="mso-list: Ignore">1.<SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN></SPAN><SPAN style="COLOR: #1f497d">Before applying validation, start a transaction<o:p></o:p></SPAN></P><P =MsoListParagraph style="TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1"><SPAN style="COLOR: #1f497d"><SPAN style="mso-list: Ignore">2.<SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN></SPAN><SPAN style="COLOR: #1f497d">Retrieve the current copy of the record from the database.<o:p></o:p></SPAN></P><P =MsoListParagraph style="TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1"><SPAN style="COLOR: #1f497d"><SPAN style="mso-list: Ignore">3.<SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN></SPAN><SPAN style="COLOR: #1f497d">Verify none of the unchangedList field have changed (send errors if so).<o:p></o:p></SPAN></P><P =MsoListParagraph style="TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1"><SPAN style="COLOR: #1f497d"><SPAN style="mso-list: Ignore">4.<SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN></SPAN><SPAN style="COLOR: #1f497d">Apply the updated field values to the record<o:p></o:p></SPAN></P><P =MsoListParagraph style="TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1"><SPAN style="COLOR: #1f497d"><SPAN style="mso-list: Ignore">5.<SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN></SPAN><SPAN style="COLOR: #1f497d">Perform validation.<o:p></o:p></SPAN></P><P =MsoListParagraph style="TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1"><SPAN style="COLOR: #1f497d"><SPAN style="mso-list: Ignore">6.<SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN></SPAN><SPAN style="COLOR: #1f497d">Update if OK, send error (s) if not.<o:p></o:p></SPAN></P><P =MsoListParagraph style="TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1"><SPAN style="COLOR: #1f497d"><SPAN style="mso-list: Ignore">7.<SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN></SPAN><SPAN style="COLOR: #1f497d">End transaction<o:p></o:p></SPAN></P><P =Ms&#111;normal><SPAN style="COLOR: #1f497d"><o:p></o:p></SPAN></P><P =Ms&#111;normal><SPAN style="COLOR: #1f497d">Some comments:</SPAN><SPAN style="COLOR: #1f497d"><o:p>&nbsp;</o:p></SPAN></P><P =Ms&#111;normal><SPAN style="COLOR: #1f497d">The idea behind all this is to let the user know that something in the database had changed (due to someone else’s action) from what is on their screen when they pressed “enter”.<o:p></o:p></SPAN></P><P =Ms&#111;normal><SPAN style="COLOR: #1f497d"><o:p></o:p></SPAN></P><P =Ms&#111;normal><SPAN style="COLOR: #1f497d">We liked the model as it worked over the web, and for different technologies across tiers.<o:p></o:p></SPAN></P><P =Ms&#111;normal><SPAN style="COLOR: #1f497d"><o:p></o:p></SPAN></P><P =Ms&#111;normal><SPAN style="COLOR: #1f497d">The requirement to seed the validation buffer with the existing values is obviously how we ensure a “proper” validation.&nbsp; Can this notion fit into a multi tier ORM mapper model?</SPAN><SPAN style="COLOR: #1f497d"><o:p>&nbsp;</o:p></SPAN></P><P =Ms&#111;normal><SPAN style="COLOR: #1f497d">It is the transaction that avoids your described problem of the integrity checks with other object fields.&nbsp; <o:p></o:p></SPAN></P><P =Ms&#111;normal><SPAN style="COLOR: #1f497d"><o:p></o:p></SPAN></P><P =Ms&#111;normal><SPAN style="COLOR: #1f497d">I’m now thinking hard about the meaning and appropriateness of the unchanged list. &nbsp;One simplistic observation is that your “A” example below would be a programming error:&nbsp; if the changes submitted depend on the value of A not being changed, then it should have been in the list in the first place.&nbsp; This leads to the question, suppose it isn’t in the list… shouldn’t the business logic validation catch it anyway?&nbsp; Perhaps so, in which case this makes me wonder if the list is needed at all…. Just make the changes and let the validation do its thing.&nbsp; Maybe this unchangedList is “just” a kind of optimization of optimistic update implementation that can be pushed up the object hierarchy into a base class and automated; this makes it a kind of metadata, except that it can be specified on an update-by-update basis.</SPAN><SPAN style="COLOR: #1f497d"><o:p>&nbsp;</o:p></SPAN></P><P =Ms&#111;normal><SPAN style="COLOR: #1f497d">Here is something more interesting to me, that I hadn’t fully considered before:&nbsp; Should you, in principle, always validate <U>everything</U> on any change? <o:p></o:p></SPAN></P><P =Ms&#111;normal><SPAN style="COLOR: #1f497d"><o:p></o:p></SPAN></P><P =Ms&#111;normal><SPAN style="COLOR: #1f497d">If I am inclined to answer yes to this question, then my unchangedList becomes only a list of things that the user wants to be notified of that have changed, rather than a list to guide or help or optimize validation.&nbsp; If that’s the case, then the only purpose it would serve is to allow the UI to say:<o:p></o:p></SPAN></P><P =Ms&#111;normal><SPAN style="COLOR: #1f497d">“if the changed field is not in this list, then perform the update regardless (as long as validation is ok)”.&nbsp; At that point, the list becomes a finer grained version of your “modified” column, without that column needing to exist (at least for this purpose. Audits are a different matter).&nbsp; By itself this feature seems quite useful.&nbsp; I can imagine changes to different parts of large records that can safely be performed independently.</SPAN><SPAN style="COLOR: #1f497d"><o:p>&nbsp;</o:p></SPAN></P><P =Ms&#111;normal><SPAN style="COLOR: #1f497d">I’m not sure where this conversation is going, but I’m constantly amazed at how something conceptually simple (an update) has these layers of complexity.&nbsp; Don’t worry about a deep response if you’re too busy, this seems to have gotten a bit long-winded!!!!&nbsp; If we use DevForce it becomes somewhat academic, as we’ll go with your strategy.&nbsp; Which leaves me with one more important question:<o:p></o:p></SPAN></P><P =Ms&#111;normal><SPAN style="COLOR: #1f497d"><o:p></o:p></SPAN></P><P =Ms&#111;normal><SPAN style="COLOR: #1f497d">If we want to do optimistic locking, we must have a “changed” field that you can track.&nbsp; If we don’t have that today, we’ll need to add it to most of our tables.&nbsp; Yes?<o:p></o:p></SPAN></P><P =Ms&#111;normal><SPAN style="COLOR: #1f497d">If we don’t make that change, all of our updates will be last one wins (because you won’t hold locks)? (oops, two questions)</SPAN></P></o:p></SPAN>]]>
   </description>
   <pubDate>Fri, 20 Jul 2007 15:07:53 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=322&amp;PID=743#743</guid>
  </item> 
  <item>
   <title>A couple of questions on Concurrency : DF optimistic concurrency depends...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=322&amp;PID=742#742</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=21" rel="nofollow">IdeaBlade</a><br /><strong>Subject:</strong> 322<br /><strong>Posted:</strong> 20-Jul-2007 at 2:58pm<br /><br /><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Arial">DF optimistic concurrency depends upon the existence of a single data column that serves as the concurrency indicator. It can be any type; the only requirement is that it change&nbsp;every time the row is updated (obviously the&nbsp;range of possible values must be large enough; a bit field would not do :-)</SPAN><?:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">&nbsp;<o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Arial">You can turn concurrency off for any business object type in which case "last writer wins" for saves of that type.</SPAN><o:p></o:p></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">&nbsp;<o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Arial">Thus we have coverage for (i) and (ii), albeit by different means.</SPAN><o:p></o:p></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">&nbsp;<o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Arial">====</SPAN><o:p></o:p></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">&nbsp;<o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Arial">We deliberately do not support (iii) as we feel is is unsafe and we can not think of a benefit that adequately compensates&nbsp;for the loss of safety.</SPAN><o:p></o:p></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">&nbsp;<o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Arial">What is unsafe?</SPAN><o:p></o:p></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">&nbsp;<o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Arial">Business object validation typically involves comparisons of multiple properties of a business object and often of&nbsp;properties of related objects. I'll stick to the cross-property, same object case.</SPAN><o:p></o:p></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">&nbsp;<o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Arial">If I perform a test that&nbsp;involves column "A", I'm expecting the value&nbsp;of "A" to be the one&nbsp;in&nbsp;the object I am about to update. Suppose that value is trumped by a&nbsp;different value from&nbsp;a different user who managed to save the object while I wasn't looking. I will not detect this difference. I will think the object is valid. As it happens, my object would be invalid if column "A" has the value now in the database.</SPAN><o:p></o:p></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">&nbsp;<o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Arial">Thus I&nbsp;cannot be certain that my object is valid when I save it. The (iii) feature would undermine my object integrity tests.&nbsp;I'd probably never know it happened (although I suppose I could RE-VALIDATE IT when the DF returned it from save ... but who is going to do that?).</SPAN><o:p></o:p></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">&nbsp;<o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Arial">Now suppose I proceed as we do in DevForce &#091;(ii)&#093;.&nbsp;</SPAN><o:p></o:p></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">&nbsp;<o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Arial">I detect a concurrency problem. I compare the&nbsp;object I tried to write with the object as it is in the database. I see that column "A" was changed. I decide to blend in the value from the database and try to save again. BUT THIS TIME, I re-validate the object before save (as I always do); if it is ok, the&nbsp;save continues; if it is not ok, we stop right there.</SPAN><o:p></o:p></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">&nbsp;<o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Arial">This is surely much safer than (iii). I&nbsp;can achieve the same effect as (iii) - that is, I can blend this user's changes&nbsp;with changes made by someone else - but I do so under&nbsp;validation control. There is&nbsp;no extra programming cost or complexity -&nbsp;approach (iii) and the one I describe both involve blending values from different user inputs - but the programming takes place in the business model where I can see it ... not some code&nbsp;in a distant module.</SPAN><o:p></o:p></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">&nbsp;<o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Arial">There is a slight performance impact - I have to&nbsp;update twice. But we're talking about optimistic concurrency, yes?&nbsp;Collisions are&nbsp;supposed to be rare. If they are NOT rare, then I would recommend a more pessimistic strategy such as&nbsp;soft locking.</SPAN><FONT size=3><FONT face="Times New Roman">&nbsp;<o:p></o:p></FONT></FONT></P>]]>
   </description>
   <pubDate>Fri, 20 Jul 2007 14:58:08 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=322&amp;PID=742#742</guid>
  </item> 
  <item>
   <title>A couple of questions on Concurrency : Two questions which I hope will...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=322&amp;PID=741#741</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=20" rel="nofollow">Customer</a><br /><strong>Subject:</strong> 322<br /><strong>Posted:</strong> 20-Jul-2007 at 2:56pm<br /><br /><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">Two questions which I hope will not take too much of your time:<?:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><o:p><FONT face="Times New Roman" size=3>&nbsp;</FONT></o:p></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT face="Times New Roman"><FONT size=3>1.</FONT><SPAN style="FONT-SIZE: 7pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><FONT size=3>(To see if I have understood the n-tier implementation): Is a BOS effectively a remoting server for a client? If so, does one BOS serve multiple clients?</FONT></FONT><SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Arial">&nbsp; Yes and Yes&nbsp;</SPAN><o:p></o:p></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT face="Times New Roman"><FONT size=3>2.</FONT><SPAN style="FONT-SIZE: 7pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></FONT><FONT size=3><FONT face="Times New Roman">We invented a “general” optimistic locking model which we hoped to be able to implement (over time) for all of our data access models in our many and varied products.&nbsp; From what I’ve read and understood so far (which is more than last week but still not enough) I’m not sure if we can implement it. I like our model a lot as it both simple and yet gives great flexibility for optimistic update conflict detection.<BR><BR>The essence of the model is the signature of the Update() method, which is<BR>entity.Update(unchangedList, modifiedList);<BR><BR>The rules are:<BR>unchangedList specifies a list of (fieldname,fieldvalue) pairs where the field value (in the database) must not have changed since the original data fetch. <BR>modifiedList is a list of (fieldname, newvalue) pairs which contain the new field values.<o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><o:p><FONT face="Times New Roman" size=3>&nbsp;</FONT></o:p></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">The lists are completely unrelated (but must not overlap!).&nbsp; In (almost) all cases, the unchanged list must include the primary key (PK) values.<BR><BR>Examples:<o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT face="Times New Roman"><FONT size=3>i)</FONT><SPAN style="FONT-SIZE: 7pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><FONT size=3>If the unchangedList contains only the PK value(s), then what you have is “last writer wins”.<o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT face="Times New Roman"><FONT size=3>ii)</FONT><SPAN style="FONT-SIZE: 7pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><FONT size=3>If the unchangedList contains the PK plus (say) a timestamp field, you have a “typical” optimistic locking implementation<o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT face="Times New Roman"><FONT size=3>iii)</FONT><SPAN style="FONT-SIZE: 7pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><FONT size=3>By specifying explicit fields in this list, you can be much more subtle and accommodating for multiple users updating different parts of a record during the same time period.<o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">In particular, whether or not you care about overwriting a changed value is up to the business logic in this model.&nbsp; Additionally, the model accommodates existing tables without the need to add new fields explicitly for optimistic support.<o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><o:p><FONT face="Times New Roman" size=3>&nbsp;</FONT></o:p></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT face="Times New Roman" size=3>I believe that the Mapping tool has a place where you can specify a single field that represents whether a record has been updated? That would correspond to example 2 above, but fixed with regard to number of fields(1) and field choice, at design time?<BR><BR>We can figure out later how to implement #2 (or ask later if we can’t stretch that far!).&nbsp; The main question right now is,&nbsp; do we have the capability to do it within the DevForce architecture?</FONT><SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Arial">&nbsp;</SPAN></P>]]>
   </description>
   <pubDate>Fri, 20 Jul 2007 14:56:17 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=322&amp;PID=741#741</guid>
  </item> 
 </channel>
</rss>