Ejemplo n.º 1
0
        public void Commit(ITransactionContext tx, int partitionTtl)
        {
            if (Access != EFileAccess.ReadWrite)
            {
                throw new NFSdbCommitFailedException(
                          "Journal opened in readonly mode. Transaction commit is not allowed");
            }

            bool isUpdated = false;

            try
            {
                PartitionTxData lastAppendPartition = tx.GetPartitionTx();
                // Non-empty commit.
                if (lastAppendPartition != null)
                {
                    var lastPartitionID = lastAppendPartition.PartitionID;
                    var rowIdFrom       = _lastTxRec != null ? _lastTxRec.JournalMaxRowID : 0;

                    for (int i = tx.Partitions.Count - 1; i >= 0; i--)
                    {
                        var partition = tx.Partitions[i];
                        if (partition != null)
                        {
                            if (tx.IsParitionUpdated(partition.PartitionID, _lastTransactionLog))
                            {
                                partition.Commit(tx.GetPartitionTx(partition.PartitionID));
                                tx.RemoveRef(partitionTtl);
                                isUpdated = true;
                            }
                        }
                    }

                    if (isUpdated)
                    {
                        var lastPartition = GetPartitionByID(tx, lastPartitionID);
                        var rec           = new TxRec();
                        lastPartition.SetTxRec(tx, rec);
                        // _symbolTxSupport.SetTxRec(tx, rec);
                        _txLog.Create(rec);
                        _lastTxRec = rec;

                        var onCommited = OnCommited;
                        if (onCommited != null)
                        {
                            onCommited(rowIdFrom, _lastTxRec.JournalMaxRowID);
                        }
                    }
                    tx.SetCommited();
                }
            }
            catch (Exception ex)
            {
                throw new NFSdbCommitFailedException(
                          "Error commiting transaction. See InnerException for details.", ex);
            }
            _lastTransactionLog = tx;
        }