void ChangeConfigurationIfNeeded() { ManagedRSLMemberSet currentMemberSet = new ManagedRSLMemberSet(); uint configurationNumber = 0; GetConfiguration(currentMemberSet, ref configurationNumber); uint currentConfigurationNumber = 0; byte[] cookie = currentMemberSet.ConfigurationCookie; if (cookie != null) { currentConfigurationNumber = (uint)BitConverter.ToInt32(cookie, 0); } int desiredConfigurationNumber = 0; int numMembersInDesiredConfiguration = 0; int[] memberIdsOfDesiredConfiguration = null; if (!ReadConfigurationFromFile(ref desiredConfigurationNumber, ref numMembersInDesiredConfiguration, ref memberIdsOfDesiredConfiguration)) { return; } if (currentConfigurationNumber >= desiredConfigurationNumber) { if (currentConfigurationNumber > g_maxConfigurationReported) { if (ReportCurrentConfiguration(currentConfigurationNumber)) { g_maxConfigurationReported = currentConfigurationNumber; } } return; } Console.WriteLine("New configuration found:"); ManagedRSLNode[] membersOfNewConfiguration = new ManagedRSLNode[numMembersInDesiredConfiguration]; for (int whichMember = 0; whichMember < numMembersInDesiredConfiguration; ++whichMember) { ManagedRSLNode node = new ManagedRSLNode(); membersOfNewConfiguration[whichMember] = node; PopulateNode(node, (ulong)memberIdsOfDesiredConfiguration[whichMember]); Console.Write("{0} ", node.MemberId); } Console.WriteLine(); byte[] configNumberBytes = BitConverter.GetBytes(desiredConfigurationNumber); ManagedRSLMemberSet memberSet = new ManagedRSLMemberSet( membersOfNewConfiguration, configNumberBytes, 0, configNumberBytes.Length); ChangeConfiguration(memberSet, this); }
public void InitiateBootstrap(ManagedRSLNode[] nodes, int timeoutInSeconds, Action <RSLResponse> onComplete = null) { this.isBootStrapped.Reset(); ThreadPool.QueueUserWorkItem(_ => { using (ManagedRSLMemberSet ms = new ManagedRSLMemberSet(nodes, new byte[] { 0 }, 0, 1)) { RSLResponse resp = this.Bootstrap(ms, timeoutInSeconds); this.Log(TestTracer.EventType.BootstrapFinished, "bootstrap instance finished = " + resp); this.isBootStrapped.Set(); if (onComplete != null) { onComplete(resp); } } }); }
/// <summary> /// Starts the configured number of replicas, this function will create /// the necessery files that are needed for the aplicaton to run /// </summary> /// <param name="numberOfReplicas">numberOfReplicas</param> /// <returns></returns> public int StartUp(int numberOfReplicas) { cfg = new ManagedRSLConfigParam(); cfg.NewLeaderGracePeriodSec = 10; cfg.HeartBeatIntervalSec = 2; cfg.ElectionDelaySec = 5; cfg.MaxElectionRandomizeSec = 1; cfg.InitializeRetryIntervalSec = 1; cfg.PrepareRetryIntervalSec = 1; cfg.VoteRetryIntervalSec = 1; cfg.CPQueryRetryIntervalSec = 5; cfg.MaxCheckpointIntervalSec = 0; cfg.MaxLogLenMB = 100; cfg.SendTimeoutSec = 10; cfg.ReceiveTimeoutSec = 10; cfg.MaxCacheLengthMB = 50; cfg.MaxVotesInLog = 1000; cfg.MaxOutstandingPerReplica = 10; cfg.MaxCheckpoints = 2; cfg.MaxLogs = 5; cfg.LogLenRandomize = 20; cfg.ElectionRandomize = 10; cfg.FastReadSeqThreshold = 5; cfg.InMemoryExecutionQueueSizeMB = 10; cfg.NumReaderThreads = 5; cfg.MaxMessageSizeMB = 1; cfg.WorkingDir = RSLWorkingDir; ManagedRSLNode[] nodes = new ManagedRSLNode[numberOfReplicas]; for (int i = 0; i < nodes.Length; i++) { nodes[i] = new ManagedRSLNode(); nodes[i].MemberId = (i + 1).ToString(); nodes[i].RslPort = (ushort)(5000 + (100 * (i + 1))); nodes[i].HostName = "127.0.0.1"; nodes[i].Ip = new IPAddress(0x0100007F); // 127.0.0.1 } int startedReplicas = 0; if (_replicaSet == null) { _replicaSet = new List <BasicRSLTestMachine>(); ManagedRSLStateMachine.NotificationsCallback = OnNotification; ManagedRSLStateMachine.Init(".\\" + RSLDebugLogsDir); for (int i = 0; i < nodes.Length; i++) { BasicRSLTestMachine replica = new BasicRSLTestMachine(nodes[i]); try { bool res = replica.Initialize( cfg, nodes[i], ManagedRSLProtocolVersion.ManagedRSLProtocolVersion_4, false); Debug.Assert(res); startedReplicas++; _replicaSet.Add(replica); _allReplicaSet.Add(replica); } catch (Exception e) { if (e is NullReferenceException || e is System.Runtime.InteropServices.SEHException) { throw; } } //catch } // for Console.WriteLine("Bootstrapping"); byte[] buf = new byte[] { 1 }; ManagedRSLMemberSet memberSet = new ManagedRSLMemberSet(nodes, buf, 0, 1); foreach (BasicRSLTestMachine replica in _allReplicaSet) { RSLResponse resp = replica.Bootstrap(memberSet, 10); Console.WriteLine(resp); } } else { startedReplicas = _replicaSet.Count; } return(startedReplicas); } //StartUp