private void DeleteIndexMetadataForRemovedIndexesAndTransformers(Transaction tx, TransactionOperationContext context, IndexStore indexStore, TransformerStore transformerStore) { var toRemove = new List <IndexEntryMetadata>(); var table = tx.OpenTable(IndexesTableSchema, SchemaNameConstants.IndexMetadataTable); foreach (var tvr in table.SeekForwardFrom(IndexesTableSchema.FixedSizeIndexes[EtagIndexName], 0)) { var metadata = TableValueToMetadata(tvr, context, true); if (metadata == null) //noting to do if it is a tombstone { continue; } if (metadata.Type == IndexEntryType.Index && indexStore.GetIndex(metadata.Id) == null) { toRemove.Add(metadata); } if (metadata.Type == IndexEntryType.Transformer && transformerStore.GetTransformer(metadata.Id) == null) { toRemove.Add(metadata); } } foreach (var metadata in toRemove) { WriteEntry(tx, metadata.Name, metadata.Type, -1, context); } }
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); }