Esempio n. 1
0
        public static CollectionOfBloomFilters Load(Mode mode, TransactionOperationContext indexContext)
        {
            var tree       = indexContext.Transaction.InnerTransaction.CreateTree("BloomFilters");
            var count      = GetCount(tree, ref mode);
            var collection = new CollectionOfBloomFilters(mode, tree, indexContext);

            for (var i = 0; i < count; i++)
            {
                BloomFilter filter = null;
                switch (mode)
                {
                case Mode.X64:
                    filter = new BloomFilter64(i, tree, writeable: false, allocator: indexContext.Allocator);
                    break;

                case Mode.X86:
                    filter = new BloomFilter32(i, tree, writeable: false, allocator: indexContext.Allocator);
                    break;
                }

                collection.AddFilter(filter);
            }

            collection.Initialize();

            return(collection);
        }
        public static CollectionOfBloomFilters Load(Mode mode, TransactionOperationContext indexContext)
        {
            var isNew = false;
            var tree  = indexContext.Transaction.InnerTransaction.ReadTree(BloomFiltersTreeName);

            if (tree == null)
            {
                isNew = true;
                tree  = indexContext.Transaction.InnerTransaction.CreateTree(BloomFiltersTreeName);
            }

            var version = GetVersion(tree, isNew);
            var count   = GetCount(tree, ref mode);

            if (count == _consumed)
            {
                Debug.Assert(mode == Mode.X86, "BloomFilters in x64 mode got consumed, should not happen and likely a bug!");

                var consumedCollection = new CollectionOfBloomFilters(mode, version, tree: null, context: null)
                {
                    Consumed = true
                };

                return(consumedCollection);
            }

            var collection = new CollectionOfBloomFilters(mode, version, tree, indexContext);

            for (var i = 0; i < count; i++)
            {
                BloomFilter filter = null;
                switch (mode)
                {
                case Mode.X64:
                    filter = new BloomFilter64(i, version, tree, writable: false, allocator: indexContext.Allocator);
                    break;

                case Mode.X86:
                    filter = new BloomFilter32(i, version, tree, writable: false, allocator: indexContext.Allocator);
                    break;
                }

                collection.AddFilter(filter);
            }

            collection.Initialize();

            return(collection);
        }
        public static unsafe CollectionOfBloomFilters Load(int singleBloomFilterCapacity, TransactionOperationContext indexContext)
        {
            var tree       = indexContext.Transaction.InnerTransaction.CreateTree("IndexedDocs");
            var collection = new CollectionOfBloomFilters(singleBloomFilterCapacity, tree, indexContext);

            using (var it = tree.Iterate(prefetch: false))
            {
                if (it.Seek(Slices.BeforeAllKeys))
                {
                    do
                    {
                        var reader = it.CreateReaderForCurrent();

                        Debug.Assert(reader.Length == BloomFilter.PtrSize);

                        collection.AddFilter(new BloomFilter(it.CurrentKey.Clone(indexContext.Allocator, ByteStringType.Immutable), reader.Base, tree, writeable: false));
                    } while (it.MoveNext());
                }
            }

            collection.Initialize();

            return(collection);
        }