[MS-OXCPRPT] Semantics for stream region lockingG'day long suffering forum people,<br/> <br/> I'm looking at MS-OXCPRPT, Section 2.2.23 &quot;RopLockRegionStream&quot; and Section 2.2.24 &quot;RopUnlockRegionStream&quot;.<br/> <br/> Is it possible to get some more information on the semantics of these operations? In particular:<br/> 1. What are the allowed sequences for locking/unlocking? For example, if I lock the range 0-1023, and then lock the range 1024-2047, is it legal to unlock the range 0-2047 in one operation? Is it legal to unlock the range in several sections (e.g. 0-511 then 512-1023)? What happens to the lock if I unlock a region greater than is locked (e.g. unlock 512-4095)?<br/> 2. What is the meaning of &quot;owner&quot; in 2.2.23.1.1 &quot;Lock Flags&quot;? That is, if I lock a region, who is allowed to read/write to it? Anything with the same session?<br/> <br/> Thanks again,<br/> <br/> Brad© 2009 Microsoft Corporation. All rights reserved.Sat, 08 Aug 2009 11:34:46 Z345d916e-10dd-4c6d-8471-0320118d86fahttp://social.msdn.microsoft.com/Forums/en-US/os_exchangeprotocols/thread/345d916e-10dd-4c6d-8471-0320118d86fa#345d916e-10dd-4c6d-8471-0320118d86fahttp://social.msdn.microsoft.com/Forums/en-US/os_exchangeprotocols/thread/345d916e-10dd-4c6d-8471-0320118d86fa#345d916e-10dd-4c6d-8471-0320118d86faBrad Hardshttp://social.msdn.microsoft.com/Profile/en-US/?user=Brad%20Hards[MS-OXCPRPT] Semantics for stream region lockingG'day long suffering forum people,<br/> <br/> I'm looking at MS-OXCPRPT, Section 2.2.23 &quot;RopLockRegionStream&quot; and Section 2.2.24 &quot;RopUnlockRegionStream&quot;.<br/> <br/> Is it possible to get some more information on the semantics of these operations? In particular:<br/> 1. What are the allowed sequences for locking/unlocking? For example, if I lock the range 0-1023, and then lock the range 1024-2047, is it legal to unlock the range 0-2047 in one operation? Is it legal to unlock the range in several sections (e.g. 0-511 then 512-1023)? What happens to the lock if I unlock a region greater than is locked (e.g. unlock 512-4095)?<br/> 2. What is the meaning of &quot;owner&quot; in 2.2.23.1.1 &quot;Lock Flags&quot;? That is, if I lock a region, who is allowed to read/write to it? Anything with the same session?<br/> <br/> Thanks again,<br/> <br/> BradTue, 07 Apr 2009 09:55:51 Z2009-04-07T09:55:51Zhttp://social.msdn.microsoft.com/Forums/en-US/os_exchangeprotocols/thread/345d916e-10dd-4c6d-8471-0320118d86fa#65ed1c27-8a73-46bf-8a5f-b7f91a98ce37http://social.msdn.microsoft.com/Forums/en-US/os_exchangeprotocols/thread/345d916e-10dd-4c6d-8471-0320118d86fa#65ed1c27-8a73-46bf-8a5f-b7f91a98ce37Tom Devey - MSFThttp://social.msdn.microsoft.com/Profile/en-US/?user=Tom%20Devey%20-%20MSFT[MS-OXCPRPT] Semantics for stream region locking<p>Hi Brad,<br/><br/>I have done my research on your questions above and I'm waiting for feedback from development</p><hr class="sig">Developer ConsultantWed, 08 Apr 2009 04:52:52 Z2009-04-08T04:52:52Zhttp://social.msdn.microsoft.com/Forums/en-US/os_exchangeprotocols/thread/345d916e-10dd-4c6d-8471-0320118d86fa#0e337dd9-738c-48ec-b097-f4f0fe93c1e3http://social.msdn.microsoft.com/Forums/en-US/os_exchangeprotocols/thread/345d916e-10dd-4c6d-8471-0320118d86fa#0e337dd9-738c-48ec-b097-f4f0fe93c1e3Brad Hardshttp://social.msdn.microsoft.com/Profile/en-US/?user=Brad%20Hards[MS-OXCPRPT] Semantics for stream region lockingTom,<br/> <br/> Once again, thanks for your work on this.<br/> <br/> Much appreciated.<br/> <br/> BradWed, 08 Apr 2009 04:57:05 Z2009-04-08T04:57:05Zhttp://social.msdn.microsoft.com/Forums/en-US/os_exchangeprotocols/thread/345d916e-10dd-4c6d-8471-0320118d86fa#07d108e9-5b36-42b2-9a35-f9a5ebeca69ahttp://social.msdn.microsoft.com/Forums/en-US/os_exchangeprotocols/thread/345d916e-10dd-4c6d-8471-0320118d86fa#07d108e9-5b36-42b2-9a35-f9a5ebeca69aTom Devey - MSFThttp://social.msdn.microsoft.com/Profile/en-US/?user=Tom%20Devey%20-%20MSFT[MS-OXCPRPT] Semantics for stream region locking<p class=MsoNormal style="margin:0in 0in 0pt"><span style="color:black;font-size:12pt"><span style="font-family:Calibri">Hi Brad,<br/><br/>You can have a single lock per region in a stream that is defined by a start and an end with a defined LockFlags.<span style="">  </span>You can have multiple regions locked in a stream but they cannot overlap. <span style=""> </span>Each lock is treated as separate entity and must be unlocked as a single entity unless the lock has been allowed to expired.<span style="">  </span>If you attempt to unlock an expired lock the ReturnValue in the Response buffer will be error code MAPI_E_NETWORK_ERROR (0x115).<br/><br/>In #1 above if you would have two separate locks that would require two separate unlocks with matching LockFlags.<span style="">  </span>If you lock a stream 0-1023 and then unlock the stream from 0-511 the lock 0-1023 will be cleared.<span style="">  </span>If you lock a stream 0-511 and then unlock the stream 0-512 the stream will not be unlocked and no error code will be returned.</span></span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="color:black;font-size:12pt"><span style="font-family:Calibri"> </span></span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="color:black;font-size:12pt"><span style="font-family:Calibri">As for question #2 the use of the language around Lock Flags ‘owner’ because the check is really from what I see (unless I’m missing something obvious) just a simple match.</span></span></p><hr class="sig">Developer ConsultantThu, 07 May 2009 18:00:03 Z2009-05-07T18:00:03Zhttp://social.msdn.microsoft.com/Forums/en-US/os_exchangeprotocols/thread/345d916e-10dd-4c6d-8471-0320118d86fa#744b2c29-143d-46c5-a578-a4d122344d47http://social.msdn.microsoft.com/Forums/en-US/os_exchangeprotocols/thread/345d916e-10dd-4c6d-8471-0320118d86fa#744b2c29-143d-46c5-a578-a4d122344d47Brad Hardshttp://social.msdn.microsoft.com/Profile/en-US/?user=Brad%20Hards[MS-OXCPRPT] Semantics for stream region lockingTom,<br/> <br/> That is probably the answer to my original question, but your answer raises a few more issues :-) Following along from the original questions:<br/> <br/> 3. I don't see anything in MS-OXCPRPT about locks &quot;expiring&quot;. Can you tell me more about this? For example, is it based on time, or something else (number of ROPs, perhaps something else)? Is it just a server side setting that applies to all users? Is there some client side control over it?<br/> <br/> 4. From your description, if I have a lock starting at RegionOffset of size RegionSize, then I will reliably unlock if I use the same RegionOffset and RegionSize (and flags) in the unlock. If I don't use the same RegionOffset, it will fail. If I use a RegionSize in the unlock  that is less than or equal to the RegionSize in the lock, it will unlock; howevr if RegionSize in the unlock is greater than the RegionSize in the lock, it will return success but not actually unlock. In pseudo-code:<br/> <br/> <pre>process_unlock( uint64_t unlockRegionOffset, uint64_t unlockRegionSize, uint32_t unlockLockFlags) { // find the right lock foreach ( streamLock, thisStream ) { if ( unlockRegionOffset == streamLock.RegionOffset ) { // this is the lock we're wanting to unlock if ( ( unlockRegionSize &lt;= streamLock.RegionSize ) &amp;&amp; ( unlockLockFlags == streamLock.LockFlags ) ) { unlock( streamLock ); return MAPI_E_SUCCESS; } else { // fail silently return MAPI_E_SUCCESS; } } } // we couldn't find a matching lock return MAPI_E_NETWORK_ERROR; }</pre> <br/> Does that roughly match your understanding?<br/> <br/> Brad<br/>Thu, 07 May 2009 22:33:44 Z2009-05-07T22:33:44Zhttp://social.msdn.microsoft.com/Forums/en-US/os_exchangeprotocols/thread/345d916e-10dd-4c6d-8471-0320118d86fa#6cf44c63-a709-47e0-a397-f5e2e83b41f4http://social.msdn.microsoft.com/Forums/en-US/os_exchangeprotocols/thread/345d916e-10dd-4c6d-8471-0320118d86fa#6cf44c63-a709-47e0-a397-f5e2e83b41f4Tom Devey - MSFThttp://social.msdn.microsoft.com/Profile/en-US/?user=Tom%20Devey%20-%20MSFT[MS-OXCPRPT] Semantics for stream region locking<p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-family:'Verdana','sans-serif';color:black;font-size:8pt">Brad,<br/><br/>Note that that there may be a scenario where there may be an &quot;owner&quot; so I'm looking for some addition feedback from Exchange development. <br style=""><br style=""></span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-family:'Verdana','sans-serif';color:black;font-size:8pt">I was re-reading the documents after I posted the response above and yes timeouts are not mentioned.  Looks like a opportunity for some additional details.</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-family:'Verdana','sans-serif';color:black;font-size:8pt"> </span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-family:'Verdana','sans-serif';color:black;font-size:8pt">In reviewing your code and looking at how Exchange treats the unlock I realized that my comments above about unlock is incorrect.<span style="">  </span>Turns out unlock does support the ability to unlock multiple locks on a stream with one request.<span style="">   </span>As an example if one has locked regions in a stream of 50-500 and 512-1023 one could pass in the start of 0 and the offset of 1024 and both regions would be unlocked.<span style="">  </span>If one or more of the locked regions locks had expired then MAP_E_NETWORK_ERROR is returned.</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-family:Calibri;font-size:small"> </span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-family:'Verdana','sans-serif';color:black;font-size:8pt">One additional observation is if the offset and size passed to unlock a stream defines a region that contains no locked regions then no error is returned (MAPI_E_SUCCESS).</span></p><hr class="sig">Developer ConsultantFri, 08 May 2009 05:11:16 Z2009-05-08T05:11:16Zhttp://social.msdn.microsoft.com/Forums/en-US/os_exchangeprotocols/thread/345d916e-10dd-4c6d-8471-0320118d86fa#330e4fb6-9667-478a-8798-6f473b6247f5http://social.msdn.microsoft.com/Forums/en-US/os_exchangeprotocols/thread/345d916e-10dd-4c6d-8471-0320118d86fa#330e4fb6-9667-478a-8798-6f473b6247f5Tom Devey - MSFThttp://social.msdn.microsoft.com/Profile/en-US/?user=Tom%20Devey%20-%20MSFT[MS-OXCPRPT] Semantics for stream region locking<p>Brad,<br/><br/>Ok I was able to get some clarification of the &quot;owner&quot;.  When you call RopLockRegionStream, one of the parameters is an InputHandleIndex, which points to a server object handle (that refers to the stream you are operating on).   If the lock is granted, then exclusive write access (or read/write access, depending on LockFlags) will be given to the user of that specific server object handle which is now termed the &quot;owner&quot;.  If another handle referring to the same stream object cannot write to the stream, even if that handle is on the same session. <br/><br/>Only the handle used on the RopLockRegionStream has access.</p><hr class="sig">Developer ConsultantSat, 20 Jun 2009 03:42:47 Z2009-06-20T03:42:47Zhttp://social.msdn.microsoft.com/Forums/en-US/os_exchangeprotocols/thread/345d916e-10dd-4c6d-8471-0320118d86fa#2b6ca726-c0bf-4d3d-99e7-01263df8b71fhttp://social.msdn.microsoft.com/Forums/en-US/os_exchangeprotocols/thread/345d916e-10dd-4c6d-8471-0320118d86fa#2b6ca726-c0bf-4d3d-99e7-01263df8b71fBrad Hardshttp://social.msdn.microsoft.com/Profile/en-US/?user=Brad%20Hards[MS-OXCPRPT] Semantics for stream region lockingTom.<br/> <br/> Where you wrote &quot; If another handle referring to the same stream object cannot write to the stream, even if that handle is on the same session.&quot;, should that be &quot; Another handle referring to the same stream object cannot write to the stream, even if that handle is on the same session.&quot;?<br/> <br/> Also, the part about timeouts and locks expiring is still not clarified.<br/> <br/> Thanks for continuing to follow this up.<br/> <br/> BradSat, 20 Jun 2009 04:02:34 Z2009-06-20T04:02:34Zhttp://social.msdn.microsoft.com/Forums/en-US/os_exchangeprotocols/thread/345d916e-10dd-4c6d-8471-0320118d86fa#fb3f5c18-6955-47d1-9ad5-434051f54c86http://social.msdn.microsoft.com/Forums/en-US/os_exchangeprotocols/thread/345d916e-10dd-4c6d-8471-0320118d86fa#fb3f5c18-6955-47d1-9ad5-434051f54c86Tom Devey - MSFThttp://social.msdn.microsoft.com/Profile/en-US/?user=Tom%20Devey%20-%20MSFT[MS-OXCPRPT] Semantics for stream region locking<p>Yea your correction is correct.   Ah looking at what I asked development I missed the ask about timeouts.  I will follow-up with development for clarification.  Just to make sure I frame the question correctly what additional information are you looking for outside of the fact that locks have timeouts and can expire and return an error.</p> <hr class=sig> Developer ConsultantTue, 23 Jun 2009 22:07:48 Z2009-06-24T05:14:08Zhttp://social.msdn.microsoft.com/Forums/en-US/os_exchangeprotocols/thread/345d916e-10dd-4c6d-8471-0320118d86fa#95c4a17d-0ef9-4e17-86e3-1858fe0dfbdehttp://social.msdn.microsoft.com/Forums/en-US/os_exchangeprotocols/thread/345d916e-10dd-4c6d-8471-0320118d86fa#95c4a17d-0ef9-4e17-86e3-1858fe0dfbdeBrad Hardshttp://social.msdn.microsoft.com/Profile/en-US/?user=Brad%20Hards[MS-OXCPRPT] Semantics for stream region lockingTom.<br/> <br/> I'm not really sure what the exact question is, because I don't know more than &quot;what is this timeout business&quot;.<br/> <br/> To help the discussion:<br/> 1. Under what circumstances can locks time out?<br/> 2. What is the timeout criteria (e.g. is in seconds, or in operations or bytes or something else?)<br/> 3. What does the server do when the lock times out? In particular, what error code represents a timeout?<br/> 4. What is the client expected to do in response to a timeout?<br/> <br/> Sorry to be so vague.<br/> <br/> BradWed, 24 Jun 2009 08:34:22 Z2009-06-24T08:34:22Zhttp://social.msdn.microsoft.com/Forums/en-US/os_exchangeprotocols/thread/345d916e-10dd-4c6d-8471-0320118d86fa#1846181e-4bd0-42cf-9464-dbd67df8d75fhttp://social.msdn.microsoft.com/Forums/en-US/os_exchangeprotocols/thread/345d916e-10dd-4c6d-8471-0320118d86fa#1846181e-4bd0-42cf-9464-dbd67df8d75fTom Devey - MSFThttp://social.msdn.microsoft.com/Profile/en-US/?user=Tom%20Devey%20-%20MSFT[MS-OXCPRPT] Semantics for stream region lockingI passed my feedback on what I thought was important to document and I added your suggestions to the discussion with development.<br/><br/>Thanks!<hr class="sig">Developer ConsultantThu, 25 Jun 2009 00:25:38 Z2009-06-25T00:25:38Zhttp://social.msdn.microsoft.com/Forums/en-US/os_exchangeprotocols/thread/345d916e-10dd-4c6d-8471-0320118d86fa#56b42e35-ef3f-4b2d-a1ab-1d3c9c65658ahttp://social.msdn.microsoft.com/Forums/en-US/os_exchangeprotocols/thread/345d916e-10dd-4c6d-8471-0320118d86fa#56b42e35-ef3f-4b2d-a1ab-1d3c9c65658aTom Devey - MSFThttp://social.msdn.microsoft.com/Profile/en-US/?user=Tom%20Devey%20-%20MSFT[MS-OXCPRPT] Semantics for stream region locking<p>Hi Brad,<br/><br/>This is moving forward on my side with development.  More details on the missing content will be posted soon here on this thread.<br/></p><hr class="sig">Developer ConsultantWed, 29 Jul 2009 22:57:25 Z2009-07-29T22:57:25Zhttp://social.msdn.microsoft.com/Forums/en-US/os_exchangeprotocols/thread/345d916e-10dd-4c6d-8471-0320118d86fa#b021c786-a604-4321-93cb-762c6ba981aahttp://social.msdn.microsoft.com/Forums/en-US/os_exchangeprotocols/thread/345d916e-10dd-4c6d-8471-0320118d86fa#b021c786-a604-4321-93cb-762c6ba981aaTom Devey - MSFThttp://social.msdn.microsoft.com/Profile/en-US/?user=Tom%20Devey%20-%20MSFT[MS-OXCPRPT] Semantics for stream region locking<p>Hi Brad,<br/><br/>The development for these ROPs was done in the mid 1990’s originally for Schedule+ and the the stream lock/unlock were last used by Outlook 2000.  They are not used by subsequent versions of Outlook. The ROPs were added to the documentation because the current version of Exchange 2007 Load Generator sends the ROPs over the wire. There is a bug being filed to have them removed.   There will be additional information added to the document MS-OXCPRPT in a future release.</p> <p>As for your questions here is the feedback from development:</p> <p>1. Under what circumstances can locks time out?<br/><br/>Region locking only has an effect on streams on folder objects. Streams for message or attachment objects are independent of each other, so the locks have no effect on them (you cannot lock yourself out of a region, and your lock doesn’t affect any other version of the stream). This is limited to folder streams. During a LockRegion call for folder streams, the server will first check for existing locks on that region of the stream. If any are found, we will query the last activity time on the session that locked that region. If the last activity is greater than a certain interval, then that lock is marked as expired.</p> <p>2. What is the timeout criteria (e.g. is in seconds, or in operations or bytes or something else?)<br/><br/>It is defaulted to 30 seconds. There is a way to override the default timeout in the registry but the override key has never been published.</p> <p>3. What does the server do when the lock times out? In particular, what error code represents a timeout?<br/><br/>All pending stream changes are discarded. Any read/write/setsize/commit that would encounter the region that has the expired lock will fail with the MAPI_E_NETWORK_ERROR.</p> <p>4. What is the client expected to do in response to a timeout?<br/><br/>The burden is put on the client and effectively you have retry logic. When an expired lock is encountered, unlock region will fail with the same error as mentioned above, except that it will also remove the expired lock. <br/><br/>There is no way to remove expired locks outside of trying to unlock the lock. There is a race condition with this because when one would attempt a recovery which would consists of “a) unlock the region that contains expired locks b) lock the region myself&quot;, then two clients performing the operation could have one client performing step “a” after the other did step “b”, thus removing valid locks. The retry logic in Outlook 2000 ‘s Schedule+ was based on user input, which made it very unlikely that two clients would recover at exactly the same time and hit these problems.<br/><br/>Hope this helps,</p><hr class="sig">Developer ConsultantSat, 08 Aug 2009 05:30:24 Z2009-08-08T05:30:24Zhttp://social.msdn.microsoft.com/Forums/en-US/os_exchangeprotocols/thread/345d916e-10dd-4c6d-8471-0320118d86fa#e4dfa838-468f-490a-81a6-10717fe51f50http://social.msdn.microsoft.com/Forums/en-US/os_exchangeprotocols/thread/345d916e-10dd-4c6d-8471-0320118d86fa#e4dfa838-468f-490a-81a6-10717fe51f50Brad Hardshttp://social.msdn.microsoft.com/Profile/en-US/?user=Brad%20Hards[MS-OXCPRPT] Semantics for stream region lockingTom,<br/> <br/> I think I see why this one took a while :-)<br/> <br/> Thanks for the work on this one. Can you also please pass my thanks the devel team who worked on this?<br/> <br/> BradSat, 08 Aug 2009 11:34:22 Z2009-08-08T11:34:22Z