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);
        }
Ejemplo n.º 2
0
        public RepConfig()
        {
            ackPolicy = AckPolicy.QUORUM;
            bulk = false;
            home = "";
            localSite = new DbSiteConfig();
            priority = 100;
            remoteSites = new List<DbSiteConfig>();
            startPolicy = StartPolicy.ELECTION;

            verbose = false;
        }
        public DatabaseEnvironment SetUpEnv(String home, uint priority, uint port, bool isMaster)
        {
            try    {
                Configuration.ClearDir(home);
            } catch (Exception e)    {
                Console.WriteLine(e.Message);
                throw new TestException("Please clean the directory");
            }

            /* Configure and open environment with replication
             * application.
             */
            DatabaseEnvironmentConfig cfg =
                new DatabaseEnvironmentConfig();
            cfg.UseReplication = true;
            cfg.MPoolSystemCfg = new MPoolConfig();
            cfg.MPoolSystemCfg.CacheSize =
                new CacheInfo(0, 20485760, 1);
            cfg.UseLocking = true;
            cfg.UseTxns = true;
            cfg.UseMPool = true;
            cfg.Create = true;
            cfg.UseLogging = true;
            cfg.RunRecovery = true;
            cfg.TxnNoSync = true;
            cfg.FreeThreaded = true;

            cfg.RepSystemCfg = new ReplicationConfig();
            DbSiteConfig dbSiteConfig = new DbSiteConfig();
            dbSiteConfig.Host = ip;
            dbSiteConfig.Port = port;
            dbSiteConfig.LocalSite = true;
            cfg.RepSystemCfg.RepmgrSitesConfig.Add(dbSiteConfig);
            cfg.RepSystemCfg.Priority = priority;
            if (!isMaster) {
                DbSiteConfig dbSiteConfig1 = new DbSiteConfig();
                dbSiteConfig1.Host = ip;
                dbSiteConfig1.Port = masterPort;
                dbSiteConfig1.Helper = true;
                cfg.RepSystemCfg.RepmgrSitesConfig.Add(dbSiteConfig1);
            }
            cfg.RepSystemCfg.BulkTransfer = false;
            cfg.RepSystemCfg.AckTimeout = 5000;

            cfg.RepSystemCfg.RepMgrAckPolicy =
                AckPolicy.ALL_PEERS;

            DatabaseEnvironment env = DatabaseEnvironment.Open(
                home, cfg);

            return env;
        }
