Пример #1
0
        void IterateRelation(uint relationIndex, string name)
        {
            var relationVersions     = new Dictionary <uint, RelationVersionInfo>();
            var lastPersistedVersion = ReadRelationVersions(relationIndex, name, relationVersions);

            _tr.TransactionProtector.Start();

            var o      = ObjectDB.AllRelationsPKPrefix.Length;
            var prefix = new byte[o + PackUnpack.LengthVUInt(relationIndex)];

            Array.Copy(ObjectDB.AllRelationsPKPrefix, prefix, o);
            PackUnpack.PackVUInt(prefix, ref o, relationIndex);

            var  protector             = _tr.TransactionProtector;
            long prevProtectionCounter = 0;
            long pos = 0;

            while (true)
            {
                protector.Start();
                if (pos == 0)
                {
                    _trkv.SetKeyPrefix(prefix);
                    if (!_trkv.FindFirstKey())
                    {
                        break;
                    }
                }
                else
                {
                    if (protector.WasInterupted(prevProtectionCounter))
                    {
                        _trkv.SetKeyPrefix(prefix);
                        if (!_trkv.SetKeyIndex(pos))
                        {
                            break;
                        }
                    }
                    else
                    {
                        if (!_trkv.FindNextKey())
                        {
                            break;
                        }
                    }
                }
                _fastVisitor.MarkCurrentKeyAsUsed(_trkv);
                prevProtectionCounter = protector.ProtectionCounter;
                if (_visitor == null || _visitor.StartRelationKey())
                {
                    var keyReader    = new KeyValueDBKeyReader(_trkv);
                    var relationInfo = relationVersions[lastPersistedVersion];
                    IterateFields(keyReader, relationInfo.GetPrimaryKeyFields(), null);
                    _visitor?.EndRelationKey();
                }
                if (protector.WasInterupted(prevProtectionCounter))
                {
                    _trkv.SetKeyPrefix(prefix);
                    if (!_trkv.SetKeyIndex(pos))
                    {
                        break;
                    }
                }
                if (_visitor == null || _visitor.StartRelationValue())
                {
                    var valueReader  = new KeyValueDBValueReader(_trkv);
                    var version      = valueReader.ReadVUInt32();
                    var relationInfo = relationVersions[version];
                    IterateFields(valueReader, relationInfo.GetValueFields(), new HashSet <int>());
                    _visitor?.EndRelationValue();
                }
                pos++;
            }
        }