public void ReplicateCommand(Command cmd, bool synchronous = false) { this.Log(TestTracer.EventType.ReplicateCommandCalled, " ReplicateCommand was called: cmd = {0}", cmd); if (cmd == null) { throw new ArgumentNullException(nameof(cmd)); } ManualResetEvent e = null; if (synchronous) { e = new ManualResetEvent(false); cmd.OnCompletion = () => { e.Set(); }; } MemoryStream ms = new MemoryStream(); try { using (BinaryWriter bw = new BinaryWriter(ms)) { ms = null; cmd.Serialize(bw); bw.BaseStream.Flush(); lock (this.replicationLock) { RSLResponse response = this.ReplicateRequest(((MemoryStream)bw.BaseStream).GetBuffer(), cmd); if (response != RSLResponse.RSLSuccess) { throw new InvalidOperationException("cannot replicate command: " + response); } this.inflight.Enqueue(cmd); } } } finally { if (ms != null) { ms.Dispose(); } } if (e != null) { e.WaitOne(); } }
/// <summary> /// This is called when the request can't be executed anymore because this /// replica is not a primary anymore /// </summary> /// <param name="status"></param> /// <param name="cookie"></param> public override void AbortRequest(RSLResponse status, Object cookie) { Request requestObject; if (cookie != null) { requestObject = (Request)cookie; requestObject.Cancel(); } }
public override void AbortRequest(RSLResponse status, object cookie) { Console.WriteLine("Request aborted (outstanding={0})", m_outstanding); if (this == cookie) { lock (this) { Debug.Assert(m_outstanding > 0); m_outstanding--; } } }
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); } } }); }
public override void ShutDown(RSLResponse status) { Console.WriteLine(this.Self.MemberId + ".ShutDown"); this.lastAppliedDecree = ulong.MinValue; this._internalState = int.MinValue; }
public override void AbortChangeConfiguration(RSLResponse status, object cookie) { Console.WriteLine(this.Self.MemberId + ".AbortChangeConfiguration"); }
public override void AbortRequest(RSLResponse status, Object cookie) { Console.WriteLine(this.Self.MemberId + ".AbortRequest"); }
/// <summary> /// This method is called when RSL decides that is time to shut /// this replica down /// </summary> /// <param name="status"></param> public override void ShutDown(RSLResponse status) { System.Environment.Exit(255); }
public override void AbortChangeConfiguration(RSLResponse status, object cookie) { Program._writer.WriteLine("Configuration change aborted (" + status + ")!"); Program._writer.Flush(); }
public override void ShutDown(RSLResponse status) { Console.WriteLine("Shutting down"); m_clientEnd = true; }
public override void AbortChangeConfiguration(RSLResponse status, object cookie) { Console.WriteLine("Change configuration aborted!"); Debug.Assert(false); }
public override void AbortRequest(RSLResponse status, object gc_cookie) { this.UnloadAsynchronously("AbortRequest"); }
public override void AbortChangeConfiguration(RSLResponse status, object gc_cookie) { this.UnloadAsynchronously("AbortChangeConfiguration"); }
public override void ShutDown(RSLResponse status) { this.Log(TestTracer.EventType.ShutDownCalled, " was asked ShutDown"); }
/// <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