Пример #1
0
 void Seek()
 {
     if (_ascending)
     {
         _keyValueTr.SetKeyIndex(_owner._prefix, _startPos + _pos);
     }
     else
     {
         _keyValueTr.SetKeyIndex(_owner._prefix, _startPos - _pos);
     }
     _seekState = SeekState.Ready;
 }
Пример #2
0
 void Seek()
 {
     if (_ascending)
     {
         _keyValueTr.SetKeyIndex(_startPos + _pos);
     }
     else
     {
         _keyValueTr.SetKeyIndex(_startPos - _pos);
     }
     _seekNeeded = false;
 }
Пример #3
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();
            }
        }
Пример #4
0
        public IEnumerator <TKey> GetEnumerator()
        {
            long prevProtectionCounter   = 0;
            var  prevModificationCounter = 0;
            long pos = 0;

            while (true)
            {
                _keyValueTrProtector.Start();
                if (pos == 0)
                {
                    prevModificationCounter = _modificationCounter;
                    _keyValueTr.SetKeyPrefix(_prefix);
                    if (!_keyValueTr.FindFirstKey())
                    {
                        break;
                    }
                }
                else
                {
                    if (_keyValueTrProtector.WasInterupted(prevProtectionCounter))
                    {
                        if (prevModificationCounter != _modificationCounter)
                        {
                            ThrowModifiedDuringEnum();
                        }
                        _keyValueTr.SetKeyPrefix(_prefix);
                        if (!_keyValueTr.SetKeyIndex(pos))
                        {
                            break;
                        }
                    }
                    else
                    {
                        if (!_keyValueTr.FindNextKey())
                        {
                            break;
                        }
                    }
                }

                prevProtectionCounter = _keyValueTrProtector.ProtectionCounter;
                var keyBytes = _keyValueTr.GetKey();
                var key      = ByteArrayToKey(keyBytes);
                yield return(key);

                pos++;
            }
        }
Пример #5
0
        public IEnumerator <TKey> GetEnumerator()
        {
            long prevProtectionCounter   = 0;
            var  prevModificationCounter = 0;
            long pos = 0;

            while (true)
            {
                if (pos == 0)
                {
                    prevModificationCounter = _modificationCounter;
                    if (!_keyValueTr.FindFirstKey(_prefix))
                    {
                        break;
                    }
                }
                else
                {
                    if (_keyValueTr.CursorMovedCounter != prevProtectionCounter)
                    {
                        if (prevModificationCounter != _modificationCounter)
                        {
                            ThrowModifiedDuringEnum();
                        }
                        if (!_keyValueTr.SetKeyIndex(_prefix, pos))
                        {
                            break;
                        }
                    }
                    else
                    {
                        if (!_keyValueTr.FindNextKey(_prefix))
                        {
                            break;
                        }
                    }
                }

                prevProtectionCounter = _keyValueTr.CursorMovedCounter;
                var key = CurrentToKey();
                yield return(key);

                pos++;
            }
        }
Пример #6
0
 bool Seek()
 {
     if (!_keyValueTr.SetKeyIndex(_pos))
     {
         return(false);
     }
     _seekNeeded = false;
     return(true);
 }
Пример #7
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++;
            }
        }
