Esempio n. 1
0
        public bool openDbTest(
            string sDbName,
            DbSystem dbSystem)
        {
            Db db = null;

            beginTest("Open Database Test (" + sDbName + ")");

            try
            {
                db = dbSystem.dbOpen(sDbName, null, null, null, false);
            }
            catch (XFlaimException ex)
            {
                endTest(false, ex, "opening database");
                return(false);
            }
            if (db != null)
            {
                db.close();
                db = null;
            }
            endTest(false, true);
            return(true);
        }
Esempio n. 2
0
        //-----------------------------------------------------------------------
        // This method opens or creates the sample database.
        //-----------------------------------------------------------------------
        static Db createOrOpenDatabase(DbSystem dbSystem, out bool bCreatedDatabase)
        {
            Db     db;
            string sDbName = "sample.db";

            // Try to open a database.  If that fails, create it.  The following
            // example creates the database in the current directory.  However,
            // a full or partial file name may be specified.
            // NOTE: Multiple threads should each do their own open of the
            // database and get back their own Db object.

            try
            {
                db = dbSystem.dbOpen(sDbName, null, null, null, false);
            }
            catch (XFlaimException ex)
            {
                if (ex.getRCode() != RCODE.NE_XFLM_IO_PATH_NOT_FOUND)
                {
                    throw ex;
                }
                db = dbSystem.dbCreate(sDbName, null, null, null, null, null);
                bCreatedDatabase = true;
            }
            return(db);
        }
Esempio n. 3
0
        public bool backupDbTest(
            string sDbName,
            string sBackupPath,
            DbSystem dbSystem)
        {
            Db             db           = null;
            Backup         backup       = null;
            MyBackupStatus backupStatus = null;

            // Try backing up the database

            beginTest("Backup Database Test (" + sDbName + " to directory \"" + sBackupPath + "\")");

            try
            {
                db = dbSystem.dbOpen(sDbName, null, null, null, false);
            }
            catch (XFlaimException ex)
            {
                endTest(false, ex, "opening database");
                return(false);
            }

            // Backup the database

            try
            {
                backup = db.backupBegin(true, false, 0);
            }
            catch (XFlaimException ex)
            {
                endTest(false, ex, "calling backupBegin");
                return(false);
            }

            // Perform the backup

            backupStatus = new MyBackupStatus();
            try
            {
                backup.backup(sBackupPath, null, null, backupStatus);
            }
            catch (XFlaimException ex)
            {
                endTest(backupStatus.outputLines(), ex, "calling backup");
                return(false);
            }

            // End the backup

            try
            {
                backup.endBackup();
            }
            catch (XFlaimException ex)
            {
                endTest(backupStatus.outputLines(), ex, "calling endBackup");
                return(false);
            }

            db.close();
            db = null;
            endTest(backupStatus.outputLines(), true);
            return(true);
        }
