/// <summary> /// Performs the LSM operation on the source shard. /// </summary> /// <param name="ts">Transaction scope.</param> /// <returns>Result of the operation.</returns> public override IStoreResults DoLocalSourceExecute(IStoreTransactionScope ts) { // Now actually update the shard. return(ts.ExecuteOperation( StoreOperationRequestBuilder.SpUpdateShardLocal, StoreOperationRequestBuilder.UpdateShardLocal(this.Id, _shardMap, _shardNew))); }
/// <summary> /// Execute the operation against GSM in the current transaction scope. /// </summary> /// <param name="ts">Transaction scope.</param> /// <returns> /// Results of the operation. /// </returns> public override IStoreResults DoGlobalExecute(IStoreTransactionScope ts) { // If no ranges are specified, blindly mark everything for deletion. return(ts.ExecuteOperation( StoreOperationRequestBuilder.SpGetAllShardMappingsGlobal, StoreOperationRequestBuilder.GetAllShardMappingsGlobal(_shardMap, _shard, _range))); }
/// <summary> /// Asynchronously execute the operation against GSM in the current transaction scope. /// </summary> /// <param name="ts">Transaction scope.</param> /// <returns> /// Task encapsulating results of the operation. /// </returns> public override async Task <IStoreResults> DoGlobalExecuteAsync(IStoreTransactionScope ts) { // If no ranges are specified, blindly mark everything for deletion. return(await ts.ExecuteOperationAsync( StoreOperationRequestBuilder.SpFindShardMappingByKeyGlobal, StoreOperationRequestBuilder.FindShardMappingByKeyGlobal(_shardMap, _key))); }
/// <summary> /// Performs the undo of LSM operation on the source shard. /// </summary> /// <param name="ts">Transaction scope.</param> /// <returns>Result of the operation.</returns> public override IStoreResults UndoLocalSourceExecute(IStoreTransactionScope ts) { // Adds back the removed shard entries. return(ts.ExecuteOperation( StoreOperationRequestBuilder.SpUpdateShardLocal, StoreOperationRequestBuilder.UpdateShardLocal(this.Id, _shardMap, _shardOld))); }
/// <summary> /// Performs the LSM operation on the source shard. /// </summary> /// <param name="ts">Transaction scope.</param> /// <returns>Result of the operation.</returns> public override IStoreResults DoLocalSourceExecute(IStoreTransactionScope ts) { // Now actually add the shard entries. return(ts.ExecuteOperation( StoreOperationRequestBuilder.SpRemoveShardLocal, StoreOperationRequestBuilder.RemoveShardLocal(this.Id, _shardMap, _shard))); }
/// <summary> /// Performs the LSM operation on the source shard. /// </summary> /// <param name="ts">Transaction scope.</param> /// <returns>Result of the operation.</returns> public override IStoreResults DoLocalSourceExecute(IStoreTransactionScope ts) { IStoreResults result; if (_updateLocation) { result = ts.ExecuteOperation( StoreOperationRequestBuilder.SpBulkOperationShardMappingsLocal, StoreOperationRequestBuilder.RemoveShardMappingLocal( this.Id, false, _shardMap, _mappingSource)); } else { result = ts.ExecuteOperation( StoreOperationRequestBuilder.SpBulkOperationShardMappingsLocal, StoreOperationRequestBuilder.UpdateShardMappingLocal( this.Id, false, _shardMap, _mappingSource, _mappingTarget)); } // We need to treat the kill connection operation separately, the reason // being that we cannot perform kill operations within a transaction. if (result.Result == StoreResult.Success && _fromOnlineToOffline) { this.KillConnectionsOnSourceShard(); } return(result); }
/// <summary> /// Execute the operation against GSM in the current transaction scope. /// </summary> /// <param name="ts">Transaction scope.</param> /// <returns> /// Results of the operation. /// </returns> public override IStoreResults DoGlobalExecute(IStoreTransactionScope ts) { return(ts.ExecuteOperation( StoreOperationRequestBuilder.SpLockOrUnLockShardMappingsGlobal, StoreOperationRequestBuilder.LockOrUnLockShardMappingsGlobal( _shardMap, _mapping, _lockOwnerId, _lockOpType))); }
/// <summary> /// Performs the LSM operation on the source shard. /// </summary> /// <param name="ts">Transaction scope.</param> /// <returns>Result of the operation.</returns> public override IStoreResults DoLocalSourceExecute(IStoreTransactionScope ts) { return(ts.ExecuteOperation( StoreOperationRequestBuilder.SpBulkOperationShardMappingsLocal, StoreOperationRequestBuilder.AddShardMappingLocal( this.Id, false, _shardMap, _mapping))); }
/// <summary> /// Performs the LSM operation on the target shard. /// </summary> /// <param name="ts">Transaction scope.</param> /// <returns>Result of the operation.</returns> public override IStoreResults DoLocalTargetExecute(IStoreTransactionScope ts) { Debug.Assert(_updateLocation); return(ts.ExecuteOperation( StoreOperationRequestBuilder.SpBulkOperationShardMappingsLocal, StoreOperationRequestBuilder.AddShardMappingLocal( this.Id, false, _shardMap, _mappingTarget))); }
/// <summary> /// Performs the LSM operation on the source shard. /// </summary> /// <param name="ts">Transaction scope.</param> /// <returns>Result of the operation.</returns> public override IStoreResults DoLocalSourceExecute(IStoreTransactionScope ts) { return(ts.ExecuteOperation( StoreOperationRequestBuilder.SpBulkOperationShardMappingsLocal, StoreOperationRequestBuilder.ReplaceShardMappingsLocal( this.Id, false, _shardMap, _mappingsSource.Select(m => m.Item1).ToArray(), _mappingsTarget.Select(m => m.Item1).ToArray()))); }
/// <summary> /// Performs the undo of GSM operation after LSM operations. /// </summary> /// <param name="ts">Transaction scope.</param> /// <returns>Pending operations on the target objects if any.</returns> public override IStoreResults UndoGlobalPostLocalExecute(IStoreTransactionScope ts) { return(ts.ExecuteOperation( StoreOperationRequestBuilder.SpBulkOperationShardsGlobalEnd, StoreOperationRequestBuilder.RemoveShardGlobal( this.Id, this.OperationCode, true, // undo _shardMap, _shard))); }
/// <summary> /// Execute the operation against GSM in the current transaction scope. /// </summary> /// <param name="ts">Transaction scope.</param> /// <returns> /// Results of the operation. /// </returns> public override IStoreResults DoGlobalExecute(IStoreTransactionScope ts) { IEnumerable <IStoreMapping> mappingsToReplace = this.GetMappingsToPurge(ts); return(ts.ExecuteOperation( StoreOperationRequestBuilder.SpReplaceShardMappingsGlobal, StoreOperationRequestBuilder.ReplaceShardMappingsGlobalWithoutLogging( _shardMap, mappingsToReplace.ToArray(), _mappingsToAdd.ToArray()))); }
/// <summary> /// Performs the initial GSM operation prior to LSM operations. /// </summary> /// <param name="ts">Transaction scope.</param> /// <returns>Pending operations on the target objects if any.</returns> public override IStoreResults DoGlobalPreLocalExecute(IStoreTransactionScope ts) { return(ts.ExecuteOperation( StoreOperationRequestBuilder.SpBulkOperationShardsGlobalBegin, StoreOperationRequestBuilder.AddShardGlobal( this.Id, this.OperationCode, false, // undo _shardMap, _shard))); }
/// <summary> /// Performs the final GSM operation after the LSM operations. /// </summary> /// <param name="ts">Transaction scope.</param> /// <returns>Pending operations on the target objects if any.</returns> public override IStoreResults DoGlobalPostLocalExecute(IStoreTransactionScope ts) { return(ts.ExecuteOperation( StoreOperationRequestBuilder.SpBulkOperationShardsGlobalEnd, StoreOperationRequestBuilder.UpdateShardGlobal( this.Id, this.OperationCode, false, // undo _shardMap, _shardOld, _shardNew))); }
/// <summary> /// Performs the final GSM operation after the LSM operations. /// </summary> /// <param name="ts">Transaction scope.</param> /// <returns>Pending operations on the target objects if any.</returns> public override IStoreResults DoGlobalPostLocalExecute(IStoreTransactionScope ts) { return(ts.ExecuteOperation( StoreOperationRequestBuilder.SpBulkOperationShardMappingsGlobalEnd, StoreOperationRequestBuilder.ReplaceShardMappingsGlobal( this.Id, this.OperationCode, false, // undo _shardMap, _mappingsSource, _mappingsTarget))); }
/// <summary> /// Performs the undo of LSM operation on the source shard. /// </summary> /// <param name="ts">Transaction scope.</param> /// <returns>Result of the operation.</returns> public override IStoreResults UndoLocalSourceExecute(IStoreTransactionScope ts) { DefaultStoreMapping dsmSource = new DefaultStoreMapping( _mappingSource.Id, _shardMap.Id, new DefaultStoreShard( _mappingSource.StoreShard.Id, this.OriginalShardVersionRemoves, _shardMap.Id, _mappingSource.StoreShard.Location, _mappingSource.StoreShard.Status), _mappingSource.MinValue, _mappingSource.MaxValue, _mappingSource.Status, _lockOwnerId); if (_updateLocation) { return(ts.ExecuteOperation( StoreOperationRequestBuilder.SpBulkOperationShardMappingsLocal, StoreOperationRequestBuilder.AddShardMappingLocal( this.Id, true, _shardMap, dsmSource))); } else { DefaultStoreMapping dsmTarget = new DefaultStoreMapping( _mappingTarget.Id, _shardMap.Id, new DefaultStoreShard( _mappingTarget.StoreShard.Id, this.OriginalShardVersionRemoves, _shardMap.Id, _mappingTarget.StoreShard.Location, _mappingTarget.StoreShard.Status), _mappingTarget.MinValue, _mappingTarget.MaxValue, _mappingTarget.Status, _lockOwnerId); return(ts.ExecuteOperation( StoreOperationRequestBuilder.SpBulkOperationShardMappingsLocal, StoreOperationRequestBuilder.UpdateShardMappingLocal( this.Id, true, _shardMap, dsmTarget, dsmSource))); } }
/// <summary> /// Execute the operation against LSM in the current transaction scope. /// </summary> /// <param name="ts">Transaction scope.</param> /// <returns> /// Results of the operation. /// </returns> public override IStoreResults DoLocalExecute(IStoreTransactionScope ts) { IEnumerable <IStoreMapping> mappingsToRemove = this.GetMappingsToPurge(ts); return(ts.ExecuteOperation( StoreOperationRequestBuilder.SpBulkOperationShardMappingsLocal, StoreOperationRequestBuilder.ReplaceShardMappingsLocal( Guid.NewGuid(), // Create a new Guid so that this operation forces over-writes. false, _shardMap, mappingsToRemove.ToArray(), _mappingsToAdd.ToArray()))); }
/// <summary> /// Performs the undo of GSM operation after LSM operations. /// </summary> /// <param name="ts">Transaction scope.</param> /// <returns>Pending operations on the target objects if any.</returns> public override IStoreResults UndoGlobalPostLocalExecute(IStoreTransactionScope ts) { return(ts.ExecuteOperation( StoreOperationRequestBuilder.SpBulkOperationShardMappingsGlobalEnd, StoreOperationRequestBuilder.UpdateShardMappingGlobal( this.Id, this.OperationCode, true, // undo _patternForKill, _shardMap, _mappingSource, _mappingTarget, _lockOwnerId))); }
/// <summary> /// Performs the LSM operation on the source shard. /// </summary> /// <param name="ts">Transaction scope.</param> /// <returns>Result of the operation.</returns> public override IStoreResults DoLocalSourceExecute(IStoreTransactionScope ts) { // There should already be some version of LSM at this location as RecoveryMAnager.AttachShard() first reads existing shard maps from this location. IStoreResults checkResult = ts.ExecuteCommandSingle(SqlUtils.CheckIfExistsLocalScript.Single()); Debug.Assert(checkResult.StoreVersion != null); // Upgrade local shard map to latest version before attaching. ts.ExecuteCommandBatch(SqlUtils.FilterUpgradeCommands(SqlUtils.UpgradeLocalScript, GlobalConstants.LsmVersionClient, checkResult.StoreVersion.Version)); // Now update the shards table in LSM. return(ts.ExecuteOperation( StoreOperationRequestBuilder.SpUpdateShardLocal, StoreOperationRequestBuilder.UpdateShardLocal(this.Id, _shardMap, _shard))); }
/// <summary> /// Performs the undo of LSM operation on the source shard. /// </summary> /// <param name="ts">Transaction scope.</param> /// <returns>Result of the operation.</returns> public override IStoreResults UndoLocalSourceExecute(IStoreTransactionScope ts) { IStoreResults checkResult = ts.ExecuteCommandSingle(SqlUtils.CheckIfExistsLocalScript.Single()); if (checkResult.StoreVersion != null) { // Remove the added shard entries. return(ts.ExecuteOperation( StoreOperationRequestBuilder.SpRemoveShardLocal, StoreOperationRequestBuilder.RemoveShardLocal(this.Id, _shardMap, _shard))); } else { // If version is < 0, then shard never got deployed, consider it a success. return(new SqlResults()); } }
/// <summary> /// Execute the operation against LSM in the current transaction scope. /// </summary> /// <param name="ts">Transaction scope.</param> /// <returns> /// Results of the operation. /// </returns> public override IStoreResults DoLocalExecute(IStoreTransactionScope ts) { IStoreResults result = ts.ExecuteCommandSingle(SqlUtils.CheckIfExistsLocalScript.Single()); if (result.StoreVersion == null) { // Shard not deployed, which is an error condition. throw new ShardManagementException( ShardManagementErrorCategory.Recovery, ShardManagementErrorCode.ShardNotValid, Errors._Recovery_ShardNotValid, this.Location, this.OperationName); } return(ts.ExecuteOperation( StoreOperationRequestBuilder.SpGetAllShardsLocal, StoreOperationRequestBuilder.GetAllShardsLocal())); }
/// <summary> /// Performs the LSM operation on the source shard. /// </summary> /// <param name="ts">Transaction scope.</param> /// <returns>Result of the operation.</returns> public override IStoreResults DoLocalSourceExecute(IStoreTransactionScope ts) { IStoreResults checkResult = ts.ExecuteCommandSingle(SqlUtils.CheckIfExistsLocalScript.Single()); // Shard not already deployed, just need to add the proper entries. if (checkResult.StoreVersion == null) { // create initial version of LSM ts.ExecuteCommandBatch(SqlUtils.CreateLocalScript); // now upgrade LSM to latest version ts.ExecuteCommandBatch(SqlUtils.FilterUpgradeCommands(SqlUtils.UpgradeLocalScript, GlobalConstants.LsmVersionClient)); } // Now actually add the shard entries. return(ts.ExecuteOperation( StoreOperationRequestBuilder.SpAddShardLocal, StoreOperationRequestBuilder.AddShardLocal(this.Id, false, _shardMap, _shard))); }
/// <summary> /// Terminates connection on the source shard object. /// </summary> private void KillConnectionsOnSourceShard() { SqlUtils.WithSqlExceptionHandling(() => { string sourceShardConnectionString = this.GetConnectionStringForShardLocation(_mappingSource.StoreShard.Location); SqlCredential sourceShardSecureCredential = this.GetSecureCredentialForShardLocation(_mappingSource.StoreShard.Location); IStoreResults result; using (IStoreConnection connectionForKill = this.Manager.StoreConnectionFactory.GetConnection( StoreConnectionKind.LocalSource, sourceShardConnectionString, sourceShardSecureCredential)) { connectionForKill.Open(); using (IStoreTransactionScope ts = connectionForKill.GetTransactionScope(StoreTransactionScopeKind.NonTransactional)) { result = ts.ExecuteOperation( StoreOperationRequestBuilder.SpKillSessionsForShardMappingLocal, StoreOperationRequestBuilder.KillSessionsForShardMappingLocal(_patternForKill)); } } if (result.Result != StoreResult.Success) { // Possible errors are: // StoreResult.UnableToKillSessions // StoreResult.StoreVersionMismatch // StoreResult.MissingParametersForStoredProcedure throw StoreOperationErrorHandler.OnShardMapErrorLocal( result, _shardMap, _mappingSource.StoreShard.Location, _errorCategory, StoreOperationErrorHandler.OperationNameFromStoreOperationCode(this.OperationCode), StoreOperationRequestBuilder.SpKillSessionsForShardMappingLocal); } }); }
/// <summary> /// Performs the undo of LSM operation on the source shard. /// </summary> /// <param name="ts">Transaction scope.</param> /// <returns>Result of the operation.</returns> public override IStoreResults UndoLocalSourceExecute(IStoreTransactionScope ts) { DefaultStoreShard dssOriginal = new DefaultStoreShard( _mappingsSource[0].Item1.StoreShard.Id, this.OriginalShardVersionAdds, _mappingsSource[0].Item1.ShardMapId, _mappingsSource[0].Item1.StoreShard.Location, _mappingsSource[0].Item1.StoreShard.Status); DefaultStoreMapping dsmSource = new DefaultStoreMapping( _mappingsSource[0].Item1.Id, _mappingsSource[0].Item1.ShardMapId, dssOriginal, _mappingsSource[0].Item1.MinValue, _mappingsSource[0].Item1.MaxValue, _mappingsSource[0].Item1.Status, _mappingsSource[0].Item2); DefaultStoreMapping dsmTarget = new DefaultStoreMapping( _mappingsTarget[0].Item1.Id, _mappingsTarget[0].Item1.ShardMapId, dssOriginal, _mappingsTarget[0].Item1.MinValue, _mappingsTarget[0].Item1.MaxValue, _mappingsTarget[0].Item1.Status, _mappingsTarget[0].Item2); IStoreMapping[] ms = new[] { dsmSource }; IStoreMapping[] mt = new[] { dsmTarget }; return(ts.ExecuteOperation( StoreOperationRequestBuilder.SpBulkOperationShardMappingsLocal, StoreOperationRequestBuilder.ReplaceShardMappingsLocal( this.Id, true, _shardMap, mt.Concat(_mappingsTarget.Skip(1).Select(m => m.Item1)).ToArray(), ms.Concat(_mappingsSource.Skip(1).Select(m => m.Item1)).ToArray()))); }
/// <summary> /// Execute the operation against GSM in the current transaction scope. /// </summary> /// <param name="ts">Transaction scope.</param> /// <returns> /// Results of the operation. /// </returns> public override IStoreResults DoGlobalExecute(IStoreTransactionScope ts) { _loadResults.Clear(); IStoreResults result = ts.ExecuteOperation( StoreOperationRequestBuilder.SpGetAllShardMapsGlobal, StoreOperationRequestBuilder.GetAllShardMapsGlobal()); if (result.Result == StoreResult.Success) { foreach (IStoreShardMap ssm in result.StoreShardMaps) { _ssmCurrent = ssm; result = ts.ExecuteOperation( StoreOperationRequestBuilder.SpGetAllShardMappingsGlobal, StoreOperationRequestBuilder.GetAllShardMappingsGlobal(ssm, null, null)); if (result.Result == StoreResult.Success) { _loadResults.Add( new LoadResult { ShardMap = ssm, Mappings = result.StoreMappings }); } else if (result.Result != StoreResult.ShardMapDoesNotExist) { // Ignore some possible failures for Load operation and skip failed // shard map caching operations. break; } } } return(result); }
/// <summary> /// Performs undo of LSM operation on the target shard. /// </summary> /// <param name="ts">Transaction scope.</param> /// <returns>Result of the operation.</returns> public override IStoreResults UndoLocalTargetExecute(IStoreTransactionScope ts) { DefaultStoreMapping dsmTarget = new DefaultStoreMapping( _mappingTarget.Id, _shardMap.Id, new DefaultStoreShard( _mappingTarget.StoreShard.Id, this.OriginalShardVersionAdds, _shardMap.Id, _mappingTarget.StoreShard.Location, _mappingTarget.StoreShard.Status), _mappingTarget.MinValue, _mappingTarget.MaxValue, _mappingTarget.Status, _lockOwnerId); return(ts.ExecuteOperation( StoreOperationRequestBuilder.SpBulkOperationShardMappingsLocal, StoreOperationRequestBuilder.RemoveShardMappingLocal( this.Id, true, _shardMap, dsmTarget))); }
/// <summary> /// Execute the operation against LSM in the current transaction scope. /// </summary> /// <param name="ts">Transaction scope.</param> /// <returns> /// Results of the operation. /// </returns> public override IStoreResults DoLocalExecute(IStoreTransactionScope ts) { return(ts.ExecuteOperation( StoreOperationRequestBuilder.SpGetAllShardMappingsLocal, StoreOperationRequestBuilder.GetAllShardMappingsLocal(_shardMap, _shard, _range))); }
/// <summary> /// Execute the operation against GSM in the current transaction scope. /// </summary> /// <param name="ts">Transaction scope.</param> /// <returns> /// Results of the operation. /// </returns> public override IStoreResults DoGlobalExecute(IStoreTransactionScope ts) { return(ts.ExecuteOperation( StoreOperationRequestBuilder.SpRemoveShardMapGlobal, StoreOperationRequestBuilder.RemoveShardMapGlobal(_shardMap))); }
/// <summary> /// Execute the operation against GSM in the current transaction scope. /// </summary> /// <param name="ts">Transaction scope.</param> /// <returns> /// Results of the operation. /// </returns> public override IStoreResults DoGlobalExecute(IStoreTransactionScope ts) { return(ts.ExecuteOperation( StoreOperationRequestBuilder.SpFindShardMapByNameGlobal, StoreOperationRequestBuilder.FindShardMapByNameGlobal(_shardMapName))); }
/// <summary> /// Execute the operation against GSM in the current transaction scope. /// </summary> /// <param name="ts">Transaction scope.</param> /// <returns> /// Results of the operation. /// </returns> public override IStoreResults DoGlobalExecute(IStoreTransactionScope ts) { return(ts.ExecuteOperation( StoreOperationRequestBuilder.SpGetAllShardMapsGlobal, StoreOperationRequestBuilder.GetAllShardMapsGlobal())); }