예제 #1
0
        public override long GetLastItemEtagInCollection(QueryOperationContext queryContext, string collection)
        {
            if (collection == Constants.Documents.Collections.AllDocumentsCollection)
            {
                return(DocumentsStorage.ReadLastCountersEtag(queryContext.Documents.Transaction.InnerTransaction));
            }

            return(DocumentDatabase.DocumentsStorage.CountersStorage.GetLastCounterEtag(queryContext.Documents, collection));
        }
예제 #2
0
        private unsafe void FillCountOfResultsAndIndexEtag(QueryResultServerSide<Document> resultToFill, QueryMetadata query, DocumentsOperationContext context)
        {
            var bufferSize = query.HasCounters ? 4 : 3;
            var collection = query.CollectionName;
            var buffer = stackalloc long[bufferSize];

            // If the query has include or load, it's too difficult to check the etags for just the included collections, 
            // it's easier to just show etag for all docs instead.
            if (collection == Constants.Documents.Collections.AllDocumentsCollection ||
                query.HasIncludeOrLoad)
            {
                var numberOfDocuments = Database.DocumentsStorage.GetNumberOfDocuments(context);
                buffer[0] = DocumentsStorage.ReadLastDocumentEtag(context.Transaction.InnerTransaction);
                buffer[1] = DocumentsStorage.ReadLastTombstoneEtag(context.Transaction.InnerTransaction);
                buffer[2] = numberOfDocuments;

                if (query.HasCounters)
                    buffer[3] = DocumentsStorage.ReadLastCountersEtag(context.Transaction.InnerTransaction);

                resultToFill.TotalResults = (int)numberOfDocuments;
            }
            else
            {
                var collectionStats = Database.DocumentsStorage.GetCollection(collection, context);
                buffer[0] = Database.DocumentsStorage.GetLastDocumentEtag(context, collection);
                buffer[1] = Database.DocumentsStorage.GetLastTombstoneEtag(context, collection);
                buffer[2] = collectionStats.Count;

                if (query.HasCounters)
                    buffer[3] = Database.DocumentsStorage.CountersStorage.GetLastCounterEtag(context, collection);

                resultToFill.TotalResults = (int)collectionStats.Count;
            }

            resultToFill.ResultEtag = (long)Hashing.XXHash64.Calculate((byte*)buffer, sizeof(long) * (uint)bufferSize);
            resultToFill.NodeTag = Database.ServerStore.NodeTag;
        }
예제 #3
0
        private unsafe void FillCountOfResultsAndIndexEtag(QueryResultServerSide <Document> resultToFill, QueryMetadata query, QueryOperationContext context)
        {
            var bufferSize    = 3;
            var hasCounters   = query.HasCounterSelect || query.CounterIncludes != null;
            var hasTimeSeries = query.HasTimeSeriesSelect || query.TimeSeriesIncludes != null;
            var hasCmpXchg    = query.HasCmpXchg || query.HasCmpXchgSelect || query.HasCmpXchgIncludes;

            if (hasCounters)
            {
                bufferSize++;
            }
            if (hasTimeSeries)
            {
                bufferSize++;
            }
            if (hasCmpXchg)
            {
                bufferSize++;
            }

            var collection = query.CollectionName;
            var buffer     = stackalloc long[bufferSize];

            // If the query has include or load, it's too difficult to check the etags for just the included collections,
            // it's easier to just show etag for all docs instead.
            if (collection == Constants.Documents.Collections.AllDocumentsCollection ||
                query.HasIncludeOrLoad)
            {
                var numberOfDocuments = Database.DocumentsStorage.GetNumberOfDocuments(context.Documents);
                buffer[0] = DocumentsStorage.ReadLastDocumentEtag(context.Documents.Transaction.InnerTransaction);
                buffer[1] = DocumentsStorage.ReadLastTombstoneEtag(context.Documents.Transaction.InnerTransaction);
                buffer[2] = numberOfDocuments;

                if (hasCounters)
                {
                    buffer[3] = DocumentsStorage.ReadLastCountersEtag(context.Documents.Transaction.InnerTransaction);
                }

                if (hasTimeSeries)
                {
                    buffer[hasCounters ? 4 : 3] = DocumentsStorage.ReadLastTimeSeriesEtag(context.Documents.Transaction.InnerTransaction);
                }

                resultToFill.TotalResults     = (int)numberOfDocuments;
                resultToFill.LongTotalResults = numberOfDocuments;
            }
            else
            {
                var collectionStats = Database.DocumentsStorage.GetCollection(collection, context.Documents);
                buffer[0] = Database.DocumentsStorage.GetLastDocumentEtag(context.Documents.Transaction.InnerTransaction, collection);
                buffer[1] = Database.DocumentsStorage.GetLastTombstoneEtag(context.Documents.Transaction.InnerTransaction, collection);
                buffer[2] = collectionStats.Count;

                if (hasCounters)
                {
                    buffer[3] = Database.DocumentsStorage.CountersStorage.GetLastCounterEtag(context.Documents, collection);
                }

                if (hasTimeSeries)
                {
                    buffer[hasCounters ? 4 : 3] = Database.DocumentsStorage.TimeSeriesStorage.GetLastTimeSeriesEtag(context.Documents, collection);
                }

                resultToFill.TotalResults     = (int)collectionStats.Count;
                resultToFill.LongTotalResults = collectionStats.Count;
            }

            if (hasCmpXchg)
            {
                buffer[bufferSize - 1] = Database.ServerStore.Cluster.GetLastCompareExchangeIndexForDatabase(context.Server, Database.Name);
            }

            resultToFill.ResultEtag = (long)Hashing.XXHash64.Calculate((byte *)buffer, sizeof(long) * (uint)bufferSize);
            resultToFill.NodeTag    = Database.ServerStore.NodeTag;
        }