Esempio n. 1
0
        private unsafe void FillCountOfResultsAndIndexEtag(QueryResultServerSide <Document> resultToFill, QueryMetadata query, DocumentsOperationContext context)
        {
            var collection = query.CollectionName;
            var buffer     = stackalloc long[3];

            // 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;
                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;
                resultToFill.TotalResults = (int)collectionStats.Count;
            }

            resultToFill.ResultEtag = (long)Hashing.XXHash64.Calculate((byte *)buffer, sizeof(long) * 3);
            resultToFill.NodeTag    = Database.ServerStore.NodeTag;
        }
Esempio n. 2
0
        public Task Stats()
        {
            using (ContextPool.AllocateOperationContext(out DocumentsOperationContext context))
                using (var writer = new BlittableJsonTextWriter(context, ResponseBodyStream()))
                    using (context.OpenReadTransaction())
                    {
                        var indexes = Database.IndexStore.GetIndexes().ToList();

                        var stats = new DatabaseStatistics
                        {
                            LastDocEtag              = DocumentsStorage.ReadLastDocumentEtag(context.Transaction.InnerTransaction),
                            CountOfDocuments         = Database.DocumentsStorage.GetNumberOfDocuments(context),
                            CountOfRevisionDocuments = Database.DocumentsStorage.RevisionsStorage.GetNumberOfRevisionDocuments(context)
                        };

                        var attachments = Database.DocumentsStorage.AttachmentsStorage.GetNumberOfAttachments(context);
                        stats.CountOfAttachments       = attachments.AttachmentCount;
                        stats.CountOfUniqueAttachments = attachments.StreamsCount;
                        stats.CountOfIndexes           = indexes.Count;
                        var statsDatabaseChangeVector = DocumentsStorage.GetDatabaseChangeVector(context);

                        stats.DatabaseChangeVector = statsDatabaseChangeVector;
                        stats.DatabaseId           = Database.DocumentsStorage.Environment.Base64Id;
                        stats.Is64Bit = IntPtr.Size == sizeof(long);
                        stats.Pager   = Database.DocumentsStorage.Environment.Options.DataPager.GetType().ToString();

                        stats.Indexes = new IndexInformation[indexes.Count];
                        for (var i = 0; i < indexes.Count; i++)
                        {
                            var index = indexes[i];
                            stats.Indexes[i] = new IndexInformation
                            {
                                State            = index.State,
                                IsStale          = index.IsStale(context),
                                Name             = index.Name,
                                Etag             = index.Etag,
                                LockMode         = index.Definition.LockMode,
                                Priority         = index.Definition.Priority,
                                Type             = index.Type,
                                LastIndexingTime = index.LastIndexingTime
                            };

                            if (stats.LastIndexingTime.HasValue)
                            {
                                stats.LastIndexingTime = stats.LastIndexingTime >= index.LastIndexingTime ? stats.LastIndexingTime : index.LastIndexingTime;
                            }
                            else
                            {
                                stats.LastIndexingTime = index.LastIndexingTime;
                            }
                        }

                        writer.WriteDatabaseStatistics(context, stats);
                    }

            return(Task.CompletedTask);
        }
Esempio n. 3
0
        protected long GetLastEtagForCollection(DocumentsOperationContext context, string collection, bool isAllDocs)
        {
            if (isAllDocs)
            {
                return(DocumentsStorage.ReadLastDocumentEtag(context.Transaction.InnerTransaction));
            }

            return(Database.DocumentsStorage.GetLastDocumentEtag(context.Transaction.InnerTransaction, collection));
        }
        public override long GetLastItemEtag(DocumentsOperationContext context, string collection)
        {
            var isAllDocs = collection == Constants.Documents.Collections.AllDocumentsCollection;

            if (isAllDocs)
            {
                return(DocumentsStorage.ReadLastDocumentEtag(context.Transaction.InnerTransaction));
            }

            return(Database.DocumentsStorage.GetLastDocumentEtag(context.Transaction.InnerTransaction, collection));
        }
Esempio n. 5
0
        public Task Stats()
        {
            DocumentsOperationContext context;

            using (ContextPool.AllocateOperationContext(out context))
                using (var writer = new BlittableJsonTextWriter(context, ResponseBodyStream()))
                    using (context.OpenReadTransaction())
                    {
                        var indexes           = Database.IndexStore.GetIndexes().ToList();
                        var transformersCount = Database.TransformerStore.GetTransformersCount();

                        var stats = new DatabaseStatistics();
                        stats.LastDocEtag              = DocumentsStorage.ReadLastDocumentEtag(context.Transaction.InnerTransaction);
                        stats.CountOfDocuments         = Database.DocumentsStorage.GetNumberOfDocuments(context);
                        stats.CountOfRevisionDocuments = Database.BundleLoader.VersioningStorage?.GetNumberOfRevisionDocuments(context);
                        stats.CountOfIndexes           = indexes.Count;
                        stats.CountOfTransformers      = transformersCount;
                        stats.DatabaseId = Database.DocumentsStorage.Environment.DbId;
                        stats.Is64Bit    = IntPtr.Size == sizeof(long);

                        stats.Indexes = new IndexInformation[indexes.Count];
                        for (var i = 0; i < indexes.Count; i++)
                        {
                            var index = indexes[i];
                            stats.Indexes[i] = new IndexInformation
                            {
                                State            = index.State,
                                IsStale          = index.IsStale(context),
                                Name             = index.Name,
                                IndexId          = index.IndexId,
                                LockMode         = index.Definition.LockMode,
                                Type             = index.Type,
                                LastIndexingTime = index.LastIndexingTime
                            };

                            if (stats.LastIndexingTime.HasValue)
                            {
                                stats.LastIndexingTime = stats.LastIndexingTime >= index.LastIndexingTime ? stats.LastIndexingTime : index.LastIndexingTime;
                            }
                            else
                            {
                                stats.LastIndexingTime = index.LastIndexingTime;
                            }
                        }

                        writer.WriteDatabaseStatistics(context, stats);
                    }

            return(Task.CompletedTask);
        }
