/*
  * Get the length of the whole database.
  */
 public long Length()
 {
     try
     {
         return(BitConverter.ToInt64(hashDatabase.Get(new DatabaseEntry(BitConverter.GetBytes(0L))).Value.Data));
     }
     catch (NotFoundException)
     {
         hashDatabase.Put(
             new DatabaseEntry(BitConverter.GetBytes(0L)),
             new DatabaseEntry(BitConverter.GetBytes(0L))
             );
         hashDatabase.Sync();
         return(0);
     }
 }
예제 #2
0
        public void TestCompactWithoutTxn()
        {
            int i, nRecs;

            nRecs    = 10000;
            testName = "TestCompactWithoutTxn";
            SetUpTest(true);
            string hashDBFileName = testHome + "/" + testName + ".db";

            HashDatabaseConfig hashDBConfig = new HashDatabaseConfig();

            hashDBConfig.Creation = CreatePolicy.ALWAYS;
            // The minimum page size
            hashDBConfig.PageSize       = 512;
            hashDBConfig.HashComparison =
                new EntryComparisonDelegate(dbIntCompare);
            using (HashDatabase hashDB = HashDatabase.Open(
                       hashDBFileName, hashDBConfig)) {
                DatabaseEntry key;
                DatabaseEntry data;

                // Fill the database with entries from 0 to 9999
                for (i = 0; i < nRecs; i++)
                {
                    key  = new DatabaseEntry(BitConverter.GetBytes(i));
                    data = new DatabaseEntry(BitConverter.GetBytes(i));
                    hashDB.Put(key, data);
                }

                /*
                 * Delete entries below 500, between 3000 and
                 * 5000 and above 7000
                 */
                for (i = 0; i < nRecs; i++)
                {
                    if (i < 500 || i > 7000 || (i < 5000 && i > 3000))
                    {
                        key = new DatabaseEntry(BitConverter.GetBytes(i));
                        hashDB.Delete(key);
                    }
                }

                hashDB.Sync();
                long fileSize = new FileInfo(hashDBFileName).Length;

                // Compact database
                CompactConfig cCfg = new CompactConfig();
                cCfg.FillPercentage = 30;
                cCfg.Pages          = 10;
                cCfg.Timeout        = 1000;
                cCfg.TruncatePages  = true;
                cCfg.start          = new DatabaseEntry(BitConverter.GetBytes(1));
                cCfg.stop           = new DatabaseEntry(BitConverter.GetBytes(7000));
                CompactData compactData = hashDB.Compact(cCfg);
                Assert.IsFalse((compactData.Deadlocks == 0) &&
                               (compactData.Levels == 0) &&
                               (compactData.PagesExamined == 0) &&
                               (compactData.PagesFreed == 0) &&
                               (compactData.PagesTruncated == 0));

                hashDB.Sync();
                long compactedFileSize = new FileInfo(hashDBFileName).Length;
                Assert.Less(compactedFileSize, fileSize);
            }
        }
 /*
  * Syncronizes the database with the data from RAM to HDD.
  */
 public void SyncToDisk()
 {
     hashDatabase.Sync();
     urlDatabase.Sync();
 }
 public void Sync()
 {
     logger.LogInformation("I'm syncing!");
     db.Sync();
 }