internal ActiveTransaction(DB_TXN_ACTIVE active, byte[] GlobalID, string Name) { txn = active; _lsn = new LSN(txn.lsn.file, txn.lsn.offset); _read_lsn = new LSN(txn.read_lsn.file, txn.read_lsn.offset); gid = GlobalID; txnname = Name; }
internal RepProcMsgResult(int ret, LSN dblsn) { RetLsn = null; switch (ret) { case DbConstants.DB_REP_DUPMASTER: Result = ProcMsgResult.DUPLICATE_MASTER; break; case DbConstants.DB_REP_HOLDELECTION: Result = ProcMsgResult.HOLD_ELECTION; break; case DbConstants.DB_REP_IGNORE: Result = ProcMsgResult.IGNORED; break; case DbConstants.DB_REP_ISPERM: Result = ProcMsgResult.IS_PERMANENT; break; case DbConstants.DB_REP_JOIN_FAILURE: Result = ProcMsgResult.JOIN_FAILURE; break; case DbConstants.DB_REP_NEWSITE: Result = ProcMsgResult.NEW_SITE; break; case DbConstants.DB_REP_NOTPERM: Result = ProcMsgResult.NOT_PERMANENT; break; case 0: Result = ProcMsgResult.SUCCESS; break; default: Result = ProcMsgResult.ERROR; break; } }
internal TransactionStats(Internal.TxnStatStruct stats) { st = stats.st; lastCkp = new LSN(st.st_last_ckp.file, st.st_last_ckp.offset); txns = new List<ActiveTransaction>(); for (int i = 0; i < st.st_nactive; i++) txns.Add(new ActiveTransaction( stats.st_txnarray[i], stats.st_txngids[i], stats.st_txnnames[i])); }
internal static DB_LSN getDB_LSN(LSN inp) { if (inp == null) return null; DB_LSN ret = new DB_LSN(); ret.file = inp.LogFileNumber; ret.offset = inp.Offset; return ret; }
internal ReplicationStats(Internal.ReplicationStatStruct stats) { st = stats; next = new LSN(st.st_next_lsn.file, st.st_next_lsn.offset); waiting = new LSN(st.st_waiting_lsn.file, st.st_waiting_lsn.offset); maxPerm = new LSN(st.st_max_perm_lsn.file, st.st_max_perm_lsn.offset); winner = new LSN(st.st_election_lsn.file, st.st_election_lsn.offset); }
internal RepMgrSite(DB_REPMGR_SITE site) { EId = site.eid; Address = new ReplicationHostAddress(site.host, site.port); maxAcknowledgedLSN = new LSN(site.max_ack_lsn.file, site.max_ack_lsn.offset); isConnected = (site.status == DbConstants.DB_REPMGR_CONNECTED); isElectable = (site.flags & DbConstants.DB_REPMGR_ISELECTABLE) != 0; isPeer = (site.flags & DbConstants.DB_REPMGR_ISPEER) != 0; isView = (site.flags & DbConstants.DB_REPMGR_ISVIEW) != 0; }
/// <summary> /// Instantiate a new LogVerifyConfig object, with the default /// configuration settings. /// </summary> public LogVerifyConfig() { envhome = null; dbfile = null; dbname = null; caf = true; verbose = false; startlsn = new LSN(0, 0); endlsn = new LSN(0, 0); cachesz = 0; }
/// <summary> /// Compare two LSNs. /// </summary> /// <param name="lsn1">The first LSN to compare</param> /// <param name="lsn2">The second LSN to compare</param> /// <returns> /// 0 if they are equal, 1 if lsn1 is greater than lsn2, and -1 if lsn1 /// is less than lsn2. /// </returns> public static int Compare(LSN lsn1, LSN lsn2) { DB_LSN a = new DB_LSN(); a.offset = lsn1.Offset; a.file = lsn1.LogFileNumber; DB_LSN b = new DB_LSN(); b.offset = lsn2.Offset; b.file = lsn2.LogFileNumber; return libdb_csharp.log_compare(a, b); }
private static int doRepTransport(IntPtr envp, IntPtr controlp, IntPtr recp, IntPtr lsnp, int envid, uint flags) { DB_ENV dbenv = new DB_ENV(envp, false); DBT control = new DBT(controlp, false); DBT rec = new DBT(recp, false); DB_LSN tmplsn = new DB_LSN(lsnp, false); LSN dblsn = new LSN(tmplsn.file, tmplsn.offset); return dbenv.api2_internal.transportHandler( DatabaseEntry.fromDBT(control), DatabaseEntry.fromDBT(rec), dblsn, envid, flags); }
internal TransactionStats(Internal.TxnStatStruct stats) { st = stats.st; lastCkp = new LSN(st.st_last_ckp.file, st.st_last_ckp.offset); txns = new List <ActiveTransaction>(); for (int i = 0; i < st.st_nactive; i++) { txns.Add(new ActiveTransaction( stats.st_txnarray[i], stats.st_txngids[i], stats.st_txnnames[i])); } }
internal static DB_LSN getDB_LSN(LSN inp) { if (inp == null) { return(null); } DB_LSN ret = new DB_LSN(); ret.file = inp.LogFileNumber; ret.offset = inp.Offset; return(ret); }
/// <summary> /// Compare two LSNs. /// </summary> /// <param name="lsn1">The first LSN to compare</param> /// <param name="lsn2">The second LSN to compare</param> /// <returns> /// 0 if they are equal, 1 if lsn1 is greater than lsn2, and -1 if lsn1 /// is less than lsn2. /// </returns> public static int Compare(LSN lsn1, LSN lsn2) { DB_LSN a = new DB_LSN(); a.offset = lsn1.Offset; a.file = lsn1.LogFileNumber; DB_LSN b = new DB_LSN(); b.offset = lsn2.Offset; b.file = lsn2.LogFileNumber; return(libdb_csharp.log_compare(a, b)); }
public void TestCurrentRecord() { testName = "TestCurrentRecord"; SetUpTest(true); DatabaseEnvironment env; RecnoDatabase db; Logging(testHome, testName, out env, out db); // Get log cursor to read/write log. LogCursor logCursor = env.GetLogCursor(); /* * Move the cursor to the beginning of the #1 log file. * Get the current LSN and confirm that is the position * the cursor is moved to. */ LSN lsn = new LSN(1, 0); logCursor.Move(lsn); Assert.IsNotNull(logCursor.CurrentRecord.Data); // Close all. logCursor.Close(); db.Close(); env.Close(); }
public void TestLsn() { testName = "TestLsn"; SetUpTest(true); LSN lsn = new LSN(12, 411); Assert.AreEqual(12, lsn.LogFileNumber); Assert.AreEqual(411, lsn.Offset); LSN newLsn = new LSN(15, 410); Assert.AreEqual(0, LSN.Compare(lsn, lsn)); Assert.Greater(0, LSN.Compare(lsn, newLsn)); }
/// <summary> /// Map an LSN object to a log filename /// </summary> /// <param name="logSeqNum"> /// The DB_LSN structure for which a filename is wanted. /// </param> /// <returns> /// The name of the file containing the record named by /// <paramref name="logSeqNum"/>. /// </returns> public string LogFile(LSN logSeqNum) { return dbenv.log_file(LSN.getDB_LSN(logSeqNum)); }
public void TestLogFile() { testName = "TestLogFile"; SetUpTest(true); // Open environment and configure logging subsystem. DatabaseEnvironmentConfig cfg = new DatabaseEnvironmentConfig(); cfg.Create = true; cfg.UseTxns = true; cfg.AutoCommit = true; cfg.UseLocking = true; cfg.UseMPool = true; cfg.UseLogging = true; cfg.MPoolSystemCfg = new MPoolConfig(); cfg.MPoolSystemCfg.CacheSize = new CacheInfo(0, 1048576, 1); cfg.LogSystemCfg = new LogConfig(); cfg.LogSystemCfg.AutoRemove = false; cfg.LogSystemCfg.BufferSize = 10240; cfg.LogSystemCfg.Dir = "./"; cfg.LogSystemCfg.FileMode = 755; cfg.LogSystemCfg.ForceSync = true; cfg.LogSystemCfg.InMemory = false; cfg.LogSystemCfg.MaxFileSize = 1048576; cfg.LogSystemCfg.NoBuffer = false; cfg.LogSystemCfg.RegionSize = 204800; cfg.LogSystemCfg.ZeroOnCreate = true; DatabaseEnvironment env = DatabaseEnvironment.Open(testHome, cfg); // Open database. Transaction allTxn = env.BeginTransaction(); TransactionConfig txnConfig = new TransactionConfig(); txnConfig.Name = "OpenTransaction"; Transaction openTxn = env.BeginTransaction(txnConfig, allTxn); BTreeDatabaseConfig dbConfig = new BTreeDatabaseConfig(); dbConfig.Creation = CreatePolicy.IF_NEEDED; dbConfig.Env = env; BTreeDatabase db = BTreeDatabase.Open( testName + ".db", dbConfig, openTxn); List<ActiveTransaction> activeTxns = env.TransactionSystemStats().Transactions; for (int i = 0; i < activeTxns.Count; i++) if (activeTxns[i].Name == "OpenTransaction") { LSN lsn = new LSN( activeTxns[i].Begun.LogFileNumber, activeTxns[i].Begun.Offset); env.LogFlush(lsn); string fileName = env.LogFile(lsn); } openTxn.Commit(); // Write "##" to log before putting data into database. env.WriteToLog("##"); // Write 1000 records into database. TransactionConfig writeTxnConfig = new TransactionConfig(); writeTxnConfig.Name = "WriteTxn"; Transaction writeTxn = env.BeginTransaction(writeTxnConfig, allTxn); byte[] byteArr = new byte[1024]; for (int i = 0; i < 1000; i++) { db.Put(new DatabaseEntry(BitConverter.GetBytes(i)), new DatabaseEntry(byteArr), writeTxn); env.LogFlush(); env.WriteToLog("#" + i.ToString(), writeTxn); } activeTxns = env.TransactionSystemStats().Transactions; for (int i = 0; i < activeTxns.Count; i++) if (activeTxns[i].Name == "WriteTxn") { LSN lsn = new LSN( activeTxns[i].Begun.LogFileNumber, activeTxns[i].Begun.Offset); env.LogFlush(lsn); string fileName = env.LogFile(lsn); } writeTxn.Commit(); db.Close(); // Write "##" after data has been put. env.WriteToLog("##"); List<string> logFiles = env.LogFiles(true); env.LogWrite(new DatabaseEntry(), true); env.RemoveUnusedLogFiles(); allTxn.Commit(); env.Close(); }
/// <summary> /// Write log records to disk. /// </summary> /// <param name="logSeqNum"> /// All log records with LSN values less than or equal to /// <paramref name="logSeqNum"/> are written to disk. If null, all /// records in the log are flushed. /// </param> public void LogFlush(LSN logSeqNum) { dbenv.log_flush(LSN.getDB_LSN(logSeqNum)); }
public void TesCurrentLSN() { testName = "TesCurrentLSN"; SetUpTest(true); RecnoDatabase db; Logging(testHome, testName, out env, out db); // Get log cursor to read/write log. LogCursor logCursor = env.GetLogCursor(); /* * Move the cursor to the beginning of the #1 log file. * Get the current LSN and confirm that is the position * the cursor is moved to. */ LSN lsn = new LSN(1, 0); logCursor.Move(lsn); Assert.AreEqual(lsn.LogFileNumber, logCursor.CurrentLSN.LogFileNumber); Assert.AreEqual(lsn.Offset, logCursor.CurrentLSN.Offset); // Close all. logCursor.Close(); db.Close(); env.Close(); }
public void TestMove() { testName = "TestMove"; SetUpTest(true); DatabaseEnvironment env; RecnoDatabase db; Logging(testHome, testName, out env, out db); // Get log cursor to read/write log. LogCursor logCursor = env.GetLogCursor(); // Move the cursor to specified location in log files. LSN lsn = new LSN(1, 0); Assert.IsTrue(logCursor.Move(lsn)); // Close all. logCursor.Close(); db.Close(); env.Close(); }
public void TestLsn() { testName = "TestLsn"; testHome = testFixtureHome + "/" + testName; Configuration.ClearDir(testHome); LSN lsn = new LSN(12, 411); Assert.AreEqual(12, lsn.LogFileNumber); Assert.AreEqual(411, lsn.Offset); LSN newLsn = new LSN(15, 410); Assert.AreEqual(0, LSN.Compare(lsn, lsn)); Assert.Greater(0, LSN.Compare(lsn, newLsn)); }
/// <summary> /// Flush modified pages in the cache with log sequence numbers less /// than <paramref name="minLSN"/> to their backing files. /// </summary> /// <remarks> /// Pages in the cache that cannot be immediately written back to disk /// (for example, pages that are currently in use by another thread of /// control) are waited for and written to disk as soon as it is /// possible to do so. /// </remarks> /// <param name="minLSN"> /// All modified pages with a log sequence number less than the minLSN /// parameter are written to disk. If null, all modified pages in the /// cache are written to disk. /// </param> public void SyncMemPool(LSN minLSN) { dbenv.memp_sync(LSN.getDB_LSN(minLSN)); }
/// <summary> /// Process an incoming replication message sent by a member of the /// replication group to the local database environment. /// </summary> /// <remarks> /// <para> /// RepProcessMessage is not called by most replication applications. It /// should only be called by applications implementing their own network /// transport layer, explicitly holding replication group elections and /// handling replication messages outside of the replication manager /// framework. /// </para> /// <para> /// For implementation reasons, all incoming replication messages must /// be processed using the same <see cref="DatabaseEnvironment"/> /// object. It is not required that a single thread of control process /// all messages, only that all threads of control processing messages /// use the same object. /// </para> /// <para> /// Before calling this method, the <see cref="RepTransport"/> delegate /// must already have been configured to send replication messages. /// </para> /// </remarks> /// <param name="control"> /// A copy of the control parameter specified by Berkeley DB on the /// sending environment. /// </param> /// <param name="rec"> /// A copy of the rec parameter specified by Berkeley DB on the sending /// environment. /// </param> /// <param name="envid"> /// The local identifier that corresponds to the environment that sent /// the message to be processed (see Replication environment IDs in the /// Programmer's Reference Guide for more information).. /// </param> /// <returns>The result of processing a message</returns> public RepProcMsgResult RepProcessMessage( DatabaseEntry control, DatabaseEntry rec, int envid) { DB_LSN dblsn = new DB_LSN(); int ret = dbenv.rep_process_message(control, rec, envid, dblsn); LSN lsnp = new LSN(dblsn.file, dblsn.offset); RepProcMsgResult result = new RepProcMsgResult(ret, lsnp); if (result.Result == RepProcMsgResult.ProcMsgResult.ERROR) DatabaseException.ThrowException(ret); return result; }