Exemple #1
0
        public static void DoFreeContent(IReaderCtx ctx, ulong id, int cfgId)
        {
            var readerCtx = (DBReaderCtx)ctx;
            var tr        = readerCtx.GetTransaction();
            var dict      = new ODBDictionary <TKey, TValue>(tr, ODBDictionaryConfiguration.Get(cfgId), id);

            dict.FreeContent(ctx, cfgId);
        }
Exemple #2
0
        void CreateConfiguration()
        {
            HandledType();
            var keyAndValueTypes = _type !.GetGenericArguments();

            _configurationId = ODBDictionaryConfiguration.Register(_keysHandler, keyAndValueTypes[0], null, null);
            var cfg = ODBDictionaryConfiguration.Get(_configurationId);

            lock (cfg)
            {
                cfg.KeyReader ??= CreateReader(_keysHandler, keyAndValueTypes[0]);
                cfg.KeyWriter ??= CreateWriter(_keysHandler, keyAndValueTypes[0]);
            }
        }
        int GetConfigurationId(Type type)
        {
            var keyAndValueTypes = type.GetGenericArguments();
            var configurationId  = ODBDictionaryConfiguration.Register(_keysHandler, keyAndValueTypes[0], _valuesHandler, keyAndValueTypes[1]);
            var cfg = ODBDictionaryConfiguration.Get(configurationId);

            lock (cfg)
            {
                cfg.KeyReader ??= CreateReader(_keysHandler, keyAndValueTypes[0]);
                cfg.KeyWriter ??= CreateWriter(_keysHandler, keyAndValueTypes[0]);
                cfg.ValueReader ??= CreateReader(_valuesHandler, keyAndValueTypes[1]);
                cfg.ValueWriter ??= CreateWriter(_valuesHandler, keyAndValueTypes[1]);
            }

            return(configurationId);
        }
        public void Init(IILGen ilGenerator, Action <IILGen> pushReaderCtx)
        {
            var genericArguments = _type !.GetGenericArguments();
            var instanceType     = typeof(ODBDictionary <,>).MakeGenericType(genericArguments);
            var constructorInfo  = instanceType.GetConstructor(
                new[] { typeof(IInternalObjectDBTransaction), typeof(ODBDictionaryConfiguration) });

            ilGenerator
            .Do(pushReaderCtx)
            .Castclass(typeof(IDBReaderCtx))
            .Callvirt(() => default(IDBReaderCtx).GetTransaction())
            .LdcI4(_configurationId)
            .Call(() => ODBDictionaryConfiguration.Get(0))
            .Newobj(constructorInfo !)
            .Castclass(_type);
        }
        public void Load(IILGen ilGenerator, Action <IILGen> pushReaderOrCtx)
        {
            var genericArguments = _type !.GetGenericArguments();
            var instanceType     = typeof(ODBSet <>).MakeGenericType(genericArguments);
            var constructorInfo  = instanceType.GetConstructor(
                new[] { typeof(IInternalObjectDBTransaction), typeof(ODBDictionaryConfiguration), typeof(ulong) });

            ilGenerator
            .Do(pushReaderOrCtx)
            .Castclass(typeof(IDBReaderCtx))
            .Callvirt(() => default(IDBReaderCtx).GetTransaction())
            .LdcI4(_configurationId)
            .Call(() => ODBDictionaryConfiguration.Get(0))
            .Do(Extensions.PushReaderFromCtx(pushReaderOrCtx))
            .Callvirt(() => default(AbstractBufferedReader).ReadVUInt64())
            .Newobj(constructorInfo !)
            .Castclass(_type);
        }
Exemple #6
0
        public static void DoSave(ref SpanWriter writer, IWriterCtx ctx, IOrderedSet <TKey>?dictionary, int cfgId)
        {
            var writerCtx = (IDBWriterCtx)ctx;

            if (!(dictionary is ODBSet <TKey> goodDict))
            {
                var tr = writerCtx.GetTransaction();
                var id = tr.AllocateDictionaryId();
                goodDict = new ODBSet <TKey>(tr, ODBDictionaryConfiguration.Get(cfgId), id);
                if (dictionary != null)
                {
                    foreach (var pair in dictionary)
                    {
                        goodDict.Add(pair);
                    }
                }
            }

            writer.WriteVUInt64(goodDict._id);
        }
        public static void DoSave(IWriterCtx ctx, IDictionary <TKey, TValue>?dictionary, int cfgId)
        {
            var writerCtx = (IDBWriterCtx)ctx;

            if (!(dictionary is ODBDictionary <TKey, TValue> goodDict))
            {
                var tr = writerCtx.GetTransaction();
                var id = tr.AllocateDictionaryId();
                goodDict = new ODBDictionary <TKey, TValue>(tr, ODBDictionaryConfiguration.Get(cfgId), id);
                if (dictionary != null)
                {
                    foreach (var pair in dictionary)
                    {
                        goodDict.Add(pair.Key, pair.Value);
                    }
                }
            }

            ctx.Writer().WriteVUInt64(goodDict._id);
        }
Exemple #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++;
            }
        }
        void FreeContent(IReaderCtx readerCtx, int cfgId)
        {
            var config = ODBDictionaryConfiguration.Get(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)
                // ReSharper disable once ObjectCreationAsStatement
                .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++;
            }
        }