public void TestRoundRobinPartitionAssign(int delay) { var nodeMock = new NodeMock(); var partitions = new[] { new Partition { Id = 0, Leader = nodeMock }, new Partition { Id = 1, Leader = nodeMock }, new Partition { Id = 2, Leader = nodeMock }, new Partition { Id = 3, Leader = nodeMock }, new Partition { Id = 4, Leader = nodeMock }, }; var partitionStrategy = new RoundRobinPartitionSelection(delay); var partitioner = new PartitionSelector(partitionStrategy); delay = delay <= 0 ? 1 : delay; foreach (var partition in partitions) { for (var j = 0; j < delay; ++j) { Assert.AreEqual(partition.Id, partitioner .GetPartition(ProduceMessage.New(string.Empty, Partitions.Any, new Message(), new DateTime()), partitions) .Id); } } }
protected PartitionSelector GetPartitionSelector() { if (this.ParameterSetName == "PartitionId") { return(PartitionSelector.PartitionIdOf(this.ServiceName, this.PartitionId)); } else { switch (this.ParameterSetName) { case "ServiceNameRandomPartition": return(PartitionSelector.RandomOf(this.ServiceName)); case "ServiceNamePartitionSingleton": return(PartitionSelector.SingletonOf(this.ServiceName)); case "ServiceNamePartitionNamed": return(PartitionSelector.PartitionKeyOf(this.ServiceName, this.PartitionKey)); case "ServiceNamePartitionUniformedInt": long partitionKeyLong; if (!long.TryParse(this.PartitionKey, out partitionKeyLong)) { throw new ArgumentException(StringResources.Error_InvalidPartitionKey); } return(PartitionSelector.PartitionKeyOf(this.ServiceName, partitionKeyLong)); default: throw new ArgumentException(StringResources.Error_CouldNotParsePartitionSelector); } } }
public void Test_MessageKeyPartitionSelection_Fallbacks_To_RoundRobin_If_MessageKey_Null() { var nodeMock = new NodeMock(); var partitions = new[] { new Partition { Id = 0, Leader = nodeMock }, new Partition { Id = 1, Leader = nodeMock }, new Partition { Id = 2, Leader = nodeMock }, }; var partitionStrategy = new MessageKeyPartitionSelection(Serializer, RoundRobinPartitionSelection, Mock.Of <ILogger>()); var partitioner = new PartitionSelector(partitionStrategy); var message = ProduceMessage.New(string.Empty, Partitions.Any, new Message { Key = null }, new DateTime()); var partition = partitioner.GetPartition(message, partitions); Assert.IsTrue(partition.Id != Partition.None.Id); }
public void Test_MessageKeyPartitionSelection_Fallbacks_To_RoundRobin_If_Partition_Blacklisted(int partitionIdBlacklisted) { var nodeMock = new NodeMock(); var partitions = new[] { new Partition { Id = 0, Leader = nodeMock }, new Partition { Id = 1, Leader = nodeMock }, new Partition { Id = 2, Leader = nodeMock }, }; var blacklistedPartitions = new Dictionary <int, DateTime> { { partitionIdBlacklisted, DateTime.MaxValue } }; var partitionStrategy = new MessageKeyPartitionSelection(Serializer, RoundRobinPartitionSelection, Mock.Of <ILogger>()); var partitioner = new PartitionSelector(partitionStrategy); var message = ProduceMessage.New(string.Empty, Partitions.Any, new Message { Key = "ThisIsMyKey" }, new DateTime()); for (var i = 0; i < 300; i++) { var partition = partitioner.GetPartition(message, partitions, blacklistedPartitions); Assert.IsTrue(partition.Id != Partition.None.Id); Assert.IsTrue(partition.Id != partitionIdBlacklisted); } }
public void Test_MessageKeyPartitionSelection_Is_Consistent() { var nodeMock = new NodeMock(); var partitions = new[] { new Partition { Id = 0, Leader = nodeMock }, new Partition { Id = 1, Leader = nodeMock }, new Partition { Id = 2, Leader = nodeMock }, }; var partitionStrategy = new MessageKeyPartitionSelection(Serializer, RoundRobinPartitionSelection, Mock.Of <ILogger>()); var partitioner = new PartitionSelector(partitionStrategy); var message1 = ProduceMessage.New(string.Empty, Partitions.Any, new Message { Key = "ThisIsMyKey" }, new DateTime()); var message2 = ProduceMessage.New(string.Empty, Partitions.Any, new Message { Key = "ThisIsMyOtherKey" }, new DateTime()); var expectedPartition1 = partitioner.GetPartition(message1, partitions); var expectedPartition2 = partitioner.GetPartition(message2, partitions); for (var i = 0; i < 300; i++) { var currentPartition1 = partitioner.GetPartition(message1, partitions); var currentPartition2 = partitioner.GetPartition(message2, partitions); Assert.AreEqual(expectedPartition1.Id, currentPartition1.Id); Assert.AreEqual(expectedPartition2.Id, currentPartition2.Id); } }
public override void ClearInfo() { PartitionSelector ps = this.Info.PartitionSelector; DataLossMode dlm = this.Info.DataLossMode; this.Info = new InvokeDataLossInfo(ps, dlm); }
public void TestRoundRobinPartitionWithStartSeed(int startSeed, int delay) { var nodeMock = new NodeMock(); var partitions = new[] { new Partition { Id = 0, Leader = nodeMock }, new Partition { Id = 1, Leader = nodeMock }, new Partition { Id = 2, Leader = nodeMock }, new Partition { Id = 3, Leader = nodeMock }, new Partition { Id = 4, Leader = nodeMock }, }; var partitionStrategy = new RoundRobinPartitionSelection(delay: delay, startSeed: startSeed); var partitioner = new PartitionSelector(partitionStrategy); foreach (var partition in partitions) { for (var j = 0; j < delay; ++j) { Assert.AreEqual((partition.Id + startSeed) % partitions.Length, partitioner.GetPartition( ProduceMessage.New(string.Empty, Partitions.Any, new Message(), new DateTime()), partitions).Id); } } }
private FabricTestAction GetMoveSecondaryReplicaAction(MoveSecondaryReplicaStateTransitionAction ragAction) { Requires.Argument("moveSecondaryReplicaStateTransitionAction", ragAction).NotNull(); Uri serviceUri = ragAction.ServiceUri; Guid guid = ragAction.PartitionId; string currentNodeName = ragAction.NodeFrom; string newNodeName = ragAction.NodeTo; string report = StringHelper.Format( "Generating Action: {0}\n\t\tService: {1}\n\t\tPartition: {2}\n\t\tFrom: {3} To: {4}", ragAction.ActionType, serviceUri, guid, currentNodeName, newNodeName); Log.WriteInfo(TraceType, report); if (this.reportFunction != null) { this.reportFunction(report); } var partitionSelector = PartitionSelector.PartitionIdOf(serviceUri, guid); return(new MoveSecondaryAction(currentNodeName, newNodeName, partitionSelector, ragAction.ForceMove)); }
public void TestRobinPartitionAssignWhenFiltered() { var nodeMock = new NodeMock(); var partitions = new[] { new Partition { Id = 1, Leader = nodeMock }, new Partition { Id = 2, Leader = nodeMock }, new Partition { Id = 3, Leader = nodeMock }, }; var filter = new Dictionary <int, DateTime>(); int delay = partitions.Length + 2; var partitionStrategy = new RoundRobinPartitionSelection(delay); var partitioner = new PartitionSelector(partitionStrategy); var partition = partitioner.GetPartition(ProduceMessage.New(string.Empty, Partitions.Any, new Message(), new DateTime()), partitions, filter); Assert.AreEqual(1, partition.Id); filter.Add(1, DateTime.UtcNow); var batch = GetPartitions(delay, partitioner, partitions, filter); Assert.AreEqual(delay, batch.Count); Assert.IsTrue(batch.All(p => p.Id == 2), "The round-robin threshold wasn't properly reset after previous partition was blacklisted"); }
/// <summary> /// Asynchronously starts a restore operation using the state indicated by <paramref name="backupMetadata"/>. /// The backup is retrieved from the central store. /// This method completes and returns before the backup restore process is completely done. /// </summary> /// <param name="service"></param> /// <param name="dataLossMode"></param> /// <param name="backupMetadata"></param> /// <returns></returns> public static async Task BeginRestoreBackup(this IBackupRestoreServiceOperations service, BackupMetadata backupMetadata, DataLossMode dataLossMode) { service.LogCallback?.Invoke($"BackupRestoreService - Beginning restore backup {backupMetadata.BackupId} for partition {service.Context.PartitionId}."); try { if (backupMetadata == null) { throw new ArgumentNullException(nameof(backupMetadata)); } await service.CentralBackupStore.ScheduleBackupRestoreAsync(service.Context.PartitionId, backupMetadata.BackupId); var partitionSelector = PartitionSelector.PartitionIdOf(service.Context.ServiceName, service.Context.PartitionId); var operationId = Guid.NewGuid(); await new FabricClient(FabricClientRole.Admin).TestManager.StartPartitionDataLossAsync(operationId, partitionSelector, dataLossMode); //Causes OnDataLossAsync to be called later on. } catch (Exception ex) { string message = $"Failed to restore backup for partition {service.Context.PartitionId}"; service.LogCallback?.Invoke($"{nameof(BackupRestoreServiceOperations)} - {nameof(BeginRestoreBackup)} failed for partition: {service.Context.PartitionId}. Message:{message} - Error: {ex.Message}"); throw new Exception(message, ex); } service.LogCallback?.Invoke($"{nameof(BackupRestoreServiceOperations)} - {nameof(BeginRestoreBackup)} succeeded {backupMetadata.BackupId} for partition {service.Context.PartitionId}."); }
public void SelectorShouldThrowExceptionWhenPartitionsAreEmpty() { var selector = new PartitionSelector(); var topic = new MetadataResponse.Topic("emptyPartition"); Assert.Throws <RoutingException>(() => selector.Select(topic, CreateKeyForPartition(1))); }
public override void ClearInfo() { PartitionSelector ps = this.Info.PartitionSelector; RestartPartitionMode mode = this.Info.RestartPartitionMode; this.Info = new RestartPartitionInfo(ps, mode); }
public void TestRoundRobinPartitionAssignNoPartitionReturnsNone() { var partitions = new Partition[0]; var partitioner = new PartitionSelector(); Assert.AreEqual(0, Partition.None.CompareTo(partitioner.GetPartition(Partitions.Any, partitions))); }
public void TestRoundRobinPartitionWithStartSeed(int startSeed, int delay) { var nodeMock = new NodeMock(); var partitions = new[] { new Partition { Id = 0, Leader = nodeMock }, new Partition { Id = 1, Leader = nodeMock }, new Partition { Id = 2, Leader = nodeMock }, new Partition { Id = 3, Leader = nodeMock }, new Partition { Id = 4, Leader = nodeMock }, }; var partitioner = new PartitionSelector(delay, startSeed); foreach (var partition in partitions) { for (var j = 0; j < delay; ++j) { Assert.AreEqual((partition.Id + startSeed) % partitions.Length, partitioner.GetPartition(Partitions.Any, partitions).Id); } } }
public void TestRoundRobinPartitionAssign(int delay) { var nodeMock = new NodeMock(); var partitions = new[] { new Partition { Id = 0, Leader = nodeMock }, new Partition { Id = 1, Leader = nodeMock }, new Partition { Id = 2, Leader = nodeMock }, new Partition { Id = 3, Leader = nodeMock }, new Partition { Id = 4, Leader = nodeMock }, }; var partitioner = new PartitionSelector(delay); delay = delay <= 0 ? 1 : delay; foreach (var partition in partitions) { for (var j = 0; j < delay; ++j) { Assert.AreEqual(partition.Id, partitioner.GetPartition(Partitions.Any, partitions).Id); } } }
public PerformingActions(FabricClient fabricClient, InvokeDataLossState state, TimeSpan requestTimeout, TimeSpan operationTimeout, PartitionSelector partitionSelector, int dataLossCheckWaitDurationInSeconds, int dataLossCheckPollIntervalInSeconds, int replicaDropWaitDurationInSeconds) : base(fabricClient, state, requestTimeout, operationTimeout) { this.partitionSelector = partitionSelector; this.dataLossCheckWaitDurationInSeconds = dataLossCheckWaitDurationInSeconds; this.dataLossCheckPollIntervalInSeconds = dataLossCheckPollIntervalInSeconds; this.replicaDropWaitDurationInSeconds = replicaDropWaitDurationInSeconds; }
public async Task WhenOneOfTheServicesMoves(string fullyQualifiedServiceTypeName) { var applicationName = fullyQualifiedServiceTypeName.ParseServiceTypeUri().ApplicationName; var serviceTypeName = fullyQualifiedServiceTypeName.ParseServiceTypeUri().ServiceTypeName; var service = (await _fabricClient.QueryManager.GetServiceListAsync(new Uri(applicationName))) .First(x => x.ServiceTypeName == serviceTypeName); await _fabricClient.FaultManager.MovePrimaryAsync(PartitionSelector.SingletonOf(service.ServiceName)); }
/// <summary> /// Restarts a random node. /// </summary> /// <param name="serviceName">Uri of the service in the format fabric:/[application]/[service name]</param> /// <returns>Task instance.</returns> public async Task RestartNodeAsync(Uri serviceName) { PartitionSelector randomPartitionSelector = PartitionSelector.RandomOf(serviceName); ReplicaSelector primaryofReplicaSelector = ReplicaSelector.PrimaryOf(randomPartitionSelector); // Create FabricClient with connection and security information here await _client.FaultManager.RestartNodeAsync(primaryofReplicaSelector, CompletionMode.Verify).ConfigureAwait(false); }
public override void ClearInfo() { PartitionSelector ps = this.Info.PartitionSelector; QuorumLossMode mode = this.Info.QuorumLossMode; TimeSpan duration = this.Info.QuorumLossDuration; this.Info = new InvokeQuorumLossInfo(ps, mode, duration); }
public void TestRoundRobinPartitionAssignNoPartitionReturnsNone() { var partitions = new Partition[0]; var partitionStrategy = new RoundRobinPartitionSelection(); var partitioner = new PartitionSelector(partitionStrategy); Assert.AreEqual(0, Partition.None.CompareTo(partitioner.GetPartition( ProduceMessage.New(string.Empty, Partitions.Any, new Message(), new DateTime()), partitions))); }
public async Task <bool> RestartGetSnowConditionsService() { var replicaSelector = ReplicaSelector.PrimaryOf(PartitionSelector.RandomOf(GlobalContext.ServiceName)); //PartitionSelector namedPartitionSelector = PartitionSelector.PartitionKeyOf(new Uri(GlobalContext.appName), "Partition1"); //await fabricClient.ClusterManager.(new ServicePar); ; //statefull return(true); }
public async Task RestoreServiceAsync(string nameOfBackupSet) { this._fileStore.WriteRestoreInformation(nameOfBackupSet); var partitionSelector = PartitionSelector.PartitionIdOf(this.Context.ServiceName, this.Context.PartitionId); var operationId = Guid.NewGuid(); await new FabricClient(FabricClientRole.Admin).TestManager.StartPartitionDataLossAsync(operationId, partitionSelector, DataLossMode.FullDataLoss); }
public RestartPartitionInfo(PartitionSelector partitionSelector, RestartPartitionMode restartPartitionMode) { this.PartitionSelector = partitionSelector; this.RestartPartitionMode = restartPartitionMode; // This is a default value and will be overwritten when the command executes. The default value is not used during the command. this.NodeName = "UNKNOWNNODE"; this.UnreliableTransportInfo = new List <Tuple <string, string> >(); }
internal static async Task InitiatePartitionDataLoss(Guid dataLossGuid, string serviceNameUri, string partitionId, TimeSpan timeout) { await InvokeWithRetryAsync(() => { return(FabricClient.TestManager.StartPartitionDataLossAsync(dataLossGuid, PartitionSelector.PartitionIdOf(new Uri(UtilityHelper.GetUriFromCustomUri(serviceNameUri)), Guid.Parse(partitionId)), DataLossMode.PartialDataLoss)); } ); }
public RestartPartitionDescription( Guid operationId, PartitionSelector partitionSelector, RestartPartitionMode restartPartitionMode) { Requires.Argument <Guid>("operationId", operationId).NotNull(); this.OperationId = operationId; this.PartitionSelector = partitionSelector; this.RestartPartitionMode = restartPartitionMode; }
public void RoundRobinShouldHandleMultiThreadedRollOver() { var selector = new PartitionSelector(); var bag = new ConcurrentBag <MetadataResponse.Partition>(); Parallel.For(0, 100, x => bag.Add(selector.Select(_topicA, null))); Assert.That(bag.Count(x => x.PartitionId == 0), Is.EqualTo(50)); Assert.That(bag.Count(x => x.PartitionId == 1), Is.EqualTo(50)); }
public void KeyHashShouldSelectEachPartitionType() { var selector = new PartitionSelector(); var first = selector.Select(_topicA, CreateKeyForPartition(0)); var second = selector.Select(_topicA, CreateKeyForPartition(1)); Assert.That(first.partition_id, Is.EqualTo(0)); Assert.That(second.partition_id, Is.EqualTo(1)); }
public InvokeDataLossDescription( Guid operationId, PartitionSelector partitionSelector, DataLossMode dataLossMode) { Requires.Argument <Guid>("operationId", operationId).NotNull(); this.OperationId = operationId; this.PartitionSelector = partitionSelector; this.DataLossMode = dataLossMode; }
public void PartitionSelectionOnEmptyKeyHashShouldNotFail() { var selector = new PartitionSelector(); var topic = new MetadataResponse.Topic("badPartition", partitions: new [] { new MetadataResponse.Partition(0, 0), new MetadataResponse.Partition(999, 1) }); Assert.That(selector.Select(topic, new ArraySegment <byte>()), Is.Not.Null); }
public void KeyHashShouldThrowExceptionWhenChoosesAPartitionIdThatDoesNotExist() { var selector = new PartitionSelector(); var topic = new MetadataResponse.Topic("badPartition", partitions: new [] { new MetadataResponse.Partition(0, 0), new MetadataResponse.Partition(999, 1) }); Assert.Throws <RoutingException>(() => selector.Select(topic, CreateKeyForPartition(1))); }