public static void Confirm(XmlElement xmlElement,
                            ReplicationConfig cfg, bool compulsory)
 {
     Configuration.ConfirmUint(xmlElement,
                               "AckTimeout", cfg.AckTimeout,
                               compulsory);
     Configuration.ConfirmBool(xmlElement, "BulkTransfer",
                               cfg.BulkTransfer, compulsory);
     Configuration.ConfirmUint(xmlElement, "CheckpointDelay",
                               cfg.CheckpointDelay, compulsory);
     Configuration.ConfirmUint(xmlElement, "ConnectionRetry",
                               cfg.ConnectionRetry, compulsory);
     Configuration.ConfirmBool(xmlElement, "DelayClientSync",
                               cfg.DelayClientSync, compulsory);
     Configuration.ConfirmUint(xmlElement, "ElectionRetry",
                               cfg.ElectionRetry, compulsory);
     Configuration.ConfirmUint(xmlElement, "ElectionTimeout",
                               cfg.ElectionTimeout, compulsory);
     Configuration.ConfirmUint(xmlElement, "FullElectionTimeout",
                               cfg.FullElectionTimeout, compulsory);
     Configuration.ConfirmUint(xmlElement, "HeartbeatMonitor",
                               cfg.HeartbeatMonitor, compulsory);
     Configuration.ConfirmUint(xmlElement, "HeartbeatSend",
                               cfg.HeartbeatSend, compulsory);
     Configuration.ConfirmUint(xmlElement, "LeaseTimeout",
                               cfg.LeaseTimeout, compulsory);
     Configuration.ConfirmBool(xmlElement, "AutoInit",
                               cfg.AutoInit, compulsory);
     Configuration.ConfirmBool(xmlElement, "NoBlocking",
                               cfg.NoBlocking, compulsory);
     Configuration.ConfirmUint(xmlElement, "Priority",
                               cfg.Priority, compulsory);
     Configuration.ConfirmAckPolicy(xmlElement,
                                    "RepMgrAckPolicy", cfg.RepMgrAckPolicy, compulsory);
     if (cfg.RepmgrSitesConfig.Count > 0)
     {
         Configuration.ConfirmReplicationHostAddress(
             xmlElement, "RepMgrLocalSite",
             cfg.RepmgrSitesConfig[0], compulsory);
     }
     Configuration.ConfirmBool(xmlElement, "Strict2Site",
                               cfg.Strict2Site, compulsory);
     Configuration.ConfirmBool(xmlElement, "UseMasterLeases",
                               cfg.UseMasterLeases, compulsory);
 }
Exemple #2
0
        /// <summary>
        /// Parses a replication state from a state file stream.
        /// </summary>
        /// <param name="config">The replication config.</param>
        /// <param name="streamReader">The stream reader.</param>
        /// <returns>The replication state.</returns>
        /// <exception cref="Exception"></exception>
        internal static ReplicationState ParseReplicationState(this ReplicationConfig config, StreamReader streamReader)
        {
            var sequenceNumber = long.MaxValue;
            var timestamp      = default(DateTime);

            while (!streamReader.EndOfStream)
            {
                var line = streamReader.ReadLine();
                if (string.IsNullOrWhiteSpace(line))
                {
                    continue;
                }
                if (line.StartsWith("#"))
                {
                    continue;
                }
                if (line.StartsWith(ReplicationState.SequenceNumberKey))
                { // this line has the sequence number.
                    var keyValue = line.Split('=');
                    if (keyValue.Length != 2)
                    {
                        throw new Exception($"Could not parse {ReplicationState.SequenceNumberKey}");
                    }
                    if (!long.TryParse(keyValue[1], out sequenceNumber))
                    {
                        throw new Exception($"Could not parse {ReplicationState.SequenceNumberKey}");
                    }
                }
                else if (line.StartsWith(ReplicationState.TimestampKey))
                {
                    var keyValue = line.Split('=');
                    if (keyValue.Length != 2)
                    {
                        throw new Exception($"Could not parse {ReplicationState.TimestampKey}");
                    }
                    keyValue[1] = keyValue[1].Replace("\\", string.Empty);
                    if (!DateTime.TryParse(keyValue[1], null, DateTimeStyles.AdjustToUniversal, out timestamp))
                    {
                        throw new Exception($"Could not parse {ReplicationState.TimestampKey}");
                    }
                }
            }

            return(new ReplicationState(config, sequenceNumber, timestamp));
        }