Пример #8
0
        void FreeContent(IReaderCtx readerCtx, int cfgId)
        {
            var config = ODBDictionaryConfiguration.Get(cfgId);
            var ctx    = (DBReaderWithFreeInfoCtx)readerCtx;

            if (config.FreeContent == null)
            {
                var method      = ILBuilder.Instance.NewMethod <FreeContentFun>($"IDictFinder_Cfg_{cfgId}");
                var ilGenerator = method.Generator;

                var readerLoc = ilGenerator.DeclareLocal(typeof(IReaderCtx));
                ilGenerator
                .Ldarg(0)
                .Ldarg(2)
                // ReSharper disable once ObjectCreationAsStatement
                .Newobj(() => new DBReaderWithFreeInfoCtx(null, null))
                .Stloc(readerLoc);

                var readerOrCtx = _valueHandler.NeedsCtx() ? (Action <IILGen>?)(il => il.Ldloc(readerLoc)) : null;
                _valueHandler.FreeContent(ilGenerator, il => il.Ldarg(1), readerOrCtx);
                ilGenerator.Ret();
                config.FreeContent = method.Create();
            }

            var findIDictAction = (FreeContentFun)config.FreeContent;

            long prevProtectionCounter = 0;
            long pos = 0;

            while (true)
            {
                if (pos == 0)
                {
                    if (!_keyValueTr.FindFirstKey(_prefix))
                    {
                        break;
                    }
                }
                else
                {
                    if (_keyValueTr.CursorMovedCounter != prevProtectionCounter)
                    {
                        if (!_keyValueTr.SetKeyIndex(_prefix, pos))
                        {
                            break;
                        }
                    }
                    else
                    {
                        if (!_keyValueTr.FindNextKey(_prefix))
                        {
                            break;
                        }
                    }
                }

                prevProtectionCounter = _keyValueTr.CursorMovedCounter;
                var valueBytes  = _keyValueTr.GetValue();
                var valueReader = new SpanReader(valueBytes);
                findIDictAction(ctx.GetTransaction(), ref valueReader, ctx.DictIds);

                pos++;
            }
        }
 public bool SetKeyIndex(long index)
 {
     return(_keyValueDBTransaction.SetKeyIndex(index));
 }
Пример #10
0
        void FreeContent(IReaderCtx readerCtx, int cfgId)
        {
            var config = (ODBDictionaryConfiguration)((IInstanceRegistry)readerCtx).FindInstance(cfgId);
            var ctx    = (DBReaderWithFreeInfoCtx)readerCtx;

            if (config.FreeContent == null)
            {
                var method = ILBuilder.Instance
                             .NewMethod <Action <IInternalObjectDBTransaction, AbstractBufferedReader, IList <ulong> > >(
                    $"IDictFinder_Cfg_{cfgId}");
                var ilGenerator = method.Generator;

                var readerLoc = ilGenerator.DeclareLocal(typeof(IReaderCtx));
                ilGenerator
                .Ldarg(0)
                .Ldarg(1)
                .Ldarg(2)
                .Newobj(() => new DBReaderWithFreeInfoCtx(null, null, null))
                .Stloc(readerLoc);

                Action <IILGen> readerOrCtx;
                if (_valueHandler.NeedsCtx())
                {
                    readerOrCtx = il => il.Ldloc(readerLoc);
                }
                else
                {
                    readerOrCtx = il => il.Ldarg(1);
                }
                _valueHandler.FreeContent(ilGenerator, readerOrCtx);
                ilGenerator.Ret();
                config.FreeContent = method.Create();
            }

            var findIDictAction = (Action <IInternalObjectDBTransaction, AbstractBufferedReader, IList <ulong> >)config.FreeContent;

            long prevProtectionCounter = 0;
            long pos = 0;

            while (true)
            {
                _keyValueTrProtector.Start();
                if (pos == 0)
                {
                    _keyValueTr.SetKeyPrefix(_prefix);
                    if (!_keyValueTr.FindFirstKey())
                    {
                        break;
                    }
                }
                else
                {
                    if (_keyValueTrProtector.WasInterupted(prevProtectionCounter))
                    {
                        _keyValueTr.SetKeyPrefix(_prefix);
                        if (!_keyValueTr.SetKeyIndex(pos))
                        {
                            break;
                        }
                    }
                    else
                    {
                        if (!_keyValueTr.FindNextKey())
                        {
                            break;
                        }
                    }
                }

                prevProtectionCounter = _keyValueTrProtector.ProtectionCounter;
                var valueBytes  = _keyValueTr.GetValueAsByteArray();
                var valueReader = new ByteArrayReader(valueBytes);
                findIDictAction(ctx.GetTransaction(), valueReader, ctx.DictIds);

                pos++;
            }
        }