Beispiel #1
0
        public void IterateRelationRow(ODBIteratorRelationInfo relation, long pos)
        {
            var prefix = BuildRelationPrefix(relation.Id);

            if (!_trkv.SetKeyIndex(prefix, pos))
            {
                return;
            }
            var prevProtectionCounter = _trkv.CursorMovedCounter;

            if (_visitor == null || _visitor.StartRelationKey())
            {
                var keyReader    = new SpanReader(_trkv.GetKey().Slice(prefix.Length));
                var relationInfo = relation.VersionInfos[relation.LastPersistedVersion];
                IterateFields(ref keyReader, relationInfo.PrimaryKeyFields.Span, null);
                _visitor?.EndRelationKey();
            }
            if (_trkv.CursorMovedCounter != prevProtectionCounter)
            {
                if (!_trkv.SetKeyIndex(prefix, pos))
                {
                    return;
                }
            }
            if (_visitor == null || _visitor.StartRelationValue())
            {
                var valueReader  = new SpanReader(_trkv.GetValue());
                var version      = valueReader.ReadVUInt32();
                var relationInfo = relation.VersionInfos[version];
                IterateFields(ref valueReader, relationInfo.Fields.Span, new HashSet <int>());
                _visitor?.EndRelationValue();
            }
        }
Beispiel #2
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++;
            }
        }