public DynamicJsonValue GenerateDatabaseInfo() { Size size = new Size(GetAllStoragesEnvironment().Sum(env => env.Environment.Stats().AllocatedDataFileSizeInBytes)); var databaseInfo = new DynamicJsonValue { [nameof(ResourceInfo.Bundles)] = new DynamicJsonArray(BundleLoader.GetActiveBundles()), [nameof(ResourceInfo.IsAdmin)] = true, //TODO: implement me! [nameof(ResourceInfo.Name)] = Name, [nameof(ResourceInfo.Disabled)] = false, //TODO: this value should be overwritten by the studio since it is cached [nameof(ResourceInfo.TotalSize)] = new DynamicJsonValue { [nameof(Size.HumaneSize)] = size.HumaneSize, [nameof(Size.SizeInBytes)] = size.SizeInBytes }, [nameof(ResourceInfo.Errors)] = IndexStore.GetIndexes().Sum(index => index.GetErrors().Count), [nameof(ResourceInfo.Alerts)] = Alerts.GetAlertCount(), [nameof(ResourceInfo.UpTime)] = null, //it is shutting down [nameof(ResourceInfo.BackupInfo)] = BundleLoader.GetBackupInfo(), [nameof(DatabaseInfo.DocumentsCount)] = DocumentsStorage.GetNumberOfDocuments(), [nameof(DatabaseInfo.IndexesCount)] = IndexStore.GetIndexes().Count(), [nameof(DatabaseInfo.RejectClients)] = false, //TODO: implement me! [nameof(DatabaseInfo.IndexingStatus)] = IndexStore.Status.ToString(), [CachedDatabaseInfo] = true }; return(databaseInfo); }
public DynamicJsonValue GenerateDatabaseInfo() { var envs = GetAllStoragesEnvironment().ToList(); if (envs.Any(x => x.Environment == null)) { return(null); } var size = new Size(envs.Sum(env => env.Environment.Stats().AllocatedDataFileSizeInBytes)); var databaseInfo = new DynamicJsonValue { [nameof(DatabaseInfo.HasRevisionsConfiguration)] = DocumentsStorage.RevisionsStorage.Configuration != null, [nameof(DatabaseInfo.HasExpirationConfiguration)] = ExpiredDocumentsCleaner != null, [nameof(DatabaseInfo.IsAdmin)] = true, //TODO: implement me! [nameof(DatabaseInfo.IsEncrypted)] = DocumentsStorage.Environment.Options.EncryptionEnabled, [nameof(DatabaseInfo.Name)] = Name, [nameof(DatabaseInfo.Disabled)] = false, //TODO: this value should be overwritten by the studio since it is cached [nameof(DatabaseInfo.TotalSize)] = new DynamicJsonValue { [nameof(Size.HumaneSize)] = size.HumaneSize, [nameof(Size.SizeInBytes)] = size.SizeInBytes }, [nameof(DatabaseInfo.IndexingErrors)] = IndexStore.GetIndexes().Sum(index => index.GetErrorCount()), [nameof(DatabaseInfo.Alerts)] = NotificationCenter.GetAlertCount(), [nameof(DatabaseInfo.UpTime)] = null, //it is shutting down [nameof(DatabaseInfo.BackupInfo)] = PeriodicBackupRunner.GetBackupInfo(), [nameof(DatabaseInfo.DocumentsCount)] = DocumentsStorage.GetNumberOfDocuments(), [nameof(DatabaseInfo.IndexesCount)] = IndexStore.GetIndexes().Count(), [nameof(DatabaseInfo.RejectClients)] = false, //TODO: implement me! [nameof(DatabaseInfo.IndexingStatus)] = IndexStore.Status.ToString(), ["CachedDatabaseInfo"] = true }; return(databaseInfo); }
public bool IsEmpty() { if (CollectionName == string.Empty) { return(_documentStorage.GetNumberOfDocuments() == 0); } return(_documentStorage.GetCollection(CollectionName, _context).Count == 0); }
public DatabaseSummary GetDatabaseSummary(DocumentsOperationContext documentsContext) { return(new DatabaseSummary { DocumentsCount = DocumentsStorage.GetNumberOfDocuments(), AttachmentsCount = DocumentsStorage.AttachmentsStorage.GetNumberOfAttachments(documentsContext).AttachmentCount, RevisionsCount = DocumentsStorage.RevisionsStorage.GetNumberOfRevisionDocuments(documentsContext), ConflictsCount = DocumentsStorage.ConflictsStorage.GetNumberOfConflicts(documentsContext) }); }
public DatabaseSummary GetDatabaseSummary() { using (DocumentsStorage.ContextPool.AllocateOperationContext(out DocumentsOperationContext documentsContext)) using (documentsContext.OpenReadTransaction()) { return(new DatabaseSummary { DocumentsCount = DocumentsStorage.GetNumberOfDocuments(), AttachmentsCount = DocumentsStorage.AttachmentsStorage.GetNumberOfAttachments(documentsContext).AttachmentCount, RevisionsCount = DocumentsStorage.RevisionsStorage.GetNumberOfRevisionDocuments(documentsContext) }); } }
public DatabaseSummary GetDatabaseSummary() { using (DocumentsStorage.ContextPool.AllocateOperationContext(out DocumentsOperationContext documentsContext)) using (_serverStore.ContextPool.AllocateOperationContext(out TransactionOperationContext context)) using (documentsContext.OpenReadTransaction()) using (context.OpenReadTransaction()) { return(new DatabaseSummary { DocumentsCount = DocumentsStorage.GetNumberOfDocuments(), AttachmentsCount = DocumentsStorage.AttachmentsStorage.GetNumberOfAttachments(documentsContext).AttachmentCount, RevisionsCount = DocumentsStorage.RevisionsStorage.GetNumberOfRevisionDocuments(documentsContext), IndexesCount = IndexStore.GetIndexes().Count(), IdentitiesCount = _serverStore.Cluster.GetIdentitiesCount(context) }); } }
private IEnumerable <Document> GetDocuments() { IEnumerable <Document> documents; if (_startsWith != null) { if (_isAllDocsCollection) { documents = _documents.GetDocumentsStartingWith(_context, _startsWith, null, null, null, _start, _query.PageSize); } else { documents = _documents.GetDocumentsStartingWith(_context, _startsWith, null, null, null, _start, _query.PageSize, _collection); } } else if (_ids != null) { if (_ids.Count == 0) { documents = Enumerable.Empty <Document>(); } else { documents = _isAllDocsCollection ? _documents.GetDocuments(_context, _ids, _start, _query.PageSize, _totalResults) : _documents.GetDocuments(_context, _ids, _collection, _start, _query.PageSize, _totalResults); } } else if (_isAllDocsCollection) { documents = _documents.GetDocumentsFrom(_context, 0, _start, _query.PageSize); _totalResults.Value = (int)_documents.GetNumberOfDocuments(_context); } else { documents = _documents.GetDocumentsFrom(_context, _collection, 0, _start, _query.PageSize); _totalResults.Value = (int)_documents.GetCollection(_collection, _context).Count; } return(documents); }
private IEnumerable <Document> GetDocuments() { IEnumerable <Document> documents; if (_ids != null && _ids.Count > 0) { documents = _documents.GetDocuments(_context, _ids, _start, _query.PageSize, _totalResults); } else if (_isAllDocsCollection) { documents = _documents.GetDocumentsFrom(_context, 0, _start, _query.PageSize); _totalResults.Value = (int)_documents.GetNumberOfDocuments(_context); } else { documents = _documents.GetDocumentsFrom(_context, _collection, 0, _start, _query.PageSize); _totalResults.Value = (int)_documents.GetCollection(_collection, _context).Count; } return(ApplySorting(documents)); }
private static void FillDocumentsInfo(DatabaseStatusReport prevDatabaseReport, DocumentDatabase dbInstance, DatabaseStatusReport report, DocumentsOperationContext context, DocumentsStorage documentsStorage) { if (prevDatabaseReport?.LastTransactionId != null && prevDatabaseReport.LastTransactionId == dbInstance.LastTransactionId) { report.LastEtag = prevDatabaseReport.LastEtag; report.LastTombstoneEtag = prevDatabaseReport.LastTombstoneEtag; report.NumberOfConflicts = prevDatabaseReport.NumberOfConflicts; report.NumberOfDocuments = prevDatabaseReport.NumberOfDocuments; report.DatabaseChangeVector = prevDatabaseReport.DatabaseChangeVector; } else { using (var tx = context.OpenReadTransaction()) { report.LastEtag = DocumentsStorage.ReadLastEtag(tx.InnerTransaction); report.LastTombstoneEtag = DocumentsStorage.ReadLastTombstoneEtag(tx.InnerTransaction); report.NumberOfConflicts = documentsStorage.ConflictsStorage.ConflictsCount; report.NumberOfDocuments = documentsStorage.GetNumberOfDocuments(context); report.DatabaseChangeVector = DocumentsStorage.GetDatabaseChangeVector(context); } } }
private unsafe void FillCountOfResultsAndIndexEtag(QueryResultServerSide resultToFill, string collection) { var buffer = stackalloc long[3]; if (collection == Constants.Documents.Collections.AllDocumentsCollection) { var numberOfDocuments = _documents.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 = _documents.GetCollection(collection, _context); buffer[0] = _documents.GetLastDocumentEtag(_context, collection); buffer[1] = _documents.GetLastTombstoneEtag(_context, collection); buffer[2] = collectionStats.Count; } resultToFill.ResultEtag = (long)Hashing.XXHash64.Calculate((byte *)buffer, sizeof(long) * 3); }
private IEnumerable <Document> GetDocuments() { IEnumerable <Document> documents; if (_startsWith != null) { var countQuery = false; if (_query.PageSize == 0) { countQuery = true; _query.PageSize = int.MaxValue; } if (_isAllDocsCollection) { documents = _documents.GetDocumentsStartingWith(_context, _startsWith, null, null, null, _start, _query.PageSize); } else { documents = _documents.GetDocumentsStartingWith(_context, _startsWith, null, null, null, _start, _query.PageSize, _collection); } if (countQuery) { foreach (var document in documents) { using (document.Data) _totalResults.Value++; } documents = Enumerable.Empty <Document>(); _query.PageSize = 0; } } else if (_ids != null) { if (_ids.Count == 0) { documents = Enumerable.Empty <Document>(); } else { documents = _isAllDocsCollection ? _documents.GetDocuments(_context, _ids, _start, _query.PageSize, _totalResults) : _documents.GetDocuments(_context, _ids, _collection, _start, _query.PageSize, _totalResults); } } else if (_isAllDocsCollection) { documents = _documents.GetDocumentsFrom(_context, 0, _start, _query.PageSize); _totalResults.Value = (int)_documents.GetNumberOfDocuments(_context); } else { documents = _documents.GetDocumentsFrom(_context, _collection, 0, _start, _query.PageSize); _totalResults.Value = (int)_documents.GetCollection(_collection, _context).Count; } return(documents); }
private void ExecuteCollectionQuery(QueryResultServerSide resultToFill, IndexQueryServerSide query, string collection) { var isAllDocsCollection = collection == Constants.Indexing.AllDocumentsCollection; // we optimize for empty queries without sorting options resultToFill.IndexName = isAllDocsCollection ? "AllDocs" : collection; resultToFill.IsStale = false; resultToFill.ResultEtag = Environment.TickCount; resultToFill.LastQueryTime = DateTime.MinValue; resultToFill.IndexTimestamp = DateTime.MinValue; _context.OpenReadTransaction(); if (isAllDocsCollection) { resultToFill.TotalResults = (int)_documents.GetNumberOfDocuments(_context); } else { var collectionStats = _documents.GetCollection(collection, _context); resultToFill.TotalResults = (int)collectionStats.Count; } var includeDocumentsCommand = new IncludeDocumentsCommand(_documents, _context, query.Includes); Transformer transformer = null; if (string.IsNullOrEmpty(query.Transformer) == false) { transformer = _transformerStore.GetTransformer(query.Transformer); if (transformer == null) { throw new InvalidOperationException($"The transformer '{query.Transformer}' was not found."); } } using (var scope = transformer?.OpenTransformationScope(query.TransformerParameters, includeDocumentsCommand, _documents, _transformerStore, _context)) { var fieldsToFetch = new FieldsToFetch(query, null, transformer); var documents = new CollectionQueryEnumerable(_documents, fieldsToFetch, collection, query, _context); var results = scope != null?scope.Transform(documents) : documents; try { foreach (var document in results) { _token.Token.ThrowIfCancellationRequested(); resultToFill.AddResult(document); includeDocumentsCommand.Gather(document); } } catch (Exception e) { if (resultToFill.SupportsExceptionHandling == false) { throw; } resultToFill.HandleException(e); } } includeDocumentsCommand.Fill(resultToFill.Includes); }
private IEnumerable <Document> GetDocuments() { IEnumerable <Document> documents; if (_startsWith != null) { var countQuery = false; if (_query.PageSize == 0) { countQuery = true; _query.PageSize = int.MaxValue; } documents = _isAllDocsCollection ? _documents.GetDocumentsStartingWith(_context, _startsWith, null, null, _startAfterId, _start, _query.PageSize, fields: _fields) : _documents.GetDocumentsStartingWith(_context, _startsWith, null, null, _startAfterId, _start, _query.PageSize, _collection, _fields); if (countQuery) { foreach (var document in documents) { using (document.Data) _totalResults.Value++; } documents = Enumerable.Empty <Document>(); _query.PageSize = 0; } } else if (_ids != null) { if (_ids.Count == 0) { documents = Enumerable.Empty <Document>(); } else if (_alreadySeenIdsCount != null) { var idsLeft = _ids.Count - _alreadySeenIdsCount.Value; if (idsLeft == 0) { documents = Enumerable.Empty <Document>(); } else { var count = idsLeft >= _query.PageSize ? _query.PageSize : idsLeft; var ids = _ids.Skip((int)_alreadySeenIdsCount.Value).Take((int)count); _alreadySeenIdsCount.Value += count; documents = _isAllDocsCollection ? _documents.GetDocuments(_context, ids, 0, _query.PageSize, _totalResults) : _documents.GetDocuments(_context, ids, _collection, 0, _query.PageSize, _totalResults); } } else { documents = _isAllDocsCollection ? _documents.GetDocuments(_context, _ids, _start, _query.PageSize, _totalResults) : _documents.GetDocuments(_context, _ids, _collection, _start, _query.PageSize, _totalResults); } } else if (_isAllDocsCollection) { documents = _documents.GetDocumentsFrom(_context, 0, _start, _query.PageSize); _totalResults.Value = (int)_documents.GetNumberOfDocuments(_context); } else { documents = _documents.GetDocumentsFrom(_context, _collection, 0, _start, _query.PageSize); _totalResults.Value = (int)_documents.GetCollection(_collection, _context).Count; } return(documents); }