/// <summary>
        /// Constructs request to lock or unlock given mappings in GSM.
        /// </summary>
        /// <param name="shardMapManager">Shard map manager object.</param>
        /// <param name="operationName">Operation name, useful for diagnostics.</param>
        /// <param name="shardMap">Shard map to add.</param>
        /// <param name="mapping">Mapping to lock or unlock. Null means all mappings.</param>
        /// <param name="lockOwnerId">Lock owner.</param>
        /// <param name="lockOpType">Lock operation type.</param>
        /// <param name="errorCategory">Error category.</param>
        internal LockOrUnLockMappingsGlobalOperation(ShardMapManager shardMapManager, string operationName, IStoreShardMap shardMap, IStoreMapping mapping, Guid lockOwnerId, LockOwnerIdOpType lockOpType, ShardManagementErrorCategory errorCategory) :
            base(shardMapManager.Credentials, shardMapManager.RetryPolicy, operationName)
        {
            _shardMapManager = shardMapManager;
            _shardMap = shardMap;
            _mapping = mapping;
            _lockOwnerId = lockOwnerId;
            _lockOpType = lockOpType;
            _errorCategory = errorCategory;

            Debug.Assert(mapping != null || (lockOpType == LockOwnerIdOpType.UnlockAllMappingsForId || lockOpType == LockOwnerIdOpType.UnlockAllMappings));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Constructs request to lock or unlock given mappings in GSM.
        /// </summary>
        /// <param name="shardMapManager">Shard map manager object.</param>
        /// <param name="operationName">Operation name, useful for diagnostics.</param>
        /// <param name="shardMap">Shard map to add.</param>
        /// <param name="mapping">Mapping to lock or unlock. Null means all mappings.</param>
        /// <param name="lockOwnerId">Lock owner.</param>
        /// <param name="lockOpType">Lock operation type.</param>
        /// <param name="errorCategory">Error category.</param>
        internal LockOrUnLockMappingsGlobalOperation(ShardMapManager shardMapManager, string operationName, IStoreShardMap shardMap, IStoreMapping mapping, Guid lockOwnerId, LockOwnerIdOpType lockOpType, ShardManagementErrorCategory errorCategory) :
            base(shardMapManager.Credentials, shardMapManager.RetryPolicy, operationName)
        {
            _shardMapManager = shardMapManager;
            _shardMap        = shardMap;
            _mapping         = mapping;
            _lockOwnerId     = lockOwnerId;
            _lockOpType      = lockOpType;
            _errorCategory   = errorCategory;

            Debug.Assert(mapping != null || (lockOpType == LockOwnerIdOpType.UnlockAllMappingsForId || lockOpType == LockOwnerIdOpType.UnlockAllMappings));
        }
 /// <summary>
 /// Constructs request to lock or unlock given mappings in GSM.
 /// </summary>
 /// <param name="shardMapManager">Shard map manager object.</param>
 /// <param name="operationName">Operation name, useful for diagnostics.</param>
 /// <param name="shardMap">Shard map to add.</param>
 /// <param name="mapping">Mapping to lock or unlock. Null means all mappings.</param>
 /// <param name="lockOwnerId">Lock owner.</param>
 /// <param name="lockOpType">Lock operation type.</param>
 /// <param name="errorCategory">Error category.</param>
 /// <returns>The store operation.</returns>
 public virtual IStoreOperationGlobal CreateLockOrUnLockMappingsGlobalOperation(
     ShardMapManager shardMapManager,
     string operationName,
     IStoreShardMap shardMap,
     IStoreMapping mapping,
     Guid lockOwnerId,
     LockOwnerIdOpType lockOpType,
     ShardManagementErrorCategory errorCategory)
 {
     return(new LockOrUnLockMappingsGlobalOperation(
                shardMapManager,
                operationName,
                shardMap,
                mapping,
                lockOwnerId,
                lockOpType,
                errorCategory));
 }
Ejemplo n.º 4
0
 internal void LockOrUnlockMappings(RangeMapping <TKey> mapping, Guid lockOwnerId, LockOwnerIdOpType lockOwnerIdOpType)
 {
     this.LockOrUnlockMappings <RangeMapping <TKey> >(
         mapping,
         lockOwnerId,
         lockOwnerIdOpType,
         ShardManagementErrorCategory.RangeShardMap);
 }
Ejemplo n.º 5
0
        internal void LockOrUnlockMappings <TMapping>(TMapping mapping, Guid lockOwnerId, LockOwnerIdOpType lockOwnerIdOpType, ShardManagementErrorCategory errorCategory) where TMapping : class, IShardProvider, IMappingInfoProvider
        {
            string operationName = lockOwnerIdOpType == LockOwnerIdOpType.Lock ? "Lock" : "UnLock";

            if (lockOwnerIdOpType != LockOwnerIdOpType.UnlockAllMappingsForId && lockOwnerIdOpType != LockOwnerIdOpType.UnlockAllMappings)
            {
                this.EnsureMappingBelongsToShardMap <TMapping>(mapping, operationName, "mapping");

                if (lockOwnerIdOpType == LockOwnerIdOpType.Lock &&
                    lockOwnerId == MappingLockToken.ForceUnlock.LockOwnerId)
                {
                    throw new ArgumentException(
                              StringUtils.FormatInvariant(
                                  Errors._ShardMapping_LockIdNotSupported,
                                  mapping.ShardInfo.Location,
                                  this.ShardMap.Name,
                                  lockOwnerId),
                              "lockOwnerId");
                }
            }
            else
            {
                Debug.Assert(mapping == null);
            }

            using (IStoreOperationGlobal op = this.Manager.StoreOperationFactory.CreateLockOrUnLockMappingsGlobalOperation(
                       this.Manager,
                       operationName,
                       this.ShardMap.StoreShardMap,
                       mapping != null ? mapping.StoreMapping : null,
                       lockOwnerId,
                       lockOwnerIdOpType,
                       errorCategory))
            {
                op.Do();
            }
        }
 /// <summary>
 /// Constructs request to lock or unlock given mappings in GSM.
 /// </summary>
 /// <param name="shardMapManager">Shard map manager object.</param>
 /// <param name="operationName">Operation name, useful for diagnostics.</param>
 /// <param name="shardMap">Shard map to add.</param>
 /// <param name="mapping">Mapping to lock or unlock. Null means all mappings.</param>
 /// <param name="lockOwnerId">Lock owner.</param>
 /// <param name="lockOpType">Lock operation type.</param>
 /// <param name="errorCategory">Error category.</param>
 /// <returns>The store operation.</returns>
 public virtual IStoreOperationGlobal CreateLockOrUnLockMappingsGlobalOperation(
     ShardMapManager shardMapManager,
     string operationName,
     IStoreShardMap shardMap,
     IStoreMapping mapping,
     Guid lockOwnerId,
     LockOwnerIdOpType lockOpType,
     ShardManagementErrorCategory errorCategory)
 {
     return new LockOrUnLockMappingsGlobalOperation(
         shardMapManager,
         operationName,
         shardMap,
         mapping,
         lockOwnerId,
         lockOpType,
         errorCategory);
 }
 /// <summary>
 /// Request to lock or unlock mappings in GSM.
 /// </summary>
 /// <param name="shardMap">Shard map whose mappings are being requested.</param>
 /// <param name="mapping">Mapping being locked or unlocked.</param>
 /// <param name="lockId">Lock Id.</param>
 /// <param name="lockOpType">Lock operation code.</param>
 /// <returns>Xml formatted request.</returns>
 internal static XElement LockOrUnLockShardMappingsGlobal(
     IStoreShardMap shardMap,
     IStoreMapping mapping,
     Guid lockId,
     LockOwnerIdOpType lockOpType)
 {
     Debug.Assert(mapping != null || (lockOpType == LockOwnerIdOpType.UnlockAllMappingsForId || lockOpType == LockOwnerIdOpType.UnlockAllMappings));
     return new XElement(
         @"LockOrUnlockShardMappingsGlobal",
         StoreOperationRequestBuilder.s_gsmVersion,
         StoreObjectFormatterXml.WriteIStoreShardMap("ShardMap", shardMap),
         mapping == null ? null : StoreObjectFormatterXml.WriteIStoreMapping("Mapping", mapping),
         new XElement("Lock",
             new XElement("Id", lockId),
             new XElement("Operation", (int)lockOpType)));
 }
 /// <summary>
 /// Sets the stub of StoreOperationFactory.CreateLockOrUnLockMappingsGlobalOperation(ShardMapManager shardMapManager, String operationName, IStoreShardMap shardMap, IStoreMapping mapping, Guid lockOwnerId, LockOwnerIdOpType lockOpType, ShardManagementErrorCategory errorCategory)
 /// </summary>
 public override IStoreOperationGlobal CreateLockOrUnLockMappingsGlobalOperation(ShardMapManager shardMapManager, string operationName, IStoreShardMap shardMap, IStoreMapping mapping, Guid lockOwnerId, LockOwnerIdOpType lockOpType, ShardManagementErrorCategory errorCategory)
 {
     Func<ShardMapManager, string, IStoreShardMap, IStoreMapping, Guid, LockOwnerIdOpType, ShardManagementErrorCategory, IStoreOperationGlobal> func1 = this.CreateLockOrUnLockMappingsGlobalOperationShardMapManagerStringIStoreShardMapIStoreMappingGuidLockOwnerIdOpTypeShardManagementErrorCategory;
     if (func1 != null)
         return func1(shardMapManager, operationName, shardMap, mapping, lockOwnerId, lockOpType, errorCategory);
     if (this.___callBase)
         return base.CreateLockOrUnLockMappingsGlobalOperation(shardMapManager, operationName, shardMap, mapping, lockOwnerId, lockOpType, errorCategory);
     return this.InstanceBehavior.Result<StubStoreOperationFactory, IStoreOperationGlobal>(this, "CreateLockOrUnLockMappingsGlobalOperation");
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Locks or unlocks the given range mapping
        /// </summary>
        /// <param name="ssm">Shard map to add mapping to.</param>
        /// <param name="sm">Shard mapping to store.</param>
        /// <param name="lockOwnerId">The lock owner id of this mapping</param>
        /// <param name="lockOwnerIdOpType">Operation to perform on this mapping with the given lockOwnerId</param>
        /// <returns></returns>
        public virtual IStoreResults LockOrUnlockRangeMappingGlobal(IStoreShardMap ssm, IStoreMapping sm, Guid lockOwnerId, LockOwnerIdOpType lockOwnerIdOpType)
        {
            try
            {
                SqlResults result = new SqlResults();

                using (SqlCommand cmd = SqlTransactionScopeGlobal.CreateSqlCommand())
                {
                    cmd.CommandText = @"__ShardManagement.smm_lockOrUnlockShardMappingGlobal";
                    cmd.CommandType = CommandType.StoredProcedure;

                    XElement input = new XElement(cmd.CommandText,
                        new XElement("gsm_version", SqlStoreGsmVersion.ToString()),
                        new XElement("m_id", sm.Id.ToString()),
                        new XElement("sm_id", sm.ShardMapId.ToString()),
                        new XElement("lo_id", lockOwnerId.ToString()),
                        new XElement("s_id", sm.StoreShard.Id.ToString()),
                        new XElement("m_version", sm.Version.ToString()),
                        new XElement("sm_version", ssm.Version.ToString()),
                        new XElement("lo_id_op_type", (int)lockOwnerIdOpType));

                    SqlStore.AddCommandParameter(cmd, "@input", SqlDbType.Xml, ParameterDirection.Input, 0, input.ToString());
                    SqlParameter resultParam = SqlStore.AddCommandParameter(cmd, "@result", SqlDbType.Int, ParameterDirection.Output, 0, 0);

                    using (SqlDataReader reader = cmd.ExecuteReader())
                    {
                        result.Fetch(reader);
                    }

                    // Output parameter will be used to specify the outcome.
                    result.Result = (StoreResult)resultParam.Value;
                }

                return result;
            }
            catch (SqlException se)
            {
                throw new StoreException(
                    Errors.SqlStore_UpdateMappingGlobal_SqlException,
                    se,
                    "LockOrUnlockMapping",
                    sm.StoreShard.Location,
                    ssm.Name);
            }
        }