Exemple #3
0
        /// <summary>
        /// Gets an enumerator to loop over incoming diffs.
        /// </summary>
        /// <param name="config">The replication config.</param>
        /// <param name="sequenceNumber">The sequence number, latest if empty.</param>
        /// <returns>The enumerator moved to the given sequence number or null if the sequence number doesn't exist.</returns>
        public static async Task <ReplicationDiffEnumerator> GetDiffEnumerator(this ReplicationConfig config,
                                                                               long?sequenceNumber = null)
        {
            if (sequenceNumber == null)
            { // get the latest number.
                var latest = await config.LatestReplicationState();

                sequenceNumber = latest.SequenceNumber;
            }

            var enumerator = new ReplicationDiffEnumerator(config);

            if (!await enumerator.MoveTo(sequenceNumber.Value))
            {
                return(null);
            }
            return(enumerator);
        }
Exemple #4
0
        public void TestRepMgrLocalSite()
        {
            string host = "127.0.0.0";
            uint   port = 8888;

            testName = "TestRepMgrLocalSite";
            SetUpTest(false);

            ReplicationConfig repConfig1 = new ReplicationConfig();

            repConfig1.RepMgrLocalSite      = new ReplicationHostAddress();
            repConfig1.RepMgrLocalSite.Host = host;
            repConfig1.RepMgrLocalSite.Port = port;
            Assert.AreEqual(host, repConfig1.RepMgrLocalSite.Host);
            Assert.AreEqual(port, repConfig1.RepMgrLocalSite.Port);

            ReplicationConfig repConfig2 = new ReplicationConfig();

            repConfig2.RepMgrLocalSite =
                new ReplicationHostAddress(host, port);
            Assert.AreEqual(host, repConfig2.RepMgrLocalSite.Host);
            Assert.AreEqual(port, repConfig2.RepMgrLocalSite.Port);

            ReplicationConfig repConfig3 = new ReplicationConfig();

            repConfig3.RepMgrLocalSite =
                new ReplicationHostAddress(host + ":" + port);
            Assert.AreEqual(host, repConfig3.RepMgrLocalSite.Host);
            Assert.AreEqual(port, repConfig3.RepMgrLocalSite.Port);

            try
            {
                repConfig3.RepMgrLocalSite =
                    new ReplicationHostAddress(host + port);
                throw new TestException();
            }
            catch (ArgumentException) {
            }
        }
        public void TestConfig()
        {
            testName = "TestConfig";

            ReplicationConfig repConfig = new ReplicationConfig();
            XmlElement        xmlElem   = Configuration.TestSetUp(
                testFixtureName, testName);

            Config(xmlElem, ref repConfig, true);
            Confirm(xmlElem, repConfig, true);

            repConfig.Clockskew(102, 100);
            Assert.AreEqual(102, repConfig.ClockskewFast);
            Assert.AreEqual(100, repConfig.ClockskewSlow);

            repConfig.TransmitLimit(1, 1024);
            Assert.AreEqual(1, repConfig.TransmitLimitGBytes);
            Assert.AreEqual(1024, repConfig.TransmitLimitBytes);

            repConfig.RetransmissionRequest(10, 100);
            Assert.AreEqual(100, repConfig.RetransmissionRequestMax);
            Assert.AreEqual(10, repConfig.RetransmissionRequestMin);
        }
