Exemplo n.º 1
0
        protected override unsafe long CalculateIndexEtag(QueryOperationContext queryContext, TransactionOperationContext indexContext,
                                                          QueryMetadata query, bool isStale)
        {
            if (_handleReferences == null && _handleCompareExchangeReferences == null)
            {
                return(base.CalculateIndexEtag(queryContext, indexContext, query, isStale));
            }

            var minLength = MinimumSizeForCalculateIndexEtagLength(query);
            var length    = minLength;

            if (_handleReferences != null)
            {
                length += sizeof(long) * 4 * (Collections.Count * _referencedCollections.Count); // last referenced collection etags (document + tombstone) and last processed reference collection etags (document + tombstone)
            }
            if (_handleCompareExchangeReferences != null)
            {
                length += sizeof(long) * 4 * _compiled.CollectionsWithCompareExchangeReferences.Count; // last referenced collection etags (document + tombstone) and last processed reference collection etags (document + tombstone)
            }
            var indexEtagBytes = stackalloc byte[length];

            CalculateIndexEtagInternal(indexEtagBytes, isStale, State, queryContext, indexContext);
            UseAllDocumentsCounterCmpXchgAndTimeSeriesEtags(queryContext, query, length, indexEtagBytes);

            var writePos = indexEtagBytes + minLength;

            return(StaticIndexHelper.CalculateIndexEtag(this, length, indexEtagBytes, writePos, queryContext, indexContext));
        }
Exemplo n.º 2
0
        protected override bool ShouldReplace()
        {
            if (_isSideBySide.HasValue == false)
            {
                _isSideBySide = Name.StartsWith(Constants.Documents.Indexing.SideBySideIndexNamePrefix, StringComparison.OrdinalIgnoreCase);
            }

            if (_isSideBySide == false)
            {
                return(false);
            }

            using (DocumentDatabase.DocumentsStorage.ContextPool.AllocateOperationContext(out DocumentsOperationContext databaseContext))
                using (_contextPool.AllocateOperationContext(out TransactionOperationContext indexContext))
                {
                    using (indexContext.OpenReadTransaction())
                        using (databaseContext.OpenReadTransaction())
                        {
                            var canReplace = StaticIndexHelper.CanReplace(this, IsStale(databaseContext, indexContext), DocumentDatabase, databaseContext, indexContext);
                            if (canReplace)
                            {
                                _isSideBySide = null;
                            }

                            return(canReplace);
                        }
                }
        }
Exemplo n.º 3
0
 public override Dictionary <string, long> GetLastProcessedTombstonesPerCollection()
 {
     using (CurrentlyInUse())
     {
         return(StaticIndexHelper.GetLastProcessedTombstonesPerCollection(
                    this, _referencedCollections, Collections, _compiled.ReferencedCollections, _indexStorage));
     }
 }
Exemplo n.º 4
0
        protected override bool IsStale(DocumentsOperationContext databaseContext, TransactionOperationContext indexContext, long?cutoff = null, long?referenceCutoff = null, List <string> stalenessReasons = null)
        {
            var isStale = base.IsStale(databaseContext, indexContext, cutoff, referenceCutoff, stalenessReasons);

            if (isStale && stalenessReasons == null || _referencedCollections.Count == 0)
            {
                return(isStale);
            }

            return(StaticIndexHelper.IsStaleDueToReferences(this, databaseContext, indexContext, referenceCutoff, stalenessReasons) || isStale);
        }
Exemplo n.º 5
0
        protected override bool IsStale(DocumentsOperationContext databaseContext, TransactionOperationContext indexContext, long?cutoff = null)
        {
            var isStale = base.IsStale(databaseContext, indexContext, cutoff);

            if (isStale || _referencedCollections.Count == 0)
            {
                return(isStale);
            }

            return(StaticIndexHelper.IsStale(this, databaseContext, indexContext, cutoff));
        }
Exemplo n.º 6
0
        internal override bool IsStale(QueryOperationContext queryContext, TransactionOperationContext indexContext, long?cutoff = null, long?referenceCutoff = null, long?compareExchangeReferenceCutoff = null, List <string> stalenessReasons = null)
        {
            var isStale = base.IsStale(queryContext, indexContext, cutoff, referenceCutoff, compareExchangeReferenceCutoff, stalenessReasons);

            if (isStale && (stalenessReasons == null || (_handleReferences == null && _handleCompareExchangeReferences == null)))
            {
                return(isStale);
            }

            return(StaticIndexHelper.IsStaleDueToReferences(this, queryContext, indexContext, referenceCutoff, compareExchangeReferenceCutoff, stalenessReasons) || isStale);
        }
Exemplo n.º 7
0
        public override Dictionary <string, long> GetLastProcessedTombstonesPerCollection(ITombstoneAware.TombstoneType tombstoneType)
        {
            if (tombstoneType != ITombstoneAware.TombstoneType.Documents)
            {
                return(null);
            }

            using (CurrentlyInUse())
            {
                return(StaticIndexHelper.GetLastProcessedDocumentTombstonesPerCollection(
                           this, _referencedCollections, Collections, _compiled.ReferencedCollections, _indexStorage));
            }
        }
