/// <summary>
        /// Clear cache, discard journal file
        /// </summary>
        public void Rollback()
        {
            // clear all dirty pages from memory
            _cache.DiscardDirtyPages();

            _disk.ClearJournal();
        }
Exemple #2
0
        /// <summary>
        /// Encapsulate all operations in a single write transaction
        /// </summary>
        private T Transaction <T>(string collection, bool addIfNotExists, Func <CollectionPage, T> action)
        {
            // always starts write operation locking database
            using (_locker.Write())
            {
                try
                {
                    var col = this.GetCollectionPage(collection, addIfNotExists);

                    var result = action(col);

                    _trans.PersistDirtyPages();

                    return(result);
                }
                catch (Exception ex)
                {
                    _log.Write(Logger.ERROR, ex.Message);

                    // if an error occurs during an operation, rollback must be called to avoid datafile inconsistent
                    _cache.DiscardDirtyPages();

                    throw;
                }
            }
        }
        /// <summary>
        /// Clear cache, discard journal file
        /// </summary>
        public void Rollback()
        {
            // clear all dirty pages from memory
            _cache.DiscardDirtyPages();
            var header = _pager.GetPage <HeaderPage>(0);

            _disk.ClearJournal(header.LastPageID);
        }