Exemple #1
0
 public Master(PaxosNode Node, TimeSpan DriftRange, TimeSpan LeaseSpan)
 {
     node = Node;
     if (LeaseSpan > TimeSpan.FromMinutes(1))
         throw new ArgumentOutOfRangeException("LeaseSpan", LeaseSpan, "LeaseSpan must be less than 60 minutes");
     LeaseSpanSeconds = (int)Math.Floor(LeaseSpan.TotalSeconds);
     if (!IsDivisble(LeaseSpanSeconds, 60 * 60))
         throw new ArgumentException("LeaseSpan must divide exactly into an hour", "LeaseSpan");
     if (DriftRange > LeaseSpan)
         throw new ArgumentOutOfRangeException("DriftRange", DriftRange, "DriftRange can't be more than the LeaseSpan");
     this.DriftRange = DriftRange;
 }
Exemple #2
0
        public StorageNode(int NodeCount)
        {
            address = Guid.NewGuid().ToString();
            paxos = new PaxosNode(address, NodeCount);

            paxos.RoundComplete += paxos_RoundComplete;
            TransactionResults.TrySet("SKIP", false);
            Sequencing.TrySet(-1, "SKIP");

            TransactionUpdates.KeyRequested += TransactionUpdates_KeyRequested;

            paxos.Message += (s, m) => SendMessage("paxos", m);
        }
        public async Task PaxosNodesPassResults()
        {
            var A = new PaxosNode("A", 3);
            var B = new PaxosNode("B", 3);
            var C = new PaxosNode("C", 3);
            Group(A, B, C);

            string result;

            Assert.IsFalse(A.TryGetResult("round", out result));
            Assert.IsFalse(B.TryGetResult("round", out result));
            Assert.IsFalse(C.TryGetResult("round", out result));

            var t1 = A.Propose("round", "foo");
            var expected = await t1;
            var t2 = B.Propose("round", "bar");
            Assert.IsTrue(expected == "foo" || expected == "bar");
            Assert.AreEqual(expected, await t2);

            Assert.AreEqual(expected, await B.GetResult("round"));
            Assert.AreEqual(expected, await A.GetResult("round"));
            Assert.AreEqual(expected, await C.GetResult("round"));
        }