예제 #1
0
        private long GetTxAddress()
        {
            long oldAddress = -1;
            byte oldCheck   = 0;

            while (true)
            {
                var address = _data.ReadInt64(0);
                var check   = _data.ReadByte(8);

                if (address == oldAddress && check == oldCheck)
                {
                    throw new NFSdbInvalidTxAddressException(address,
                                                             "Check sum does not match address value and does not change on re-read");
                }

                var actual = GetCheckByte(address);
                if (actual == check)
                {
                    return(address);
                }
                oldAddress = address;
                oldCheck   = check;
            }
        }
예제 #2
0
        public IEnumerable <long> GetValues(int hashKey, PartitionTxData tx)
        {
            var keyRecOffset = _indexAddress.ReadOnlyKeyRecordOffset(hashKey, tx);

            if (keyRecOffset < 0)
            {
                yield break;
            }
            var blockOffset = _kData.ReadInt64(keyRecOffset);
            var rowCount    = _kData.ReadInt64(keyRecOffset + 8);

            // Key found.
            var rowBlockSize  = _indexAddress.RowBlockSize;
            var rowBlockCount = (int)(rowCount >> _rowBlockLenBitHint) + 1;
            var len           = (int)(rowCount & (_rowBlockLen - 1));

            if (len == 0)
            {
                rowBlockCount--;
                len = _rowBlockLen;
            }

            var rowBlockOffset = blockOffset;
            var partMaxRowId   = tx.NextRowID;

            // Loop blocks.
            for (int i = rowBlockCount - 1; i >= 0; i--)
            {
                // Loop cells.
                for (int k = len - 1; k >= 0; k--)
                {
                    var rowid = _rData.ReadInt64(rowBlockOffset - rowBlockSize + k * 8);
                    // yield return rowid;

                    // Check data visible.
                    if (partMaxRowId < 0 || rowid < partMaxRowId)
                    {
                        yield return(rowid);
                    }
                }

                // Next block.
                rowBlockOffset = _rData.ReadInt64(rowBlockOffset - 8);
                len            = _rowBlockLen;
            }
        }
예제 #3
0
        public byte[] GetBytes(long rowID, ReadContext readContext)
        {
            var beginOffset = _index.ReadInt64(rowID * MetadataConstants.STRING_INDEX_FILE_RECORD_SIZE);

            if (beginOffset == MetadataConstants.INDEX_NULL_DATA_VALUE)
            {
                return(null);
            }
            var arrayLength = ReadLength(_data, beginOffset);

            if (arrayLength == 0)
            {
                return(EMPTY_BYTE_ARRAY);
            }
            //var byteArray = readContext.AllocateByteArray2(arrayLength);
            var byteArray = new byte[arrayLength];

            _data.ReadBytes(beginOffset + HEADER_SIZE, byteArray, 0, arrayLength);
            return(byteArray);
        }
예제 #4
0
 public long GetInt64(long rowID)
 {
     return(_storage.ReadInt64(rowID * _sizeBytes));
 }