Esempio n. 6
0
        private unsafe void FillCountOfResultsAndIndexEtag(QueryResultServerSide resultToFill, string collection, DocumentsOperationContext context)
        {
            var buffer = stackalloc long[3];

            if (collection == Constants.Documents.Collections.AllDocumentsCollection)
            {
                var numberOfDocuments = Database.DocumentsStorage.GetNumberOfDocuments(context);
                buffer[0] = DocumentsStorage.ReadLastDocumentEtag(context.Transaction.InnerTransaction);
                buffer[1] = DocumentsStorage.ReadLastTombstoneEtag(context.Transaction.InnerTransaction);
                buffer[2] = numberOfDocuments;
                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;
            }

            resultToFill.ResultEtag = (long)Hashing.XXHash64.Calculate((byte *)buffer, sizeof(long) * 3);
        }
Esempio n. 7
0
        private void FillDatabaseStatistics(DatabaseStatistics stats, DocumentsOperationContext context)
        {
            using (context.OpenReadTransaction())
            {
                var indexes = Database.IndexStore.GetIndexes().ToList();

                var size = Database.GetSizeOnDisk();

                stats.LastDocEtag               = DocumentsStorage.ReadLastDocumentEtag(context.Transaction.InnerTransaction);
                stats.CountOfDocuments          = Database.DocumentsStorage.GetNumberOfDocuments(context);
                stats.CountOfRevisionDocuments  = Database.DocumentsStorage.RevisionsStorage.GetNumberOfRevisionDocuments(context);
                stats.CountOfDocumentsConflicts = Database.DocumentsStorage.ConflictsStorage.GetNumberOfDocumentsConflicts(context);
                stats.CountOfTombstones         = Database.DocumentsStorage.GetNumberOfTombstones(context);
                stats.CountOfConflicts          = Database.DocumentsStorage.ConflictsStorage.ConflictsCount;
                stats.SizeOnDisk = size.Data;
                stats.NumberOfTransactionMergerQueueOperations = Database.TxMerger.NumberOfQueuedOperations;
                stats.TempBuffersSizeOnDisk = size.TempBuffers;
                stats.CountOfCounterEntries = Database.DocumentsStorage.CountersStorage.GetNumberOfCounterEntries(context);

                var attachments = Database.DocumentsStorage.AttachmentsStorage.GetNumberOfAttachments(context);
                stats.CountOfAttachments       = attachments.AttachmentCount;
                stats.CountOfUniqueAttachments = attachments.StreamsCount;

                stats.CountOfIndexes = indexes.Count;
                var statsDatabaseChangeVector = DocumentsStorage.GetDatabaseChangeVector(context);

                stats.DatabaseChangeVector = statsDatabaseChangeVector;
                stats.DatabaseId           = Database.DocumentsStorage.Environment.Base64Id;
                stats.Is64Bit = !Database.DocumentsStorage.Environment.Options.ForceUsing32BitsPager && IntPtr.Size == sizeof(long);
                stats.Pager   = Database.DocumentsStorage.Environment.Options.DataPager.GetType().ToString();

                stats.Indexes = new IndexInformation[indexes.Count];
                for (var i = 0; i < indexes.Count; i++)
                {
                    var  index = indexes[i];
                    bool isStale;
                    try
                    {
                        isStale = index.IsStale(context);
                    }
                    catch (OperationCanceledException)
                    {
                        // if the index has just been removed, let us consider it stale
                        // until it can be safely removed from the list of indexes in the
                        // database
                        isStale = true;
                    }
                    stats.Indexes[i] = new IndexInformation
                    {
                        State            = index.State,
                        IsStale          = isStale,
                        Name             = index.Name,
                        LockMode         = index.Definition.LockMode,
                        Priority         = index.Definition.Priority,
                        Type             = index.Type,
                        LastIndexingTime = index.LastIndexingTime
                    };

                    if (stats.LastIndexingTime.HasValue)
                    {
                        stats.LastIndexingTime = stats.LastIndexingTime >= index.LastIndexingTime ? stats.LastIndexingTime : index.LastIndexingTime;
                    }
                    else
                    {
                        stats.LastIndexingTime = index.LastIndexingTime;
                    }
                }
            }
        }
