Exemple #1
0
        private void FillCollectionEtags(Transaction tx,
                                         Dictionary <string, IndexTransactionCache.CollectionEtags> map)
        {
            foreach (string collection in _index.Collections)
            {
                using (Slice.From(tx.LowLevelTransaction.Allocator, collection, out Slice collectionSlice))
                {
                    var etags = new IndexTransactionCache.CollectionEtags
                    {
                        LastIndexedEtag = IndexStorage.ReadLastEtag(tx,
                                                                    IndexStorage.IndexSchema.EtagsTree,
                                                                    collectionSlice
                                                                    ),
                        LastProcessedTombstoneEtag = IndexStorage.ReadLastEtag(tx,
                                                                               IndexStorage.IndexSchema.EtagsTombstoneTree,
                                                                               collectionSlice
                                                                               )
                    };

                    map[collection] = etags;
                }
            }

            var referencedCollections = _index.GetReferencedCollections();

            if (referencedCollections == null || referencedCollections.Count == 0)
            {
                return;
            }

            foreach (var(src, collections)  in referencedCollections)
            {
                var collectionEtags = map[src];
                collectionEtags.LastReferencedEtags ??= new Dictionary <string, IndexTransactionCache.ReferenceCollectionEtags>(StringComparer.OrdinalIgnoreCase);
                foreach (var collectionName in collections)
                {
                    collectionEtags.LastReferencedEtags[collectionName.Name] = new IndexTransactionCache.ReferenceCollectionEtags
                    {
                        LastEtag = IndexStorage.ReadLastProcessedReferenceEtag(tx, src, collectionName),
                        LastProcessedTombstoneEtag = IndexStorage.ReadLastProcessedReferenceTombstoneEtag(tx, src, collectionName),
                    };
                }
            }
        }
        private void FillCollectionEtags(Transaction tx,
                                         Dictionary <string, IndexTransactionCache.CollectionEtags> map)
        {
            AbstractStaticIndexBase compiled = null;

            if (_index.Type.IsStatic())
            {
                switch (_index)
                {
                case MapIndex mapIndex:
                    compiled = mapIndex._compiled;
                    break;

                case MapReduceIndex mapReduceIndex:
                    compiled = mapReduceIndex._compiled;
                    break;

                case MapCountersIndex mapCountersIndex:
                    compiled = mapCountersIndex._compiled;
                    break;

                case MapTimeSeriesIndex mapTimeSeriesIndex:
                    compiled = mapTimeSeriesIndex._compiled;
                    break;
                }
            }

            foreach (string collection in _index.Collections)
            {
                using (Slice.From(tx.LowLevelTransaction.Allocator, collection, out Slice collectionSlice))
                {
                    var etags = new IndexTransactionCache.CollectionEtags
                    {
                        LastIndexedEtag = IndexStorage.ReadLastEtag(tx,
                                                                    IndexStorage.IndexSchema.EtagsTree,
                                                                    collectionSlice
                                                                    ),
                        LastProcessedTombstoneEtag = IndexStorage.ReadLastEtag(tx,
                                                                               IndexStorage.IndexSchema.EtagsTombstoneTree,
                                                                               collectionSlice
                                                                               )
                    };

                    if (compiled?.CollectionsWithCompareExchangeReferences.Contains(collection) == true)
                    {
                        etags.LastReferencedEtagsForCompareExchange = new IndexTransactionCache.ReferenceCollectionEtags
                        {
                            LastEtag = _index._indexStorage.ReferencesForCompareExchange.ReadLastProcessedReferenceEtag(tx, collection, IndexStorage.CompareExchangeReferences.CompareExchange),
                            LastProcessedTombstoneEtag = _index._indexStorage.ReferencesForCompareExchange.ReadLastProcessedReferenceTombstoneEtag(tx, collection, IndexStorage.CompareExchangeReferences.CompareExchange)
                        };
                    }

                    map[collection] = etags;
                }
            }

            var referencedCollections = _index.GetReferencedCollections();

            if (referencedCollections == null || referencedCollections.Count == 0)
            {
                return;
            }

            foreach (var(src, collections) in referencedCollections)
            {
                var collectionEtags = map[src];
                collectionEtags.LastReferencedEtags ??= new Dictionary <string, IndexTransactionCache.ReferenceCollectionEtags>(StringComparer.OrdinalIgnoreCase);
                foreach (var collectionName in collections)
                {
                    collectionEtags.LastReferencedEtags[collectionName.Name] = new IndexTransactionCache.ReferenceCollectionEtags
                    {
                        LastEtag = _index._indexStorage.ReferencesForDocuments.ReadLastProcessedReferenceEtag(tx, src, collectionName),
                        LastProcessedTombstoneEtag = _index._indexStorage.ReferencesForDocuments.ReadLastProcessedReferenceTombstoneEtag(tx, src, collectionName),
                    };
                }
            }
        }