/// <summary>
        /// Realease all the resources associated with the transaction.
        /// </summary>
        public void Unlock(StateManagerTransactionContext transactionContext)
        {
            var lockContext = transactionContext.LockContext;
            var metadata    = this.GetMetadata(lockContext.Key, true);

            if (transactionContext.OperationType == OperationType.Add)
            {
                if (metadata != null)
                {
                    if (metadata.StateProviderId == lockContext.StateProviderId)
                    {
                        if (metadata.TransientCreate)
                        {
                            // Delete lock entry and data.
                            this.Remove(lockContext.Key, transactionContext.TransactionId, Timeout.InfiniteTimeSpan);
                        }
                        else
                        {
                            // successful create.
                            lockContext.Release(transactionContext.TransactionId);

                            FabricEvents.Events.StateProviderMetadataManagerUnlock(
                                this.TraceType,
                                transactionContext.TransactionId);
                        }
                    }
                    else
                    {
                        // creation of a state provider that already exists
                        lockContext.Release(transactionContext.TransactionId);
                    }
                }
                else
                {
                    // metadata has been removed but there is a subsequent add in the same transaction.
                    this.RemoveLock(lockContext, transactionContext.TransactionId);
                }
            }
            else if (transactionContext.OperationType == OperationType.Remove)
            {
                if (metadata != null)
                {
                    if (metadata.StateProviderId == lockContext.StateProviderId)
                    {
                        if (metadata.TransientDelete)
                        {
                            metadata.TransientDelete = false;
                            lockContext.Release(transactionContext.TransactionId);
                            FabricEvents.Events.StateProviderMetadataManagerUnlock(
                                this.TraceType,
                                transactionContext.TransactionId);
                        }
                        else
                        {
                            // Delete got aborted.
                            lockContext.Release(transactionContext.TransactionId);
                        }
                    }
                }
                else if (this.DeletedStateProviders.ContainsKey(lockContext.StateProviderId))
                {
                    // state provider has been deleted (this is used on false progress as well)
                    FabricEvents.Events.StateProviderMetadataManagerUnlockDelete(
                        this.TraceType,
                        lockContext.Key.OriginalString,
                        transactionContext.TransactionId);

                    // data has beeen deleted, delete the lock entry.
                    this.RemoveLock(lockContext, transactionContext.TransactionId);
                }
                else
                {
                    // trying to delete a state provider that does not exist.
                    this.RemoveLock(lockContext, transactionContext.TransactionId);
                }
            }
            else
            {
                Utility.Assert(
                    transactionContext.OperationType == OperationType.Read,
                    "{0}: Unlock: operation type should be a read type. OperationType: {1}",
                    this.traceType,
                    transactionContext.OperationType);

                // Reading a state provider that does not exist
                if (metadata == null)
                {
                    this.RemoveLock(lockContext, transactionContext.TransactionId);
                }
                else
                {
                    transactionContext.LockContext.Release(transactionContext.TransactionId);
                }
            }
        }
 /// <summary>
 /// Release locks.
 /// </summary>
 public void Unlock(StateManagerTransactionContext transactionContext)
 {
     this.MetadataManager.Unlock(transactionContext);
 }