예제 #1
0
        public static IDisposable GetIdentifiersOfMappedDocuments(this Index self, string startsWith, int start, int take, out IEnumerable <string> docIds)
        {
            if (self.Type.IsMapReduce() == false)
            {
                throw new NotSupportedException("Getting doc ids for map indexes is not supported");
            }

            using (var scope = new DisposableScope())
            {
                scope.EnsureDispose(self._contextPool.AllocateOperationContext(out TransactionOperationContext indexContext));

                RavenTransaction tx;
                scope.EnsureDispose(tx = indexContext.OpenReadTransaction());

                var tree = tx.InnerTransaction.ReadTree(MapReduceIndexBase <MapReduceIndexDefinition, IndexField> .MapPhaseTreeName);

                if (tree == null)
                {
                    docIds = Enumerable.Empty <string>();
                    return(scope);
                }

                TreeIterator it;
                scope.EnsureDispose(it = tree.Iterate(false));

                docIds = IterateKeys(it, startsWith, start, take, indexContext);

                return(scope.Delay());
            }
        }
예제 #2
0
        private static IEnumerable <ReduceTree> IterateTrees(Index self, List <FixedSizeTree> mapEntries,
                                                             Tree reducePhaseTree, FixedSizeTree typePerHash, TransactionOperationContext indexContext, DisposableScope scope)
        {
            var reduceKeys    = new HashSet <ulong>();
            var idToDocIdHash = new Dictionary <long, string>();

            foreach (var tree in mapEntries)
            {
                foreach (var mapEntry in MapReduceIndexBase <MapReduceIndexDefinition, IndexField> .GetMapEntries(tree))
                {
                    reduceKeys.Add(mapEntry.ReduceKeyHash);
                    idToDocIdHash[mapEntry.Id] = tree.Name.ToString();
                }
            }

            foreach (var reduceKeyHash in reduceKeys)
            {
                MapReduceResultsStore store;

                var mapReduceIndex = self as MapReduceIndex;

                if (mapReduceIndex != null)
                {
                    store = mapReduceIndex.CreateResultsStore(typePerHash,
                                                              reduceKeyHash, indexContext, false);
                }
                else
                {
                    store = ((AutoMapReduceIndex)self).CreateResultsStore(typePerHash,
                                                                          reduceKeyHash, indexContext, false);
                }

                using (store)
                {
                    ReduceTree tree;
                    switch (store.Type)
                    {
                    case MapResultsStorageType.Tree:
                        tree = RenderTree(store.Tree, reduceKeyHash, idToDocIdHash, self, indexContext);
                        break;

                    case MapResultsStorageType.Nested:
                        tree = RenderNestedSection(store.GetNestedResultsSection(reducePhaseTree), reduceKeyHash, idToDocIdHash, self,
                                                   indexContext);
                        break;

                    default:
                        throw new ArgumentOutOfRangeException(store.Type.ToString());
                    }

                    scope.EnsureDispose(tree);
                    yield return(tree);
                }
            }
        }
예제 #3
0
        public static IDisposable GetReduceTree(this Index self, string[] docIds, out IEnumerable <ReduceTree> trees)
        {
            using (var scope = new DisposableScope())
            {
                scope.EnsureDispose(self._contextPool.AllocateOperationContext(out TransactionOperationContext indexContext));

                RavenTransaction tx;
                scope.EnsureDispose(tx = indexContext.OpenReadTransaction());

                var mapPhaseTree = tx.InnerTransaction.ReadTree(MapReduceIndexBase <MapReduceIndexDefinition, IndexField> .MapPhaseTreeName);

                if (mapPhaseTree == null)
                {
                    trees = Enumerable.Empty <ReduceTree>();
                    return(scope);
                }

                var reducePhaseTree = tx.InnerTransaction.ReadTree(MapReduceIndexBase <MapReduceIndexDefinition, IndexField> .ReducePhaseTreeName);

                if (reducePhaseTree == null)
                {
                    trees = Enumerable.Empty <ReduceTree>();
                    return(scope);
                }

                var mapEntries = new List <FixedSizeTree>(docIds.Length);
                foreach (var docId in docIds)
                {
                    FixedSizeTree mapEntriesTree;
                    scope.EnsureDispose(mapEntriesTree = mapPhaseTree.FixedTreeFor(docId.ToLower(), sizeof(long)));
                    mapEntries.Add(mapEntriesTree);
                }

                FixedSizeTree typePerHash;
                scope.EnsureDispose(typePerHash = reducePhaseTree.FixedTreeFor(MapReduceIndexBase <MapReduceIndexDefinition, IndexField> .ResultsStoreTypesTreeName, sizeof(byte)));

                trees = IterateTrees(self, mapEntries, reducePhaseTree, typePerHash, indexContext, scope);

                return(scope.Delay());
            }
        }
예제 #4
0
        public IDisposable ReadPostponedActions(out IEnumerable <NotificationTableValue> actions, DateTime cutoff)
        {
            using (var scope = new DisposableScope())
            {
                scope.EnsureDispose(_contextPool.AllocateOperationContext(out TransactionOperationContext context));
                scope.EnsureDispose(context.OpenReadTransaction());

                actions = ReadPostponedActionsByPostponedUntilIndex(context, cutoff);

                return(scope.Delay());
            }
        }
예제 #5
0
        public IDisposable ReadActionsOrderedByCreationDate(out IEnumerable <NotificationTableValue> actions)
        {
            using (var scope = new DisposableScope())
            {
                scope.EnsureDispose(_contextPool.AllocateOperationContext(out TransactionOperationContext context));
                scope.EnsureDispose(context.OpenReadTransaction());

                actions = ReadActionsByCreatedAtIndex(context);

                return(scope.Delay());
            }
        }
예제 #6
0
        public IDisposable Read(string id, out NotificationTableValue value)
        {
            using (var scope = new DisposableScope())
            {
                RavenTransaction tx;

                scope.EnsureDispose(_contextPool.AllocateOperationContext(out TransactionOperationContext context));
                scope.EnsureDispose(tx = context.OpenReadTransaction());

                value = Get(id, context, tx);

                return(scope.Delay());
            }
        }