NOTE: Thisarticle is migrated from Blog AsiaTech
Date:2009-11-25 10:24 AM
Orignal URL: http://blogs.msdn.com/b/asiatech/archive/2009/11/25/unable-to-suspend-or-terminate-active-service-instance-in-biztalk.aspx
When try to suspend orterminate a active service instance, the instance can not be suspended orterminated for a long time, it keeps active with Pending Job of the instance isset to Suspend or Terminate
A service instance is inActive status means that it is still actively running in a host instance and hasn’treached the next persistence point. Suspend and Terminate operations aredesigned as operation which will only be executed at the next persistablepoint. The Suspend or Terminate operation will be put into the pendingoperation table when the target service instance is in Active status. Pleasenote BizTalk only hold one pending operation for a single instance. Theinstance will keep Active status with the queued pending operation until thenext persistence point is reached. Let’s use a simple orchestration example todemo the behavior.
The code is in Expression_1is as the below which is used to simulate long time processing in a hostinstance or hang in a host instance.
When drop a testing messageto activate the above simple orchestration, it will keep Active status forabout 5 minutes and then an output message will be sent out. If try to suspendthe active instance when the instance is sleeping in the host instance, theinstance will keep in Active status for a quite while with Pending Job is setto Suspend until the next persistence point - send shape is reached. Oneinteresting thing is that the orchestration instance will be started from thelast persistence point to continue the execution if the running host instanceis restarted, our simple orchestration will start from the beginning tore-execute the whole orchestration code again if the host instance is restartedduring System.Threading.Thread.Sleep(),we will see the instance will keepActive status with the pending operation Suspend for another 5 minutes. Now wegot a problem, If the code in the expression shape is changed as the below tosimulate a real hang situation.
We will find we can’tsuspend the Active instance. The orchestration instance will keep Active withthe pending operation Suspend forever even if the running host instance isrestarted in BTS 2K6 and 2K6R2.
The ways to handle a longtime active or hang instance as the above
1. The format way should beto find where is the instance active or hang. The HAT debugging or a hang dumpfile for the running host instance can be used to find out where the instanceprocessing is blocked. If the processing block or the hang can be fixed, thenthe instance can quickly move to the next persistable point, the pendingoperation or the other operations can get a chance to execute.
2. If you don’t want tospend the time to figure out where the blocking is and just want to simplyclean out the instance from the MessageBox, use the tool Terminator toterminate these instance hardly. You can download the Terminator from the belowlink. The following is the captured screen for Terminate Instance (Hard) forthe reference.
3. As the above, if justwant to suspend or terminate the instance, besides the Terminator, you also cancall the internal store procedure int_AdminSuspendInstance_<host> orint_AdminTerminateInstance_<host> directly to suspend or terminate theinstance in MessageBox database. The following are the two SQL script sample touse the two store procedures.
declare @fKnownInstance int
declare @dtTimeStamp datetime
select @nvcErrorString = nvcError FROMdbo.LocalizedErrorStrings WHERE nID = 4
set @spname= 'int_AdminSuspendInstance_' +@ApplicationName
exec @spname @uidInstanceID, @uidServiceID,N'0xC0C01B50', -1, @nvcErrorString, 1, null, @dtTimeStamp, null, null,@fKnownInstance OUTPUT
DELETE FROM InstancesPendingOperations WITH(ROWLOCK) WHERE uidInstanceID = @uidInstanceID OPTION (KEEPFIXED PLAN)
set @uidInstanceID='xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx '
set @uidServiceID='xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx '
set @spname= 'int_AdminTerminateInstance_' +@ApplicationName
exec @spname @uidInstanceID, @uidServiceID,@fKnownInstance OUTPUT
(1) The two store proceduresare used by BizTalk internally to suspend or terminate an instance, theimplementation and the SP interface could be changed in future. The abovesample scripts are based on BTS2K6 and BTS2K6R2
(2) You must modify thescript to provide the BizTalk Host name, the uidInstanceID and uidServiceID ofthe target service instance to the variables @ApplicationName, @uidInstanceIDand @uidServiceID before execute the script.
(3) Stop the running hostinstance before execute the script in order to avoid any inconsistence errorbetween the status of the running instance in the host process memory and thestatus of the instance persisted in the database.
*note* In multiple boxesBizTalk environment, the host instance which an active instance is running incan be found by looking “Processing Server” and “Host” columns of the serviceinstance in BizTalk admin console. The columns for “Processing Server” and“Host” are not listed in the BizTalk group hub UI by default and they can beadded manually.
(4) As you can see inTerminator when use Terminate Instance (Hard), the above script should also beused as a last resort. You should be very clear what you want to do and whatthe impact could be in business before decide to use the script.
4. In BTS2K6 R2 + KB969987 (http://support.microsoft.com/kb/969987) and BTS2K9, it is easierto terminate or suspend such active instance. If you see the instance keepActive with the Pending Operation set after terminate or suspend an activeinstance in BTS2K6 R2 + KB968897 and BTS2K9, simply restart the host instancewhich the target service instance is running with, you will see the Pendingoperation(Terminate or Suspend) got executed immediately after the hostinstance is restarted. This is because that when a host instance is restartedin BTS2K6 R2 + KB969987 or in BTS2K9, it will check if there is a PendingOperation for every service instance which was owned by this host instancepreviously, the Pending Operation for an instance will get executed immediatelyif it is found.