Exemple #6
0
        public static void Config(XmlElement xmlElement,
                                  ref ReplicationConfig cfg, bool compulsory)
        {
            uint uintValue = new uint();

            if (Configuration.ConfigUint(xmlElement, "AckTimeout",
                                         ref uintValue, compulsory))
            {
                cfg.AckTimeout = uintValue;
            }
            Configuration.ConfigBool(xmlElement, "BulkTransfer",
                                     ref cfg.BulkTransfer, compulsory);
            if (Configuration.ConfigUint(xmlElement, "CheckpointDelay",
                                         ref uintValue, compulsory))
            {
                cfg.CheckpointDelay = uintValue;
            }
            if (Configuration.ConfigUint(xmlElement, "ConnectionRetry",
                                         ref uintValue, compulsory))
            {
                cfg.ConnectionRetry = uintValue;
            }
            Configuration.ConfigBool(xmlElement, "DelayClientSync",
                                     ref cfg.DelayClientSync, compulsory);
            if (Configuration.ConfigUint(xmlElement, "ElectionRetry",
                                         ref uintValue, compulsory))
            {
                cfg.ElectionRetry = uintValue;
            }
            if (Configuration.ConfigUint(xmlElement, "ElectionTimeout",
                                         ref uintValue, compulsory))
            {
                cfg.ElectionTimeout = uintValue;
            }
            if (Configuration.ConfigUint(xmlElement, "FullElectionTimeout",
                                         ref uintValue, compulsory))
            {
                cfg.FullElectionTimeout = uintValue;
            }
            if (Configuration.ConfigUint(xmlElement, "HeartbeatMonitor",
                                         ref uintValue, compulsory))
            {
                cfg.HeartbeatMonitor = uintValue;
            }
            if (Configuration.ConfigUint(xmlElement, "HeartbeatSend",
                                         ref uintValue, compulsory))
            {
                cfg.HeartbeatSend = uintValue;
            }
            if (Configuration.ConfigUint(xmlElement, "LeaseTimeout",
                                         ref uintValue, compulsory))
            {
                cfg.LeaseTimeout = uintValue;
            }
            Configuration.ConfigBool(xmlElement, "AutoInit",
                                     ref cfg.AutoInit, compulsory);
            Configuration.ConfigBool(xmlElement, "NoBlocking",
                                     ref cfg.NoBlocking, compulsory);
            if (Configuration.ConfigUint(xmlElement, "Priority",
                                         ref uintValue, compulsory))
            {
                cfg.Priority = uintValue;
            }
            Configuration.ConfigAckPolicy(xmlElement,
                                          "RepMgrAckPolicy", ref cfg.RepMgrAckPolicy,
                                          compulsory);
            DbSiteConfig siteConfig = new DbSiteConfig();

            siteConfig.LocalSite = true;
            Configuration.ConfigReplicationHostAddress(xmlElement,
                                                       "RepMgrLocalSite", ref siteConfig, compulsory);
            cfg.RepmgrSitesConfig.Add(siteConfig);
            Configuration.ConfigBool(xmlElement, "Strict2Site",
                                     ref cfg.Strict2Site, compulsory);
            Configuration.ConfigBool(xmlElement, "UseMasterLeases",
                                     ref cfg.UseMasterLeases, compulsory);
        }
 internal ReplicationDiffEnumerator(ReplicationConfig config)
 {
     Config        = config;
     _lastReturned = -1;
 }
Exemple #8
0
 /// <summary>
 /// Downloads the diff associated with the given replication state.
 /// </summary>
 /// <param name="config">The replication config.</param>
 /// <param name="sequenceNumber">The sequence number.</param>
 /// <returns>The raw diff stream.</returns>
 internal static async Task <Stream> DownloadDiffStream(this ReplicationConfig config, long sequenceNumber)
 {
     return(await HttpHandler.Default.TryGetStreamAsync(config.DiffUrl(sequenceNumber)));
 }
Exemple #9
0
 /// <summary>
 /// Creates a new replication state.
 /// </summary>
 /// <param name="config">The replication config.</param>
 /// <param name="sequenceNumber">The sequence number.</param>
 /// <param name="endTimestamp">The timestamp.</param>
 internal ReplicationState(ReplicationConfig config, long sequenceNumber, DateTime endTimestamp)
 {
     this.Config         = config;
     this.SequenceNumber = sequenceNumber;
     this.EndTimestamp   = endTimestamp;
 }