/// <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> /// 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> /// 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); }