public static RepQuoteEnvironment Open(string home, DatabaseEnvironmentConfig cfg)
 {
     RepQuoteEnvironment dbEnv = new RepQuoteEnvironment();
     dbEnv.env = DatabaseEnvironment.Open(home, cfg);
     dbEnv._appFinished = false;
     dbEnv._inClientSync = false;
     dbEnv._isMaster = false;
     return dbEnv;
 }
        public static RepQuoteEnvironment Open(string home, DatabaseEnvironmentConfig cfg)
        {
            RepQuoteEnvironment dbEnv = new RepQuoteEnvironment();

            dbEnv.env           = DatabaseEnvironment.Open(home, cfg);
            dbEnv._appFinished  = false;
            dbEnv._inClientSync = false;
            dbEnv._isMaster     = false;
            return(dbEnv);
        }
 public RepQuoteExample()
 {
     dbenv = null;
 }
        public int init(RepConfig config)
        {
            int ret = 0;

            DatabaseEnvironmentConfig envConfig = new DatabaseEnvironmentConfig();
            envConfig.ErrorPrefix = RepConfig.progname;
            envConfig.RepSystemCfg = new ReplicationConfig();

            envConfig.RepSystemCfg.RepmgrSitesConfig.Add(config.localSite);
            for (int i = 0; i < config.remoteSites.Count; i++)
                envConfig.RepSystemCfg.RepmgrSitesConfig.Add(config.remoteSites[i]);

            envConfig.RepSystemCfg.BulkTransfer = config.bulk;

            /*
             * Configure heartbeat timeouts so that repmgr monitors the
             * health of the TCP connection.  Master sites broadcast a heartbeat
             * at the frequency specified by the DB_REP_HEARTBEAT_SEND timeout.
             * Client sites wait for message activity the length of the
             * DB_REP_HEARTBEAT_MONITOR timeout before concluding that the
             * connection to the master is lost.  The DB_REP_HEARTBEAT_MONITOR
             * timeout should be longer than the DB_REP_HEARTBEAT_SEND timeout.
             */
            envConfig.RepSystemCfg.HeartbeatMonitor = 10000000;
            envConfig.RepSystemCfg.HeartbeatSend = 5000000;

            /*
             * Set replication group election priority for this environment.
             * An election first selects the site with the most recent log
             * records as the new master.  If multiple sites have the most
             * recent log records, the site with the highest priority value
             * is selected as master.
             */
            envConfig.RepSystemCfg.Priority = config.priority;
            envConfig.MPoolSystemCfg = new MPoolConfig();
            envConfig.MPoolSystemCfg.CacheSize = RepConfig.CACHESIZE;
            envConfig.TxnNoSync = true;

            envConfig.EventNotify = new EventNotifyDelegate(RepQuoteEventHandler);

            /*
             * Set the policy that determines how master and client sites
             * handle acknowledgement of replication messages needed for
             * permanent records.  The default policy of "quorum" requires only
             * a quorum of electable peers sufficient to ensure a permanent
             * record remains durable if an election is held.  The "all" option
             * requires all clients to acknowledge a permanent replication
             * message instead.
             */
            envConfig.RepSystemCfg.RepMgrAckPolicy = config.ackPolicy;

            /*
             * Set the threshold for the minimum and maximum time the client
             * waits before requesting retransmission of a missing message.
             * Base these values on the performance and load characteristics
             * of the master and client host platforms as well as the round
             * trip message time.
             */
            envConfig.RepSystemCfg.RetransmissionRequest(20000, 500000);

            /*
             * Configure deadlock detection to ensure that any deadlocks
             * are broken by having one of the conflicting lock requests
             * rejected. DB_LOCK_DEFAULT uses the lock policy specified
             * at environment creation time or DB_LOCK_RANDOM if none was
             * specified.
             */
            envConfig.LockSystemCfg = new LockingConfig();
            envConfig.LockSystemCfg.DeadlockResolution = DeadlockPolicy.DEFAULT;

            envConfig.Create = true;
            envConfig.RunRecovery = true;
            envConfig.FreeThreaded = true;
            envConfig.UseReplication = true;
            envConfig.UseLocking = true;
            envConfig.UseLogging = true;
            envConfig.UseMPool = true;
            envConfig.UseTxns = true;
            envConfig.Verbosity = new VerboseMessages();
            envConfig.Verbosity.Replication = config.verbose;

            try
            {
                dbenv = RepQuoteEnvironment.Open(config.home, envConfig);
            } catch(DatabaseException e)
            {
                Console.WriteLine("Fail to open environment: " + e.Message);
                return 1;
            }

            /* The following base replication features may also be useful to your
             * application. See Berkeley DB documentation for more details.
             *   - Master leases: Provide stricter consistency for data reads
             *     on a master site.
             *   - Timeouts: Customize the amount of time Berkeley DB waits
             *     for such things as an election to be concluded or a master
             *     lease to be granted.
             *   - Delayed client synchronization: Manage the master site's
             *     resources by spreading out resource-intensive client
             *     synchronizations.
             *   - Blocked client operations: Return immediately with an error
             *     instead of waiting indefinitely if a client operation is
             *     blocked by an ongoing client synchronization.
             *
             * The following repmgr features may also be useful to your
             * application.  See Berkeley DB documentation for more details.
             *  - Two-site strict majority rule - In a two-site replication
             *    group, require both sites to be available to elect a new
             *    master.
             *  - Timeouts - Customize the amount of time repmgr waits
             *    for such things as waiting for acknowledgements or attempting
             *    to reconnect to other sites.
             *  - Site list - return a list of sites currently known to repmgr.
             */

            /* Start checkpoint and log archive support threads. */
            checkpointThread = new Thread(new ThreadStart(CheckPoint));
            checkpointThread.Start();
            logArchiveThread = new Thread(new ThreadStart(LogArchive));
            logArchiveThread.Start();

            /* Start replication manager. */
            if (config.startPolicy == StartPolicy.CLIENT)
                dbenv.env.RepMgrStartClient(3);
            else if (config.startPolicy == StartPolicy.ELECTION)
                dbenv.env.RepMgrStartClient(3, true);
            else if (config.startPolicy == StartPolicy.MASTER)
                dbenv.env.RepMgrStartMaster(3);

            return ret;
        }
