コード例 #1
0
        /// <summary>
        /// Write pages into disk and confirm transaction in wal-index. Returns true if any dirty page was updated
        /// </summary>
        public bool Commit()
        {
            if (_disposed)
            {
                return(false);
            }

            LOG($"commit transaction ({_transPages.TransactionSize} pages)", "TRANSACTION");

            if (_mode == LockMode.Write || _transPages.HeaderChanged)
            {
                // persist all dirty page as commit mode (mark last page as IsConfirm)
                var count = this.PersistDirtyPages(true);

                // update wal-index (if any page was added into log disk)
                if (count > 0)
                {
                    _walIndex.ConfirmTransaction(_transactionID, _transPages.DirtyPages.Values);
                }
            }

            // dispose all snapshosts
            foreach (var snapshot in _snapshots.Values)
            {
                snapshot.Dispose();
            }

            this.Done();

            return(true);
        }
コード例 #2
0
        /// <summary>
        /// Write pages into disk and confirm transaction in wal-index. Returns true if any dirty page was updated
        /// After commit, all snapshot are closed
        /// </summary>
        public async Task Commit()
        {
            ENSURE(_state == TransactionState.Active, $"transaction must be active to commit (current state: {_state})");

            LOG($"commit transaction ({_transPages.TransactionSize} pages)", "TRANSACTION");

            if (_mode == LockMode.Write || _transPages.HeaderChanged)
            {
                // persist all dirty page as commit mode (mark last page as IsConfirm)
                var count = await this.PersistDirtyPages(true);

                // update wal-index (if any page was added into log disk)
                if (count > 0)
                {
                    _walIndex.ConfirmTransaction(_transactionID, _transPages.DirtyPages.Values);
                }
            }

            // dispose all snapshosts
            foreach (var snapshot in _snapshots.Values)
            {
                snapshot.Dispose();
            }

            _state = TransactionState.Committed;
        }