public void Master() { string home = testHome + "/Master"; string dbName = "rep.db"; Configuration.ClearDir(home); /* * 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(); cfg.RepSystemCfg.RepmgrSitesConfig.Add(new DbSiteConfig()); cfg.RepSystemCfg.RepmgrSitesConfig[0].Host = "127.0.0.1"; cfg.RepSystemCfg.RepmgrSitesConfig[0].Port = ports[0]; cfg.RepSystemCfg.RepmgrSitesConfig[0].LocalSite = true; cfg.RepSystemCfg.Priority = 100; cfg.RepSystemCfg.BulkTransfer = true; cfg.RepSystemCfg.AckTimeout = 2000; cfg.RepSystemCfg.BulkTransfer = true; cfg.RepSystemCfg.CheckpointDelay = 1500; cfg.RepSystemCfg.Clockskew(102, 100); cfg.RepSystemCfg.ConnectionRetry = 10; cfg.RepSystemCfg.DelayClientSync = false; cfg.RepSystemCfg.ElectionRetry = 5; cfg.RepSystemCfg.ElectionTimeout = 3000; cfg.RepSystemCfg.FullElectionTimeout = 5000; cfg.RepSystemCfg.HeartbeatMonitor = 100; cfg.RepSystemCfg.HeartbeatSend = 10; cfg.RepSystemCfg.LeaseTimeout = 1300; cfg.RepSystemCfg.AutoInit = true; cfg.RepSystemCfg.NoBlocking = false; cfg.RepSystemCfg.RepMgrAckPolicy = AckPolicy.ALL_PEERS; cfg.RepSystemCfg.RetransmissionRequest(10, 100); cfg.RepSystemCfg.Strict2Site = true; cfg.RepSystemCfg.UseMasterLeases = false; cfg.EventNotify = new EventNotifyDelegate(stuffHappened); DatabaseEnvironment env = DatabaseEnvironment.Open( home, cfg); // Get initial replication stats. ReplicationStats repStats = env.ReplicationSystemStats(); env.PrintReplicationSystemStats(); Assert.AreEqual(100, repStats.EnvPriority); Assert.AreEqual(1, repStats.CurrentElectionGenerationNumber); Assert.AreEqual(0, repStats.CurrentGenerationNumber); Assert.AreEqual(0, repStats.AppliedTransactions); Assert.AreEqual(0, repStats.ElectionDataGeneration); // Start a master site with replication manager. env.RepMgrStartMaster(3); // Open a btree database and write some data. Transaction txn = env.BeginTransaction(); BTreeDatabaseConfig dbConfig = new BTreeDatabaseConfig(); dbConfig.Creation = CreatePolicy.IF_NEEDED; dbConfig.Env = env; dbConfig.PageSize = 512; BTreeDatabase db = BTreeDatabase.Open(dbName, dbConfig, txn); txn.Commit(); txn = env.BeginTransaction(); for (int i = 0; i < 5; i++) { db.Put(new DatabaseEntry(BitConverter.GetBytes(i)), new DatabaseEntry(BitConverter.GetBytes(i)), txn); } txn.Commit(); Console.WriteLine( "Master: Finished initialization and data#1."); // Client site could enter now. clientStartSignal.Set(); Console.WriteLine( "Master: Wait for Client to join and get #1."); Console.WriteLine("..."); // Put some new data into master site. txn = env.BeginTransaction(); for (int i = 10; i < 15; i++) { db.Put(new DatabaseEntry(BitConverter.GetBytes(i)), new DatabaseEntry(BitConverter.GetBytes(i)), txn); } txn.Commit(); Console.WriteLine( "Master: Write something new, data #2."); Console.WriteLine("Master: Wait for client to read #2..."); // Get the stats. repStats = env.ReplicationSystemStats(true); env.PrintReplicationSystemStats(); Assert.LessOrEqual(0, repStats.AppliedTransactions); Assert.LessOrEqual(0, repStats.AwaitedLSN.LogFileNumber); Assert.LessOrEqual(0, repStats.AwaitedLSN.Offset); Assert.LessOrEqual(0, repStats.AwaitedPage); Assert.LessOrEqual(0, repStats.BadGenerationMessages); Assert.LessOrEqual(0, repStats.BulkBufferFills); Assert.LessOrEqual(0, repStats.BulkBufferOverflows); Assert.LessOrEqual(0, repStats.BulkBufferTransfers); Assert.LessOrEqual(0, repStats.BulkRecordsStored); Assert.LessOrEqual(0, repStats.ClientServiceRequests); Assert.LessOrEqual(0, repStats.ClientServiceRequestsMissing); Assert.IsInstanceOf(typeof(bool), repStats.ClientStartupComplete); Assert.AreEqual(2, repStats.CurrentElectionGenerationNumber); Assert.AreEqual(1, repStats.CurrentGenerationNumber); Assert.LessOrEqual(0, repStats.CurrentQueuedLogRecords); Assert.LessOrEqual(0, repStats.CurrentWinner); Assert.LessOrEqual(0, repStats.CurrentWinnerMaxLSN.LogFileNumber); Assert.LessOrEqual(0, repStats.CurrentWinnerMaxLSN.Offset); Assert.LessOrEqual(0, repStats.DuplicateLogRecords); Assert.LessOrEqual(0, repStats.DuplicatePages); Assert.LessOrEqual(0, repStats.DupMasters); Assert.LessOrEqual(0, repStats.ElectionGenerationNumber); Assert.LessOrEqual(0, repStats.ElectionPriority); Assert.LessOrEqual(0, repStats.Elections); Assert.LessOrEqual(0, repStats.ElectionStatus); Assert.LessOrEqual(0, repStats.ElectionsWon); Assert.LessOrEqual(0, repStats.ElectionTiebreaker); Assert.LessOrEqual(0, repStats.ElectionTimeSec); Assert.LessOrEqual(0, repStats.ElectionTimeUSec); Assert.AreEqual(repStats.EnvID, repStats.MasterEnvID); Assert.LessOrEqual(0, repStats.EnvPriority); Assert.LessOrEqual(0, repStats.FailedMessageSends); Assert.LessOrEqual(0, repStats.ForcedRerequests); Assert.LessOrEqual(0, repStats.IgnoredMessages); Assert.LessOrEqual(0, repStats.MasterChanges); Assert.LessOrEqual(0, repStats.MasterEnvID); Assert.LessOrEqual(0, repStats.MaxLeaseSec); Assert.LessOrEqual(0, repStats.MaxLeaseUSec); Assert.LessOrEqual(0, repStats.MaxPermanentLSN.Offset); Assert.LessOrEqual(0, repStats.MaxQueuedLogRecords); Assert.LessOrEqual(0, repStats.MessagesSent); Assert.LessOrEqual(0, repStats.MissedLogRecords); Assert.LessOrEqual(0, repStats.MissedPages); Assert.LessOrEqual(0, repStats.NewSiteMessages); Assert.LessOrEqual(repStats.MaxPermanentLSN.LogFileNumber, repStats.NextLSN.LogFileNumber); if (repStats.MaxPermanentLSN.LogFileNumber == repStats.NextLSN.LogFileNumber) { Assert.Less(repStats.MaxPermanentLSN.Offset, repStats.NextLSN.Offset); } Assert.LessOrEqual(0, repStats.NextPage); Assert.LessOrEqual(0, repStats.Outdated); Assert.LessOrEqual(0, repStats.QueuedLogRecords); Assert.LessOrEqual(0, repStats.ReceivedLogRecords); Assert.LessOrEqual(0, repStats.ReceivedMessages); Assert.LessOrEqual(0, repStats.ReceivedPages); Assert.LessOrEqual(0, repStats.RegisteredSites); Assert.LessOrEqual(0, repStats.RegisteredSitesNeeded); Assert.LessOrEqual(0, repStats.Sites); Assert.LessOrEqual(0, repStats.StartSyncMessagesDelayed); Assert.AreEqual(2, repStats.Status); Assert.LessOrEqual(0, repStats.Throttled); Assert.LessOrEqual(0, repStats.Votes); // Get replication manager statistics. RepMgrStats repMgrStats = env.RepMgrSystemStats(true); Assert.AreEqual(0, repMgrStats.AutoTakeovers); Assert.LessOrEqual(0, repMgrStats.DroppedConnections); Assert.LessOrEqual(0, repMgrStats.DroppedMessages); Assert.LessOrEqual(0, repMgrStats.ElectionThreads); Assert.LessOrEqual(0, repMgrStats.FailedConnections); Assert.LessOrEqual(0, repMgrStats.FailedMessages); Assert.Less(0, repMgrStats.MaxElectionThreads); Assert.LessOrEqual(0, repMgrStats.QueuedMessages); // Print them out. env.PrintRepMgrSystemStats(); // Wait until client has finished reading. masterCloseSignal.WaitOne(); Console.WriteLine("Master: Leave as well."); // Close all. db.Close(false); env.LogFlush(); env.Close(); }