Exemple #5
0
        public int init(RepConfig config)
        {
            int ret = 0;

            DatabaseEnvironmentConfig envConfig = new DatabaseEnvironmentConfig();

            envConfig.ErrorPrefix  = RepConfig.progname;
            envConfig.RepSystemCfg = new ReplicationConfig();

            envConfig.RepSystemCfg.RepmgrSitesConfig.Add(config.localSite);
            for (int i = 0; i < config.remoteSites.Count; i++)
            {
                envConfig.RepSystemCfg.RepmgrSitesConfig.Add(config.remoteSites[i]);
            }

            envConfig.RepSystemCfg.BulkTransfer = config.bulk;

            /*
             * Configure heartbeat timeouts so that repmgr monitors the
             * health of the TCP connection.  Master sites broadcast a heartbeat
             * at the frequency specified by the DB_REP_HEARTBEAT_SEND timeout.
             * Client sites wait for message activity the length of the
             * DB_REP_HEARTBEAT_MONITOR timeout before concluding that the
             * connection to the master is lost.  The DB_REP_HEARTBEAT_MONITOR
             * timeout should be longer than the DB_REP_HEARTBEAT_SEND timeout.
             */
            envConfig.RepSystemCfg.HeartbeatMonitor = 10000000;
            envConfig.RepSystemCfg.HeartbeatSend    = 5000000;

            /*
             * Set replication group election priority for this environment.
             * An election first selects the site with the most recent log
             * records as the new master.  If multiple sites have the most
             * recent log records, the site with the highest priority value
             * is selected as master.
             */
            envConfig.RepSystemCfg.Priority    = config.priority;
            envConfig.MPoolSystemCfg           = new MPoolConfig();
            envConfig.MPoolSystemCfg.CacheSize = RepConfig.CACHESIZE;
            envConfig.TxnNoSync = true;

            envConfig.EventNotify = new EventNotifyDelegate(RepQuoteEventHandler);

            /*
             * Set the policy that determines how master and client sites
             * handle acknowledgement of replication messages needed for
             * permanent records.  The default policy of "quorum" requires only
             * a quorum of electable peers sufficient to ensure a permanent
             * record remains durable if an election is held.  The "all" option
             * requires all clients to acknowledge a permanent replication
             * message instead.
             */
            envConfig.RepSystemCfg.RepMgrAckPolicy = config.ackPolicy;

            /*
             * Set the threshold for the minimum and maximum time the client
             * waits before requesting retransmission of a missing message.
             * Base these values on the performance and load characteristics
             * of the master and client host platforms as well as the round
             * trip message time.
             */
            envConfig.RepSystemCfg.RetransmissionRequest(20000, 500000);

            /*
             * Configure deadlock detection to ensure that any deadlocks
             * are broken by having one of the conflicting lock requests
             * rejected. DB_LOCK_DEFAULT uses the lock policy specified
             * at environment creation time or DB_LOCK_RANDOM if none was
             * specified.
             */
            envConfig.LockSystemCfg = new LockingConfig();
            envConfig.LockSystemCfg.DeadlockResolution = DeadlockPolicy.DEFAULT;

            envConfig.Create                = true;
            envConfig.RunRecovery           = true;
            envConfig.FreeThreaded          = true;
            envConfig.UseReplication        = true;
            envConfig.UseLocking            = true;
            envConfig.UseLogging            = true;
            envConfig.UseMPool              = true;
            envConfig.UseTxns               = true;
            envConfig.Verbosity             = new VerboseMessages();
            envConfig.Verbosity.Replication = config.verbose;

            try
            {
                dbenv = RepQuoteEnvironment.Open(config.home, envConfig);
            } catch (DatabaseException e)
            {
                Console.WriteLine("Fail to open environment: " + e.Message);
                return(1);
            }


            /* The following base replication features may also be useful to your
             * application. See Berkeley DB documentation for more details.
             *   - Master leases: Provide stricter consistency for data reads
             *     on a master site.
             *   - Timeouts: Customize the amount of time Berkeley DB waits
             *     for such things as an election to be concluded or a master
             *     lease to be granted.
             *   - Delayed client synchronization: Manage the master site's
             *     resources by spreading out resource-intensive client
             *     synchronizations.
             *   - Blocked client operations: Return immediately with an error
             *     instead of waiting indefinitely if a client operation is
             *     blocked by an ongoing client synchronization.
             *
             * The following repmgr features may also be useful to your
             * application.  See Berkeley DB documentation for more details.
             *  - Two-site strict majority rule - In a two-site replication
             *    group, require both sites to be available to elect a new
             *    master.
             *  - Timeouts - Customize the amount of time repmgr waits
             *    for such things as waiting for acknowledgements or attempting
             *    to reconnect to other sites.
             *  - Site list - return a list of sites currently known to repmgr.
             */

            /* Start checkpoint and log archive support threads. */
            checkpointThread = new Thread(new ThreadStart(CheckPoint));
            checkpointThread.Start();
            logArchiveThread = new Thread(new ThreadStart(LogArchive));
            logArchiveThread.Start();

            /* Start replication manager. */
            if (config.startPolicy == StartPolicy.CLIENT)
            {
                dbenv.env.RepMgrStartClient(3);
            }
            else if (config.startPolicy == StartPolicy.ELECTION)
            {
                dbenv.env.RepMgrStartClient(3, true);
            }
            else if (config.startPolicy == StartPolicy.MASTER)
            {
                dbenv.env.RepMgrStartMaster(3);
            }

            return(ret);
        }
Exemple #6
0
        }         /* End main. */

        public RepQuoteExample()
        {
            dbenv = null;
        }