Esempio n. 4
0
        public bool statsTests(
            string sDbName,
            DbSystem dbSystem)
        {
            Db                  db    = null;
            DbSystemStats       stats = null;
            uint                uiNumDatabases;
            uint                uiStartTime;
            uint                uiStopTime;
            CS_XFLM_DB_STATS    dbStats    = null;
            CS_XFLM_LFILE_STATS lFileStats = null;

            beginTest("Start statistics");

            try
            {
                dbSystem.startStats();
            }
            catch (XFlaimException ex)
            {
                endTest(false, ex, "starting statistics");
                return(false);
            }
            endTest(false, true);

            // Open a database to make some statistics happen

            beginTest("Open Database Test (" + sDbName + ")");

            try
            {
                db = dbSystem.dbOpen(sDbName, null, null, null, false);
            }
            catch (XFlaimException ex)
            {
                endTest(false, ex, "opening database");
                return(false);
            }
            if (db != null)
            {
                db.close();
                db = null;
            }
            endTest(false, true);

            // Stop collecting statistics

            beginTest("Stop statistics");

            try
            {
                dbSystem.stopStats();
            }
            catch (XFlaimException ex)
            {
                endTest(false, ex, "stopping statistics");
                return(false);
            }
            endTest(false, true);

            // Get statistics

            beginTest("Get statistics");

            try
            {
                stats = dbSystem.getStats();
            }
            catch (XFlaimException ex)
            {
                endTest(false, ex, "getting statistics");
                return(false);
            }
            endTest(false, true);

            // Get general statistics

            beginTest("Get general statistics");

            try
            {
                stats.getGeneralStats(out uiNumDatabases, out uiStartTime,
                                      out uiStopTime);
            }
            catch (XFlaimException ex)
            {
                endTest(false, ex, "getting statistics");
                return(false);
            }
            endTest(false, true);
            printUIntStat(0, "Databases", uiNumDatabases);
            printUIntStat(0, "Start Time", uiStartTime);
            printUIntStat(0, "Stop Time", uiStopTime);

            // Get Database statistics

            for (uint uiLoop = 0; uiLoop < uiNumDatabases; uiLoop++)
            {
                beginTest("Get database statistics for DB#" + uiLoop);

                try
                {
                    dbStats = stats.getDbStats(uiLoop, dbStats);
                }
                catch (XFlaimException ex)
                {
                    endTest(false, ex, "getting database statistics");
                    return(false);
                }
                endTest(false, true);
                printStrStat(0, "Database Name", dbStats.sDbName);
                printUIntStat(0, "Logical File Count", dbStats.uiNumLFiles);
                System.Console.WriteLine("Read Transactions");
                printCountTimeStat(1, "Committed Transactions", dbStats.ReadTransStats.CommittedTrans);
                printCountTimeStat(1, "Aborted Transactions", dbStats.ReadTransStats.AbortedTrans);
                System.Console.WriteLine("Update Transactions");
                printCountTimeStat(1, "Committed Transactions", dbStats.UpdateTransStats.CommittedTrans);
                printCountTimeStat(1, "Aborted Transactions", dbStats.UpdateTransStats.AbortedTrans);
                printCountTimeStat(1, "Group Completes", dbStats.UpdateTransStats.GroupCompletes);
                printULongStat(1, "Group Finished", dbStats.UpdateTransStats.ulGroupFinished);
                printBlockIOStats(0, "LFH Block Stats", dbStats.LFHBlockStats);
                printBlockIOStats(0, "Avail Block Stats", dbStats.AvailBlockStats);
                printDiskIOStats(0, "Database Header Writes", dbStats.DbHdrWrites);
                printDiskIOStats(0, "Log Block Writes", dbStats.LogBlockWrites);
                printDiskIOStats(0, "Log Block Restores", dbStats.LogBlockRestores);
                printDiskIOStats(0, "Log Block Reads", dbStats.LogBlockReads);
                printUIntStat(0, "Log Block Checksum Errors", dbStats.uiLogBlockChkErrs);
                printUIntStat(0, "Read Errors", dbStats.uiReadErrors);
                printCountTimeStat(0, "No Locks", dbStats.LockStats.NoLocks);
                printCountTimeStat(0, "Waiting For Lock", dbStats.LockStats.WaitingForLock);
                printCountTimeStat(0, "Held Lock", dbStats.LockStats.HeldLock);

                for (uint uiLoop2 = 0; uiLoop2 < dbStats.uiNumLFiles; uiLoop2++)
                {
                    beginTest("  Get database statistics for DB#" + uiLoop + ", LFile#" + uiLoop2);

                    try
                    {
                        lFileStats = stats.getLFileStats(uiLoop, uiLoop2, lFileStats);
                    }
                    catch (XFlaimException ex)
                    {
                        endTest(false, ex, "getting logical file statistics");
                        return(false);
                    }
                    endTest(false, true);
                    System.Console.WriteLine("  LOGICAL FILE {0} ({1})",
                                             lFileStats.uiLFileNum, lFileStats.eLfType);
                    printBlockIOStats(2, "Root Block Stats", lFileStats.RootBlockStats);
                    printBlockIOStats(2, "Middle Block Stats", lFileStats.MiddleBlockStats);
                    printBlockIOStats(2, "Leaf Block Stats", lFileStats.LeafBlockStats);
                    printULongStat(2, "Block Splits", lFileStats.ulBlockSplits);
                    printULongStat(2, "Block Combines", lFileStats.ulBlockCombines);
                }
            }

            return(true);
        }