Пример #1
0
        public void Create(TxRec tx)
        {
            if (tx.LagName != null && tx.LagName.Length > 64)
            {
                throw new NFSdbTransactionStateExcepton("Partition name is too long");
            }

            var offset        = Math.Max(MIN_TX_ADDRESS, _data.GetAppendOffset());
            var orignalOffset = offset;

            // 4
            var size = tx.Size();

            WriteInt32(size, ref offset);

            // 8
            WriteInt64(tx.PrevTxAddress, ref offset);

            // 1
            WriteByte(tx.Command, ref offset);
            // 8
            WriteInt64(DateTime.Now.Ticks, ref offset);
            // 8
            WriteInt64(tx.JournalMaxRowID, ref offset);
            // 8
            WriteInt64(tx.LastPartitionTimestamp, ref offset);
            // 8
            WriteInt64(tx.LagSize, ref offset);
            // 1
            if (tx.LagName == null)
            {
                WriteByte(0, ref offset);
            }
            else
            {
                WriteByte(1, ref offset);
                // 2
                WriteByte((byte)tx.LagName.Length, ref offset);
                // TxRec.lagName.len
                foreach (char t in tx.LagName)
                {
                    WriteByte((byte)t, ref offset);
                }
            }
            // 2 + 4 * TxRec.symbolTableSizes.len
            WriteInt32Array(tx.SymbolTableSizes, ref offset);
            WriteInt64Array(tx.SymbolTableIndexPointers, ref offset);
            WriteInt64Array(tx.IndexPointers, ref offset);
            WriteInt64Array(tx.LagIndexPointers, ref offset);

            // write out TxRec address
            SetTxAddress(orignalOffset);
            _data.SetAppendOffset(orignalOffset + size);
        }
Пример #2
0
        public TxRec Get()
        {
            if (IsEmpty())
            {
                return(null);
            }

            var tx            = new TxRec();
            var offset        = GetTxAddress();
            var initialOffset = offset;

            int txSize = ReadInt32(ref offset);

            tx.PrevTxAddress = ReadInt64(ref offset);

            tx.Command                = ReadByte(ref offset);
            tx.Timestamp              = ReadInt64(ref offset);
            tx.JournalMaxRowID        = ReadInt64(ref offset);
            tx.LastPartitionTimestamp = ReadInt64(ref offset);
            tx.LagSize                = ReadInt64(ref offset);

            var sz = ReadByte(ref offset);

            if (sz == 0)
            {
                tx.LagName = null;
            }
            else
            {
                // lagName
                sz = ReadByte(ref offset);
                var nameBytes = new byte[sz];
                _data.ReadBytes(offset, nameBytes, 0, sz);
                tx.LagName = Encoding.ASCII.GetString(nameBytes);

                offset += sz;
            }

            // symbolTableSizes
            tx.SymbolTableSizes = ReadInt32Array(ref offset);

            //symbolTableIndexPointers
            tx.SymbolTableIndexPointers = ReadInt64Array(ref offset);

            //indexPointers
            tx.IndexPointers = ReadInt64Array(ref offset);

            //lagIndexPointers
            tx.LagIndexPointers = ReadInt64Array(ref offset);

            return(tx);
        }
Пример #3
0
        public static bool IsCommited(this TxRec txRec, DateTime partitionStartDate, int partitionID)
        {
            if (txRec == null)
            {
                return(false);
            }

            if (txRec.LastPartitionTimestamp != 0)
            {
                return(partitionStartDate <= DateUtils.UnixTimestampToDateTime(txRec.LastPartitionTimestamp));
            }

            var lastPartitionID = RowIDUtil.ToPartitionIDFromExternalRowID(txRec.JournalMaxRowID);

            return(partitionID <= lastPartitionID);
        }
        public void AddPartition(IPartition parition)
        {
            _paritions.Add(parition);

            while (_paritions.Count <= parition.PartitionID)
            {
                _paritions.Add(null);
            }
            _paritions[parition.PartitionID] = parition;

            if (_txData.Length < _paritions.Count)
            {
                var oldTx = _txData;
                _txData = new PartitionTxData[_paritions.Count + RESERVED_PARTITION_COUNT];
                Array.Copy(oldTx, _txData, oldTx.Length);
            }

            _txRec = null;
        }
        internal DeferredTransactionContext(TxState state,
                                            IUnsafePartitionManager paritionManager,
                                            TxRec txRec,
                                            int partitionTtlMs)
        {
            _state           = state;
            _paritionManager = paritionManager;

            _paritions = _state.Partitions;
            _locks     = _state.Locks;
            _locks.Clear();
            _readCache = _state.ReadContext;

            var lastPartition = _paritions.LastNotNull();

            _lastPartitionID = lastPartition != null ? lastPartition.PartitionID : -1;

            _txRec              = txRec;
            _partitionTtlMs     = partitionTtlMs;
            _txData             = new PartitionTxData[_paritions.Count + 1 + RESERVED_PARTITION_COUNT];
            LastAppendTimestamp = txRec != null?DateUtils.UnixTimestampToDateTime(txRec.LastPartitionTimestamp) : DateTime.MinValue;
        }