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()); } }
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); } } }
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()); } }
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()); } }
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()); } }
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()); } }