Ejemplo n.º 4
0
        public static void Main(string[] args)
        {
            RepConfig config = new RepConfig();
            bool isPeer, isCreator;
            uint tmpPort = 0;

            /*
             * RepQuoteExample is meant to be run from build_windows\AnyCPU, in
             * either the Debug or Release directory. The required core
             * libraries, however, are in either build_windows\Win32 or
             * build_windows\x64, depending upon the platform.  That location
             * needs to be added to the PATH environment variable for the
             * P/Invoke calls to work.
             */
            try {
                String pwd = Environment.CurrentDirectory;
                pwd = Path.Combine(pwd, "..");
                pwd = Path.Combine(pwd, "..");
                if (IntPtr.Size == 4)
                    pwd = Path.Combine(pwd, "Win32");
                else
                    pwd = Path.Combine(pwd, "x64");
            #if DEBUG
                pwd = Path.Combine(pwd, "Debug");
            #else
                pwd = Path.Combine(pwd, "Release");
            #endif
                pwd += ";" + Environment.GetEnvironmentVariable("PATH");
                Environment.SetEnvironmentVariable("PATH", pwd);
            } catch (Exception e) {
                Console.WriteLine(
                    "Unable to set the PATH environment variable.");
                Console.WriteLine(e.Message);
                return;
            }

            /*  Extract the command line parameters. */
            for (int i = 0; i < args.Length; i++)
            {
                isPeer = false;
                isCreator = false;
                string s = args[i];
                if (s[0] != '-')
                    continue;
                switch (s[1])
                {
                    case 'a':
                        if (i == args.Length - 1)
                            usage();
                        i++;
                        if (args[i].Equals("all"))
                            config.ackPolicy = AckPolicy.ALL;
                        else if (!args[i].Equals("quorum"))
                            usage();
                        break;
                    case 'b':
                        config.bulk = true;
                        break;
                    case 'C':
                        config.startPolicy = StartPolicy.CLIENT;
                        break;
                    case 'h':
                        if (i == args.Length - 1)
                            usage();
                        i++;
                        config.home = args[i];
                        break;
                    case 'l':
                    case 'L':
                        if (i == args.Length - 1)
                            usage();
                        if (args[i].Equals("-L"))
                            isCreator = true;
                        i++;
                        string[] words = args[i].Split(':');
                        if (words.Length != 2)
                        {
                            Console.Error.WriteLine("Invalid host " +
                                "specification host:port needed.");
                            usage();
                        }
                        try
                        {
                            tmpPort = uint.Parse(words[1]);
                        } catch (InvalidCastException)
                        {
                            Console.Error.WriteLine("Invalid host " +
                                "specification, could not parse port number.");
                            usage();
                        }
                        config.localSite.Host = words[0];
                        config.localSite.Port = tmpPort;
                        config.localSite.GroupCreator = isCreator;
                        config.localSite.LocalSite = true;
                        break;
                    case 'M':
                        config.startPolicy = StartPolicy.MASTER;
                        break;
                    case 'p':
                        if (i == args.Length - 1)
                            usage();
                        i++;
                        try
                        {
                            config.priority = uint.Parse(args[i]);
                        } catch (InvalidCastException)
                        {
                            Console.Error.WriteLine("Unable to parse priority.");
                            usage();
                        }
                        break;
                    case 'r':
                    case 'R':
                        if (i == args.Length - 1)
                            usage();
                        if (args[i].Equals("-R"))
                            isPeer = true;
                        i++;
                        words = args[i].Split(':');
                        if (words.Length != 2)
                        {
                            Console.Error.WriteLine("Invalid host " +
                                "specification host:port needed.");
                            usage();
                        }
                        try
                        {
                            tmpPort = uint.Parse(words[1]);
                        } catch (InvalidCastException)
                        {
                            Console.Error.WriteLine("Invalid host " +
                                "specification, could not parse port number.");
                            usage();
                        }
                        DbSiteConfig remoteConfig = new DbSiteConfig();
                        remoteConfig.Helper = true;
                        remoteConfig.Host = words[0];
                        remoteConfig.Port = tmpPort;
                        remoteConfig.Peer = isPeer;
                        config.remoteSites.Add(remoteConfig);
                        break;
                    case 'v':
                        config.verbose = true;
                        break;
                    default:
                        Console.Error.WriteLine(
                            "Unrecognized option: " + args[i]);
                        usage();
                        break;
                }
            }

            /* Error check command line. */
            if (config.localSite.Host == null || config.home.Length == 0)
                usage();

            RepQuoteExample runner = null;
            try
            {
                runner = new RepQuoteExample();
                runner.init(config);
                runner.doloop();
                runner.terminate();
                runner = null;
            } catch (DatabaseException dbErr)
            {
                Console.Error.WriteLine("Caught an exception during " +
                    "initialization or processing: " + dbErr);
                if (runner != null)
                    runner.terminate();
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Configure a site in the replication manager.
 /// </summary>
 /// <param name="siteConfig">The configuration of a site</param>
 public void RepMgrSiteConfig(DbSiteConfig siteConfig)
 {
     DB_SITE dbSite;
     dbSite = dbenv.repmgr_site(siteConfig.Host, siteConfig.Port);
     if (siteConfig.helperIsSet)
         dbSite.set_config(DbConstants.DB_BOOTSTRAP_HELPER,
             Convert.ToUInt32(siteConfig.Helper));
     if (siteConfig.groupCreatorIsSet)
         dbSite.set_config(DbConstants.DB_GROUP_CREATOR,
             Convert.ToUInt32(siteConfig.GroupCreator));
     if (siteConfig.legacyIsSet)
         dbSite.set_config(DbConstants.DB_LEGACY,
             Convert.ToUInt32(siteConfig.Legacy));
     if (siteConfig.localSiteIsSet)
         dbSite.set_config(DbConstants.DB_LOCAL_SITE,
             Convert.ToUInt32(siteConfig.LocalSite));
     if (siteConfig.peerIsSet)
         dbSite.set_config(DbConstants.DB_REPMGR_PEER,
             Convert.ToUInt32(siteConfig.Peer));
     dbSite.close();
 }
Ejemplo n.º 6
0
        public static void ConfirmReplicationHostAddress(
		    XmlElement xmlElem, string name,
		    DbSiteConfig siteConfig, bool compulsory)
        {
            XmlNode xmlNode = XMLReader.GetNode(xmlElem, name);
            if (xmlNode == null && compulsory == true)
                throw new ConfigNotFoundException(name);
            else if (xmlNode != null)
            {
                string host = XMLReader.GetNode(
                    (XmlElement)xmlNode, "Host").InnerText;
                uint port = uint.Parse(XMLReader.GetNode(
                    (XmlElement)xmlNode, "Port").InnerText);

                Assert.AreEqual(host, siteConfig.Host);
                Assert.AreEqual(port, siteConfig.Port);
            }
        }
Ejemplo n.º 7
0
        public static bool ConfigReplicationHostAddress(
		    XmlElement xmlElem, string name,
		    ref DbSiteConfig siteConfig, bool compulsory)
        {
            XmlNode xmlNode = XMLReader.GetNode(
                xmlElem, name);
            if (xmlNode == null && compulsory == false)
                return false;
            else if (xmlNode == null && compulsory == true)
                throw new ConfigNotFoundException(name);

                siteConfig.Host = XMLReader.GetNode(
                (XmlElement)xmlNode, "Host").InnerText;
                siteConfig.Port = uint.Parse(XMLReader.GetNode(
                (XmlElement)xmlNode, "Port").InnerText);
            return true;
        }