Esempio n. 8
0
        private unsafe void FillCountOfResultsAndIndexEtag(QueryResultServerSide <Document> resultToFill, QueryMetadata query, DocumentsOperationContext context)
        {
            var bufferSize  = 3;
            var hasCounters = query.HasCounterSelect || query.CounterIncludes != null;

            if (hasCounters)
            {
                bufferSize++;
            }
            if (query.HasCmpXchgSelect)
            {
                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);
                buffer[0] = DocumentsStorage.ReadLastDocumentEtag(context.Transaction.InnerTransaction);
                buffer[1] = DocumentsStorage.ReadLastTombstoneEtag(context.Transaction.InnerTransaction);
                buffer[2] = numberOfDocuments;

                if (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 (hasCounters)
                {
                    buffer[3] = Database.DocumentsStorage.CountersStorage.GetLastCounterEtag(context, collection);
                }

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

            if (query.HasCmpXchgSelect)
            {
                using (context.DocumentDatabase.ServerStore.ContextPool.AllocateOperationContext(out TransactionOperationContext transactionContext))
                    using (transactionContext.OpenReadTransaction())
                    {
                        buffer[bufferSize - 1] = Database.ServerStore.Cluster.GetLastCompareExchangeIndexForDatabase(transactionContext, Database.Name);
                    }
            }

            resultToFill.ResultEtag = (long)Hashing.XXHash64.Calculate((byte *)buffer, sizeof(long) * (uint)bufferSize);
            resultToFill.NodeTag    = Database.ServerStore.NodeTag;
        }
Esempio n. 9
0
        public Task Stats()
        {
            using (ContextPool.AllocateOperationContext(out DocumentsOperationContext context))
                using (var writer = new BlittableJsonTextWriter(context, ResponseBodyStream()))
                    using (context.OpenReadTransaction())
                    {
                        var indexes = Database.IndexStore.GetIndexes().ToList();

                        var sizeOnDiskInBytes = Database.GetSizeOnDiskInBytes();

                        var stats = new DatabaseStatistics
                        {
                            LastDocEtag               = DocumentsStorage.ReadLastDocumentEtag(context.Transaction.InnerTransaction),
                            CountOfDocuments          = Database.DocumentsStorage.GetNumberOfDocuments(context),
                            CountOfRevisionDocuments  = Database.DocumentsStorage.RevisionsStorage.GetNumberOfRevisionDocuments(context),
                            CountOfDocumentsConflicts = Database.DocumentsStorage.ConflictsStorage.GetCountOfDocumentsConflicts(context),
                            CountOfConflicts          = Database.DocumentsStorage.ConflictsStorage.ConflictsCount,
                            SizeOnDisk = new Size(sizeOnDiskInBytes)
                        };

                        var attachments = Database.DocumentsStorage.AttachmentsStorage.GetNumberOfAttachments(context);
                        stats.CountOfAttachments       = attachments.AttachmentCount;
                        stats.CountOfUniqueAttachments = attachments.StreamsCount;
                        stats.CountOfIndexes           = indexes.Count;
                        var statsDatabaseChangeVector = DocumentsStorage.GetDatabaseChangeVector(context);

                        stats.DatabaseChangeVector = statsDatabaseChangeVector;
                        stats.DatabaseId           = Database.DocumentsStorage.Environment.Base64Id;
                        stats.Is64Bit = !Database.DocumentsStorage.Environment.Options.ForceUsing32BitsPager && IntPtr.Size == sizeof(long);
                        stats.Pager   = Database.DocumentsStorage.Environment.Options.DataPager.GetType().ToString();

                        stats.Indexes = new IndexInformation[indexes.Count];
                        for (var i = 0; i < indexes.Count; i++)
                        {
                            var  index = indexes[i];
                            bool isStale;
                            try
                            {
                                isStale = index.IsStale(context);
                            }
                            catch (OperationCanceledException)
                            {
                                // if the index has just been removed, let us consider it stale
                                // until it can be safely removed from the list of indexes in the
                                // database
                                isStale = true;
                            }
                            stats.Indexes[i] = new IndexInformation
                            {
                                State            = index.State,
                                IsStale          = isStale,
                                Name             = index.Name,
                                Etag             = index.Etag,
                                LockMode         = index.Definition.LockMode,
                                Priority         = index.Definition.Priority,
                                Type             = index.Type,
                                LastIndexingTime = index.LastIndexingTime
                            };

                            if (stats.LastIndexingTime.HasValue)
                            {
                                stats.LastIndexingTime = stats.LastIndexingTime >= index.LastIndexingTime ? stats.LastIndexingTime : index.LastIndexingTime;
                            }
                            else
                            {
                                stats.LastIndexingTime = index.LastIndexingTime;
                            }
                        }

                        writer.WriteDatabaseStatistics(context, stats);
                    }

            return(Task.CompletedTask);
        }