Example #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();
            }
        }
Example #2
0
        public void IterateRelation(ODBIteratorRelationInfo relation)
        {
            var prefix = BuildRelationPrefix(relation.Id);

            long prevProtectionCounter = 0;
            long pos = 0;

            while (true)
            {
                if (pos == 0)
                {
                    if (!_trkv.FindFirstKey(prefix))
                    {
                        break;
                    }
                }
                else
                {
                    if (_trkv.CursorMovedCounter != prevProtectionCounter)
                    {
                        if (!_trkv.SetKeyIndex(prefix, pos))
                        {
                            break;
                        }
                    }
                    else
                    {
                        if (!_trkv.FindNextKey(prefix))
                        {
                            break;
                        }
                    }
                }
                _fastVisitor.MarkCurrentKeyAsUsed(_trkv);
                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))
                    {
                        break;
                    }
                }
                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();
                }
                pos++;
            }
        }
Example #3
0
        void IterateSecondaryIndexes(ODBIteratorRelationInfo relation)
        {
            var version = relation.VersionInfos[relation.LastPersistedVersion];

            foreach (var(secKeyName, secKeyIdx) in version.SecondaryKeysNames)
            {
                var secondaryKeyFields = version.GetSecondaryKeyFields(secKeyIdx);
                if (_visitor == null || _visitor.StartSecondaryIndex(secKeyName))
                {
                    var  prefix = BuildRelationSecondaryKeyPrefix(relation.Id, secKeyIdx);
                    long prevProtectionCounter = 0;
                    long pos = 0;
                    while (true)
                    {
                        if (pos == 0)
                        {
                            if (!_trkv.FindFirstKey(prefix))
                            {
                                break;
                            }
                        }
                        else
                        {
                            if (_trkv.CursorMovedCounter != prevProtectionCounter)
                            {
                                if (!_trkv.SetKeyIndex(prefix, pos))
                                {
                                    break;
                                }
                            }
                            else
                            {
                                if (!_trkv.FindNextKey(prefix))
                                {
                                    break;
                                }
                            }
                        }

                        var reader = new SpanReader(_trkv.GetKey().Slice(prefix.Length));
                        foreach (var fi in secondaryKeyFields)
                        {
                            if (_visitor == null || !_visitor.StartField(fi.Name))
                            {
                                continue;
                            }
                            IterateHandler(ref reader, fi.Handler !, false, null);
                        }
                        _visitor?.NextSecondaryKey();
                        pos++;
                    }
                    _visitor?.EndSecondaryIndex();
                }
            }
        }