/// <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.SpFindShardMappingByIdGlobal, StoreOperationRequestBuilder.FindShardMappingByIdGlobal(_shardMap, _mapping)); }
/// <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> /// 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> /// 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) { TraceHelper.Tracer.TraceInfo( TraceSourceConstants.ComponentNames.ShardMapManagerFactory, this.OperationName, "Started upgrading Local Shard Map structures at location {0}", base.Location); Stopwatch stopwatch = Stopwatch.StartNew(); IStoreResults checkResult = ts.ExecuteCommandSingle(SqlUtils.CheckIfExistsLocalScript.Single()); if (checkResult.StoreVersion == null) { // DEVNOTE(apurvs): do we want to throw here if LSM is not already deployed? // deploy initial version of LSM, if not found. ts.ExecuteCommandBatch(SqlUtils.CreateLocalScript); } if (checkResult.StoreVersion == null || checkResult.StoreVersion.Version < _targetVersion) { if (checkResult.StoreVersion == null) ts.ExecuteCommandBatch(SqlUtils.FilterUpgradeCommands(SqlUtils.UpgradeLocalScript, _targetVersion)); else ts.ExecuteCommandBatch(SqlUtils.FilterUpgradeCommands(SqlUtils.UpgradeLocalScript, _targetVersion, checkResult.StoreVersion.Version)); // Read LSM version again after upgrade. checkResult = ts.ExecuteCommandSingle(SqlUtils.CheckIfExistsLocalScript.Single()); stopwatch.Stop(); TraceHelper.Tracer.TraceInfo( TraceSourceConstants.ComponentNames.ShardMapManagerFactory, this.OperationName, "Finished upgrading store at location {0}. Duration: {1}", base.Location, stopwatch.Elapsed); } else { TraceHelper.Tracer.TraceInfo( TraceSourceConstants.ComponentNames.ShardMapManagerFactory, this.OperationName, "Local Shard Map at location {0} has version {1} equal to or higher than Client library version {2}, skipping upgrade.", base.Location, checkResult.StoreVersion, GlobalConstants.GsmVersionClient); } return checkResult; }
/// <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) { TraceHelper.Tracer.TraceInfo( TraceSourceConstants.ComponentNames.ShardMapManagerFactory, this.OperationName, "Started creating Global Shard Map structures."); Stopwatch stopwatch = Stopwatch.StartNew(); IStoreResults checkResult = ts.ExecuteCommandSingle(SqlUtils.CheckIfExistsGlobalScript.Single()); // If we did find some store deployed. if (checkResult.StoreVersion != null) { // DEVNOTE(wbasheer): We need to have a way of erroring out if versions do not match. if (_createMode == ShardMapManagerCreateMode.KeepExisting) { throw new ShardManagementException( ShardManagementErrorCategory.ShardMapManagerFactory, ShardManagementErrorCode.ShardMapManagerStoreAlreadyExists, Errors._Store_ShardMapManager_AlreadyExistsGlobal); } TraceHelper.Tracer.TraceVerbose( TraceSourceConstants.ComponentNames.ShardMapManagerFactory, this.OperationName, "Dropping existing Global Shard Map structures."); ts.ExecuteCommandBatch(SqlUtils.DropGlobalScript); } // Deploy initial version and run upgrade script to bring it to the specified version. ts.ExecuteCommandBatch(SqlUtils.CreateGlobalScript); ts.ExecuteCommandBatch(SqlUtils.FilterUpgradeCommands(SqlUtils.UpgradeGlobalScript, _targetVersion)); stopwatch.Stop(); TraceHelper.Tracer.TraceInfo( TraceSourceConstants.ComponentNames.ShardMapManagerFactory, this.OperationName, "Finished creating Global Shard Map structures. Duration: {0}", stopwatch.Elapsed); 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> /// 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); } Debug.Assert(result.Result == StoreResult.Success); 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) { TraceHelper.Tracer.TraceInfo( TraceSourceConstants.ComponentNames.ShardMapManagerFactory, this.OperationName, "Started upgrading Global Shard Map structures."); IStoreResults checkResult = ts.ExecuteCommandSingle(SqlUtils.CheckIfExistsGlobalScript.Single()); Debug.Assert(checkResult.StoreVersion != null, "GSM store structures not found."); if (checkResult.StoreVersion.Version < _targetVersion) { Stopwatch stopwatch = Stopwatch.StartNew(); ts.ExecuteCommandBatch(SqlUtils.FilterUpgradeCommands(SqlUtils.UpgradeGlobalScript, _targetVersion, checkResult.StoreVersion.Version)); // read GSM version after upgrade. checkResult = ts.ExecuteCommandSingle(SqlUtils.CheckIfExistsGlobalScript.Single()); // DEVNOTE(apurvs): verify (checkResult.StoreVersion == GlobalConstants.GsmVersionClient) and throw on failure. stopwatch.Stop(); TraceHelper.Tracer.TraceInfo( TraceSourceConstants.ComponentNames.ShardMapManagerFactory, this.OperationName, "Finished upgrading Global Shard Map. Duration: {0}", stopwatch.Elapsed); } else { TraceHelper.Tracer.TraceInfo( TraceSourceConstants.ComponentNames.ShardMapManagerFactory, this.OperationName, "Global Shard Map is at a version {0} equal to or higher than Client library version {1}, skipping upgrade.", (checkResult.StoreVersion == null) ? "" : checkResult.StoreVersion.Version.ToString(), GlobalConstants.GsmVersionClient); } return checkResult; }
/// <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) { IStoreResults result = ts.ExecuteCommandSingle(SqlUtils.CheckIfExistsGlobalScript.Single()); SqlResults returnedResult = new SqlResults(); // If we did not find some store deployed. if (result.StoreVersion == null) { returnedResult.Result = StoreResult.Failure; } else { // DEVNOTE(wbasheer): We need to have a way of erroring out if versions do not match. // we can potentially call upgrade here to get to latest version. Should this be exposed as a new parameter ? returnedResult.Result = StoreResult.Success; } return returnedResult; }
/// <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> /// Sets the stub of StoreOperation.UndoLocalTargetExecute(IStoreTransactionScope ts) /// </summary> public override IStoreResults UndoLocalTargetExecute(IStoreTransactionScope ts) { Func<IStoreTransactionScope, IStoreResults> func1 = this.UndoLocalTargetExecuteIStoreTransactionScope; if (func1 != null) return func1(ts); if (this.___callBase) return base.UndoLocalTargetExecute(ts); return this.InstanceBehavior.Result<StubReplaceMappingsOperation, IStoreResults>(this, "UndoLocalTargetExecute"); }
/// <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> /// 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 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))); }
public virtual IStoreResults UndoGlobalPostLocalExecute(IStoreTransactionScope ts) { return this.inner.UndoGlobalPostLocalExecute(ts); }
/// <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 abstract IStoreResults UndoGlobalPostLocalExecute(IStoreTransactionScope ts);
/// <summary> /// Finds all mappings to be purged based on the given input ranges. /// </summary> /// <param name="ts">GSM transaction scope.</param> /// <returns>Mappings which are to be removed.</returns> private IEnumerable <IStoreMapping> GetMappingsToPurge(IStoreTransactionScope ts) { // Find all the mappings in GSM belonging to the shard IStoreResults gsmMappingsByShard = ts.ExecuteOperation( StoreOperationRequestBuilder.SpGetAllShardMappingsGlobal, StoreOperationRequestBuilder.GetAllShardMappingsGlobal(_shardMap, _shard, null)); if (gsmMappingsByShard.Result != StoreResult.Success) { // Possible errors are: // StoreResult.ShardMapDoesNotExist // StoreResult.StoreVersionMismatch // StoreResult.MissingParametersForStoredProcedure throw StoreOperationErrorHandler.OnRecoveryErrorGlobal( gsmMappingsByShard, _shardMap, _shard, ShardManagementErrorCategory.Recovery, this.OperationName, StoreOperationRequestBuilder.SpGetAllShardMappingsGlobal); } IDictionary <ShardRange, IStoreMapping> intersectingMappings = new Dictionary <ShardRange, IStoreMapping>(); foreach (IStoreMapping gsmMappingByShard in gsmMappingsByShard.StoreMappings) { ShardKey min = ShardKey.FromRawValue( _shardMap.KeyType, gsmMappingByShard.MinValue); ShardKey max = null; switch (_shardMap.MapType) { case ShardMapType.Range: max = ShardKey.FromRawValue( _shardMap.KeyType, gsmMappingByShard.MaxValue); break; default: Debug.Assert(_shardMap.MapType == ShardMapType.List); max = ShardKey.FromRawValue( _shardMap.KeyType, gsmMappingByShard.MinValue).GetNextKey(); break; } intersectingMappings.Add(new ShardRange(min, max), gsmMappingByShard); } // We need to discover, also, the range of intersecting mappings, so we can transitively detect // inconsistencies with other shards. foreach (IStoreMapping lsmMapping in _mappingsToRemove) { ShardKey min = ShardKey.FromRawValue(_shardMap.KeyType, lsmMapping.MinValue); IStoreResults gsmMappingsByRange; switch (_shardMap.MapType) { case ShardMapType.Range: gsmMappingsByRange = ts.ExecuteOperation( StoreOperationRequestBuilder.SpGetAllShardMappingsGlobal, StoreOperationRequestBuilder.GetAllShardMappingsGlobal( _shardMap, null, new ShardRange( min, ShardKey.FromRawValue(_shardMap.KeyType, lsmMapping.MaxValue)))); break; default: Debug.Assert(_shardMap.MapType == ShardMapType.List); gsmMappingsByRange = ts.ExecuteOperation( StoreOperationRequestBuilder.SpFindShardMappingByKeyGlobal, StoreOperationRequestBuilder.FindShardMappingByKeyGlobal( _shardMap, min)); break; } if (gsmMappingsByRange.Result != StoreResult.Success) { if (gsmMappingsByRange.Result != StoreResult.MappingNotFoundForKey) { // Possible errors are: // StoreResult.ShardMapDoesNotExist // StoreResult.StoreVersionMismatch // StoreResult.MissingParametersForStoredProcedure throw StoreOperationErrorHandler.OnRecoveryErrorGlobal( gsmMappingsByRange, _shardMap, _shard, ShardManagementErrorCategory.Recovery, this.OperationName, _shardMap.MapType == ShardMapType.Range ? StoreOperationRequestBuilder.SpGetAllShardMappingsGlobal : StoreOperationRequestBuilder.SpFindShardMappingByKeyGlobal); } else { // No intersections being found is fine. Skip to the next mapping. Debug.Assert(_shardMap.MapType == ShardMapType.List); } } else { foreach (IStoreMapping gsmMappingByRange in gsmMappingsByRange.StoreMappings) { ShardKey minGlobal = ShardKey.FromRawValue(_shardMap.KeyType, gsmMappingByRange.MinValue); ShardKey maxGlobal = null; switch (_shardMap.MapType) { case ShardMapType.Range: maxGlobal = ShardKey.FromRawValue(_shardMap.KeyType, gsmMappingByRange.MaxValue); break; default: Debug.Assert(_shardMap.MapType == ShardMapType.List); maxGlobal = ShardKey.FromRawValue(_shardMap.KeyType, gsmMappingByRange.MinValue).GetNextKey(); break; } intersectingMappings[new ShardRange(minGlobal, maxGlobal)] = gsmMappingByRange; } } } return(intersectingMappings.Values); }
/// <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.SpGetAllDistinctShardLocationsGlobal, StoreOperationRequestBuilder.GetAllDistinctShardLocationsGlobal())); }
/// <summary> /// Finds all mappings to be purged based on the given input ranges. /// </summary> /// <param name="ts">LSM transaction scope.</param> /// <returns>Mappings which are to be removed.</returns> private IEnumerable <IStoreMapping> GetMappingsToPurge(IStoreTransactionScope ts) { IEnumerable <IStoreMapping> lsmMappings = null; IStoreResults result; if (_rangesToRemove == null) { // If no ranges are specified, get all the mappings for the shard. result = ts.ExecuteOperation( StoreOperationRequestBuilder.SpGetAllShardMappingsLocal, StoreOperationRequestBuilder.GetAllShardMappingsLocal(_shardMap, _shard, null)); if (result.Result != StoreResult.Success) { // Possible errors are: // StoreResult.ShardMapDoesNotExist // StoreResult.StoreVersionMismatch // StoreResult.MissingParametersForStoredProcedure throw StoreOperationErrorHandler.OnRecoveryErrorLocal( result, _shardMap, this.Location, ShardManagementErrorCategory.Recovery, this.OperationName, StoreOperationRequestBuilder.SpGetAllShardMappingsLocal); } lsmMappings = result.StoreMappings; } else { // If any ranges are specified, only delete intersected ranges. IDictionary <ShardRange, IStoreMapping> mappingsToPurge = new Dictionary <ShardRange, IStoreMapping>(); foreach (ShardRange range in _rangesToRemove) { switch (_shardMap.MapType) { case ShardMapType.Range: result = ts.ExecuteOperation( StoreOperationRequestBuilder.SpGetAllShardMappingsLocal, StoreOperationRequestBuilder.GetAllShardMappingsLocal( _shardMap, _shard, range)); break; default: Debug.Assert(_shardMap.MapType == ShardMapType.List); result = ts.ExecuteOperation( StoreOperationRequestBuilder.SpFindShardMappingByKeyLocal, StoreOperationRequestBuilder.FindShardMappingByKeyLocal( _shardMap, ShardKey.FromRawValue(_shardMap.KeyType, range.Low.RawValue))); break; } if (result.Result != StoreResult.Success) { if (result.Result != StoreResult.MappingNotFoundForKey) { // Possible errors are: // StoreResult.ShardMapDoesNotExist // StoreResult.StoreVersionMismatch // StoreResult.MissingParametersForStoredProcedure throw StoreOperationErrorHandler.OnRecoveryErrorLocal( result, _shardMap, this.Location, ShardManagementErrorCategory.Recovery, this.OperationName, _shardMap.MapType == ShardMapType.Range ? StoreOperationRequestBuilder.SpGetAllShardMappingsLocal : StoreOperationRequestBuilder.SpFindShardMappingByKeyLocal); } else { // No intersections being found is fine. Skip to the next mapping. Debug.Assert(_shardMap.MapType == ShardMapType.List); } } else { foreach (IStoreMapping mapping in result.StoreMappings) { ShardRange intersectedRange = new ShardRange( ShardKey.FromRawValue(_shardMap.KeyType, mapping.MinValue), ShardKey.FromRawValue(_shardMap.KeyType, mapping.MaxValue)); mappingsToPurge[intersectedRange] = mapping; } } } lsmMappings = mappingsToPurge.Values; } return(lsmMappings); }
public virtual IStoreResults DoLocalTargetExecute(IStoreTransactionScope ts) { return(this.inner.DoLocalTargetExecute(ts)); }
public virtual IStoreResults UndoLocalSourceExecute(IStoreTransactionScope ts) { return(this.inner.UndoLocalSourceExecute(ts)); }
/// <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 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.SpAddShardMapGlobal, StoreOperationRequestBuilder.AddShardMapGlobal(_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.SpUpdateShardingSchemaInfoGlobal, StoreOperationRequestBuilder.UpdateShardingSchemaInfoGlobal(_schemaInfo))); }
/// <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 virtual Task <IStoreResults> DoGlobalExecuteAsync(IStoreTransactionScope ts) { // Currently only implemented by FindMappingByKeyGlobalOperation throw new NotImplementedException(); }
/// <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.SpFindShardByLocationGlobal, StoreOperationRequestBuilder.FindShardByLocationGlobal(_shardMap, _location))); }
/// <summary> /// Performs the store operation. /// </summary> /// <returns>Results of the operation.</returns> public IStoreResults Do() { IStoreResults result; try { do { result = _retryPolicy.ExecuteAction(() => { IStoreResults r; try { // Open connection. this.EstablishConnnection(); using (IStoreTransactionScope ts = this.GetTransactionScope()) { r = this.DoGlobalExecute(ts); ts.Success = r.Result == StoreResult.Success; } if (!r.StoreOperations.Any()) { if (r.Result != StoreResult.Success) { this.DoGlobalUpdateCachePre(r); this.HandleDoGlobalExecuteError(r); } this.DoGlobalUpdateCachePost(r); } return(r); } finally { // Close connection. this.TeardownConnection(); } }); // If pending operation, deserialize the pending operation and perform Undo. if (result.StoreOperations.Any()) { Debug.Assert(result.StoreOperations.Count() == 1); this.UndoPendingStoreOperations(result.StoreOperations.Single()); } }while (result.StoreOperations.Any()); } catch (StoreException se) { throw this.OnStoreException(se); } Debug.Assert(result != null); return(result); }
public virtual IStoreResults UndoLocalSourceExecute(IStoreTransactionScope ts) { return this.inner.UndoLocalSourceExecute(ts); }
/// <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) { // as part of local source execute step, we just update shard location to reflect correct // servername and database name, so there is no need to undo that action. return(new SqlResults()); }
/// <summary> /// Finds all mappings to be purged based on the given input ranges. /// </summary> /// <param name="ts">LSM transaction scope.</param> /// <returns>Mappings which are to be removed.</returns> private IEnumerable<IStoreMapping> GetMappingsToPurge(IStoreTransactionScope ts) { IEnumerable<IStoreMapping> lsmMappings = null; IStoreResults result; if (_rangesToRemove == null) { // If no ranges are specified, get all the mappings for the shard. result = ts.ExecuteOperation( StoreOperationRequestBuilder.SpGetAllShardMappingsLocal, StoreOperationRequestBuilder.GetAllShardMappingsLocal(_shardMap, _shard, null)); if (result.Result != StoreResult.Success) { // Possible errors are: // StoreResult.ShardMapDoesNotExist // StoreResult.StoreVersionMismatch // StoreResult.MissingParametersForStoredProcedure throw StoreOperationErrorHandler.OnRecoveryErrorLocal( result, _shardMap, this.Location, ShardManagementErrorCategory.Recovery, this.OperationName, StoreOperationRequestBuilder.SpGetAllShardMappingsLocal); } lsmMappings = result.StoreMappings; } else { // If any ranges are specified, only delete intersected ranges. IDictionary<ShardRange, IStoreMapping> mappingsToPurge = new Dictionary<ShardRange, IStoreMapping>(); foreach (ShardRange range in _rangesToRemove) { switch (_shardMap.MapType) { case ShardMapType.Range: result = ts.ExecuteOperation( StoreOperationRequestBuilder.SpGetAllShardMappingsLocal, StoreOperationRequestBuilder.GetAllShardMappingsLocal( _shardMap, _shard, range)); break; default: Debug.Assert(_shardMap.MapType == ShardMapType.List); result = ts.ExecuteOperation( StoreOperationRequestBuilder.SpFindShardMappingByKeyLocal, StoreOperationRequestBuilder.FindShardMappingByKeyLocal( _shardMap, ShardKey.FromRawValue(_shardMap.KeyType, range.Low.RawValue))); break; } if (result.Result != StoreResult.Success) { if (result.Result != StoreResult.MappingNotFoundForKey) { // Possible errors are: // StoreResult.ShardMapDoesNotExist // StoreResult.StoreVersionMismatch // StoreResult.MissingParametersForStoredProcedure throw StoreOperationErrorHandler.OnRecoveryErrorLocal( result, _shardMap, this.Location, ShardManagementErrorCategory.Recovery, this.OperationName, _shardMap.MapType == ShardMapType.Range ? StoreOperationRequestBuilder.SpGetAllShardMappingsLocal : StoreOperationRequestBuilder.SpFindShardMappingByKeyLocal); } else { // No intersections being found is fine. Skip to the next mapping. Debug.Assert(_shardMap.MapType == ShardMapType.List); } } else { foreach (IStoreMapping mapping in result.StoreMappings) { ShardRange intersectedRange = new ShardRange( ShardKey.FromRawValue(_shardMap.KeyType, mapping.MinValue), ShardKey.FromRawValue(_shardMap.KeyType, mapping.MaxValue)); mappingsToPurge[intersectedRange] = mapping; } } } lsmMappings = mappingsToPurge.Values; } return lsmMappings; }
/// <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> /// 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)); }
public override IStoreResults DoLocalTargetExecute(IStoreTransactionScope ts) { SqlResults results = new SqlResults(); return results; }
/// <summary> /// Sets the stub of AddMappingOperation.DoLocalSourceExecute(IStoreTransactionScope ts) /// </summary> public override IStoreResults DoLocalSourceExecute(IStoreTransactionScope ts) { Func<IStoreTransactionScope, IStoreResults> func1 = this.DoLocalSourceExecuteIStoreTransactionScope; if (func1 != null) return func1(ts); if (this.___callBase) return base.DoLocalSourceExecute(ts); return this.InstanceBehavior.Result<StubAddMappingOperation, IStoreResults>(this, "DoLocalSourceExecute"); }
/// <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> /// 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> /// 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.AddShardMappingGlobal( this.Id, this.OperationCode, true, // undo _shardMap, _mapping)); }
/// <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> /// 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.SpDetachShardGlobal, StoreOperationRequestBuilder.DetachShardGlobal(_shardMapName, _location))); }
/// <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.SpGetAllShardingSchemaInfosGlobal, StoreOperationRequestBuilder.GetAllShardingSchemaInfosGlobal())); }
public virtual IStoreResults UndoGlobalPostLocalExecute(IStoreTransactionScope ts) { return(this.inner.UndoGlobalPostLocalExecute(ts)); }
public override IStoreResults DoGlobalPostLocalExecute(IStoreTransactionScope ts) { if (_currentFailureCount < _failureCountMax) { _currentFailureCount++; throw new StoreException("", TransientSqlException); } else { return base.DoGlobalPostLocalExecute(ts); } }
/// <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 abstract IStoreResults DoGlobalPreLocalExecute(IStoreTransactionScope ts);
public override IStoreResults DoGlobalPostLocalExecute(IStoreTransactionScope ts) { SqlResults results = new SqlResults(); return results; }
/// <summary> /// Performs undo of LSM operation on the target shard. /// </summary> /// <param name="ts">Transaction scope.</param> /// <returns>Result of the operation.</returns> public virtual IStoreResults UndoLocalTargetExecute(IStoreTransactionScope ts) { return(new SqlResults()); }
/// <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 dsm = new DefaultStoreMapping( _mapping.Id, _shardMap.Id, new DefaultStoreShard( _mapping.StoreShard.Id, this.OriginalShardVersionAdds, _shardMap.Id, _mapping.StoreShard.Location, _mapping.StoreShard.Status), _mapping.MinValue, _mapping.MaxValue, _mapping.Status, default(Guid)); return ts.ExecuteOperation( StoreOperationRequestBuilder.SpBulkOperationShardMappingsLocal, StoreOperationRequestBuilder.RemoveShardMappingLocal( this.Id, true, _shardMap, dsm)); }
/// <summary> /// Performs the undo of GSM operation prior to LSM operations. /// </summary> /// <param name="ts">Transaction scope.</param> /// <returns>Result of the operation.</returns> public virtual IStoreResults UndoGlobalPreLocalExecute(IStoreTransactionScope ts) { return(ts.ExecuteOperation( StoreOperationRequestBuilder.SpFindAndUpdateOperationLogEntryByIdGlobal, StoreOperationRequestBuilder.FindAndUpdateOperationLogEntryByIdGlobal(this.Id, this.UndoStartState))); }
/// <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.SpGetAllShardingSchemaInfosGlobal, StoreOperationRequestBuilder.GetAllShardingSchemaInfosGlobal()); }
/// <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 abstract IStoreResults UndoLocalSourceExecute(IStoreTransactionScope ts);