Exemplo n.º 1
0
        public void TestLocalSite()
        {
            testName = "TestLocalSite";
            SetUpTest(true);
            Configuration.ClearDir(testHome);
            DatabaseEnvironmentConfig envConfig =
                new DatabaseEnvironmentConfig();

            envConfig.Create         = true;
            envConfig.UseLocking     = true;
            envConfig.UseLogging     = true;
            envConfig.UseMPool       = true;
            envConfig.UseReplication = true;
            envConfig.UseTxns        = true;
            ReplicationHostAddress addr =
                new ReplicationHostAddress("localhost:6060");
            ReplicationConfig repCfg       = new ReplicationConfig();
            DbSiteConfig      dbSiteConfig = new DbSiteConfig();

            dbSiteConfig.Host      = addr.Host;
            dbSiteConfig.Port      = addr.Port;
            dbSiteConfig.LocalSite = true;
            repCfg.RepmgrSitesConfig.Add(dbSiteConfig);
            envConfig.RepSystemCfg = repCfg;
            DatabaseEnvironment env =
                DatabaseEnvironment.Open(testHome, envConfig);
            ReplicationHostAddress testAddr =
                env.RepMgrLocalSite.Address;

            Assert.AreEqual(addr.Host, testAddr.Host);
            Assert.AreEqual(addr.Port, testAddr.Port);
            env.Close();
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        public void TestSiteRepConfig()
        {
            testName = "TestSiteRepConfig";
            SetUpTest(true);
            Configuration.ClearDir(testHome);
            DatabaseEnvironmentConfig envConfig =
                new DatabaseEnvironmentConfig();

            envConfig.Create         = true;
            envConfig.UseLocking     = true;
            envConfig.UseLogging     = true;
            envConfig.UseMPool       = true;
            envConfig.UseReplication = true;
            envConfig.UseTxns        = true;
            ReplicationHostAddress addr =
                new ReplicationHostAddress("localhost:6060");
            ReplicationConfig repCfg       = new ReplicationConfig();
            DbSiteConfig      dbSiteConfig = new DbSiteConfig();

            dbSiteConfig.Host      = addr.Host;
            dbSiteConfig.Port      = addr.Port;
            dbSiteConfig.LocalSite = true;
            repCfg.RepmgrSitesConfig.Add(dbSiteConfig);

            // DatabaseEnvironment.RepInMemory defaults to false.
            envConfig.RepSystemCfg = repCfg;
            DatabaseEnvironment env =
                DatabaseEnvironment.Open(testHome, envConfig);

            Assert.AreEqual(false, env.RepInMemory);
            env.Close();
            Assert.Less(0,
                        Directory.GetFiles(testHome, "__db.rep.*").Length);

            // Set RepInMemory as true.
            Configuration.ClearDir(testHome);
            repCfg.InMemory        = true;
            envConfig.RepSystemCfg = repCfg;
            env = DatabaseEnvironment.Open(testHome, envConfig);
            Assert.AreEqual(true, env.RepInMemory);
            env.Close();
            Assert.AreEqual(0,
                            Directory.GetFiles(testHome, "__db.rep.*").Length);

            // Set RepInMemory as false.
            Configuration.ClearDir(testHome);
            repCfg.InMemory        = false;
            envConfig.RepSystemCfg = repCfg;
            env = DatabaseEnvironment.Open(testHome, envConfig);
            Assert.AreEqual(false, env.RepInMemory);
            env.Close();
            Assert.Less(0,
                        Directory.GetFiles(testHome, "__db.rep.*").Length);
        }
Exemplo n.º 4
0
        public RepConfig()
        {
            ackPolicy   = AckPolicy.QUORUM;
            bulk        = false;
            home        = "";
            localSite   = new DbSiteConfig();
            priority    = 100;
            remoteSites = new List <DbSiteConfig>();
            startPolicy = StartPolicy.ELECTION;

            verbose = false;
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
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();
                }
            }
        }         /* End main. */