Exemplo n.º 8
0
        protected override bool IsStale(DocumentsOperationContext databaseContext, TransactionOperationContext indexContext, long? cutoff = null, long? referenceCutoff = null, List<string> stalenessReasons = null)
        {
            var isStale = base.IsStale(databaseContext, indexContext, cutoff, referenceCutoff, stalenessReasons);

            if (isStale == false && OutputReduceToCollection?.HasDocumentsToDelete(indexContext) == true)
            {
                if (indexContext.IgnoreStalenessDueToReduceOutputsToDelete == false)
                {
                    isStale = true;
                    stalenessReasons?.Add($"There are still some reduce output documents to delete from collection '{Definition.OutputReduceToCollection}'. ");
                }
            }

            if (isStale && stalenessReasons == null || _referencedCollections.Count == 0)
                return isStale;

            return StaticIndexHelper.IsStaleDueToReferences(this, databaseContext, indexContext, referenceCutoff, stalenessReasons) || isStale;
        }
Exemplo n.º 9
0
        protected override unsafe long CalculateIndexEtag(bool isStale, DocumentsOperationContext documentsContext, TransactionOperationContext indexContext)
        {
            if (_referencedCollections.Count == 0)
            {
                return(base.CalculateIndexEtag(isStale, documentsContext, indexContext));
            }

            var minLength = MinimumSizeForCalculateIndexEtagLength();
            var length    = minLength +
                            sizeof(long) * 2 * (Collections.Count * _referencedCollections.Count); // last referenced collection etags and last processed reference collection etags

            var indexEtagBytes = stackalloc byte[length];

            CalculateIndexEtagInternal(indexEtagBytes, isStale, State, documentsContext, indexContext);

            var writePos = indexEtagBytes + minLength;

            return(StaticIndexHelper.CalculateIndexEtag(this, length, indexEtagBytes, writePos, documentsContext, indexContext));
        }
Exemplo n.º 10
0
        internal override bool IsStale(QueryOperationContext queryContext, TransactionOperationContext indexContext, long?cutoff = null, long?referenceCutoff = null, long?compareExchangeReferenceCutoff = null, List <string> stalenessReasons = null)
        {
            var isStale = base.IsStale(queryContext, indexContext, cutoff, referenceCutoff, compareExchangeReferenceCutoff, stalenessReasons);

            if (isStale == false && OutputReduceToCollection?.HasDocumentsToDelete(indexContext) == true)
            {
                if (indexContext.IgnoreStalenessDueToReduceOutputsToDelete == false)
                {
                    isStale = true;
                    stalenessReasons?.Add($"There are still some reduce output documents to delete from collection '{Definition.OutputReduceToCollection}'. ");
                }
            }

            if (isStale && (stalenessReasons == null || (_handleReferences == null && _handleCompareExchangeReferences == null)))
            {
                return(isStale);
            }

            return(StaticIndexHelper.IsStaleDueToReferences(this, queryContext, indexContext, referenceCutoff, compareExchangeReferenceCutoff, stalenessReasons) || isStale);
        }
Exemplo n.º 11
0
        protected override unsafe long CalculateIndexEtag(DocumentsOperationContext documentsContext, TransactionOperationContext indexContext,
            QueryMetadata query, bool isStale)
        {
            if (_referencedCollections.Count == 0)
                return base.CalculateIndexEtag(documentsContext, indexContext, query, isStale);

            var minLength = MinimumSizeForCalculateIndexEtagLength(query);
            var length = minLength +
                         sizeof(long) * 4 * (Collections.Count * _referencedCollections.Count); // last referenced collection etags (document + tombstone) and last processed reference collection etags (document + tombstone)

            var indexEtagBytes = stackalloc byte[length];

            CalculateIndexEtagInternal(indexEtagBytes, isStale, State, documentsContext, indexContext);

            UseAllDocumentsCounterAndCmpXchgEtags(documentsContext, query, length, indexEtagBytes);

            var writePos = indexEtagBytes + minLength;

            return StaticIndexHelper.CalculateIndexEtag(this, length, indexEtagBytes, writePos, documentsContext, indexContext);
        }
Exemplo n.º 12
0
        public override void HandleDelete(Tombstone tombstone, string collection, IndexWriteOperation writer, TransactionOperationContext indexContext, IndexingStatsScope stats)
        {
            StaticIndexHelper.HandleReferencesDelete(_handleReferences, _handleCompareExchangeReferences, tombstone, collection, writer, indexContext, stats);

            base.HandleDelete(tombstone, collection, writer, indexContext, stats);
        }
Exemplo n.º 13
0
 protected override bool ShouldReplace()
 {
     return(StaticIndexHelper.ShouldReplace(this, ref _isSideBySide));
 }
Exemplo n.º 14
0
        protected override IndexingState GetIndexingStateInternal(QueryOperationContext queryContext, TransactionOperationContext indexContext)
        {
            var result = base.GetIndexingStateInternal(queryContext, indexContext);

            if (_handleCompareExchangeReferences == null)
            {
                return(result);
            }

            (result.LastProcessedCompareExchangeReferenceEtag, result.LastProcessedCompareExchangeReferenceTombstoneEtag) = StaticIndexHelper.GetLastProcessedCompareExchangeReferenceEtags(this, _compiled, indexContext);

            return(result);
        }
Exemplo n.º 15
0
 public override void HandleDelete(Tombstone tombstone, string collection, Lazy <IndexWriteOperation> writer, TransactionOperationContext indexContext, IndexingStatsScope stats)
 {
     StaticIndexHelper.HandleDeleteBySourceDocumentId(this, _handleReferences, _handleCompareExchangeReferences, tombstone, collection, writer, indexContext, stats);
 }