public async Task Stale() { var name = GetQueryStringValueAndAssertIfSingleAndNotEmpty("name"); var index = Database.IndexStore.GetIndex(name); if (index == null) { IndexDoesNotExistException.ThrowFor(name); } using (var context = QueryOperationContext.Allocate(Database, index)) await using (var writer = new AsyncBlittableJsonTextWriter(context.Documents, ResponseBodyStream())) using (context.OpenReadTransaction()) { var stalenessReasons = new List <string>(); var isStale = index.IsStale(context, stalenessReasons: stalenessReasons); writer.WriteStartObject(); writer.WritePropertyName("IsStale"); writer.WriteBool(isStale); writer.WriteComma(); writer.WriteArray("StalenessReasons", stalenessReasons); writer.WriteEndObject(); } }
public Task ClearErrors() { var names = GetStringValuesQueryString("name", required: false); var indexes = new List <Index>(); if (names.Count == 0) { indexes.AddRange(Database.IndexStore.GetIndexes()); } else { foreach (var name in names) { var index = Database.IndexStore.GetIndex(name); if (index == null) { IndexDoesNotExistException.ThrowFor(name); } indexes.Add(index); } } foreach (var index in indexes) { index.DeleteErrors(); } return(NoContent()); }
public Task KillQuery() { var name = GetQueryStringValueAndAssertIfSingleAndNotEmpty("indexName"); var id = GetLongQueryString("id"); var index = Database.IndexStore.GetIndex(name); if (index == null) { IndexDoesNotExistException.ThrowFor(name); } var query = index.CurrentlyRunningQueries .FirstOrDefault(q => q.QueryId == id); if (query == null) { HttpContext.Response.StatusCode = (int)HttpStatusCode.NotFound; return(Task.CompletedTask); } query.Token.Cancel(); return(NoContent()); }
public override async Task <IndexEntriesQueryResult> ExecuteIndexEntriesQuery(IndexQueryServerSide query, QueryOperationContext queryContext, long?existingResultEtag, OperationCancelToken token) { var index = await MatchIndex(query, false, null, token.Token); if (index == null) { IndexDoesNotExistException.ThrowFor(query.Metadata.CollectionName); } queryContext.WithIndex(index); if (existingResultEtag.HasValue) { var etag = index.GetIndexEtag(queryContext, query.Metadata); if (etag == existingResultEtag) { return(IndexEntriesQueryResult.NotModifiedResult); } } using (QueryRunner.MarkQueryAsRunning(index.Name, query, token)) { return(await index.IndexEntries(query, queryContext, token)); } }
public Task OpenFaultyIndex() { var name = GetQueryStringValueAndAssertIfSingleAndNotEmpty("name"); var index = Database.IndexStore.GetIndex(name); if (index == null) { IndexDoesNotExistException.ThrowFor(name); } if (index is FaultyInMemoryIndex == false) { throw new InvalidOperationException($"Cannot open non faulty index named: {name}"); } lock (index) { var localIndex = Database.IndexStore.GetIndex(name); if (localIndex == null) { IndexDoesNotExistException.ThrowFor(name); } if (localIndex is FaultyInMemoryIndex == false) { throw new InvalidOperationException($"Cannot open non faulty index named: {name}"); } Database.IndexStore.OpenFaultyIndex(localIndex); } return(NoContent()); }
public Task Stale() { var name = GetQueryStringValueAndAssertIfSingleAndNotEmpty("name"); using (ContextPool.AllocateOperationContext(out DocumentsOperationContext context)) using (var writer = new BlittableJsonTextWriter(context, ResponseBodyStream())) using (context.OpenReadTransaction()) { var index = Database.IndexStore.GetIndex(name); if (index == null) { IndexDoesNotExistException.ThrowFor(name); } var stalenessReasons = new List <string>(); var isStale = index.IsStale(context, stalenessReasons: stalenessReasons); writer.WriteStartObject(); writer.WritePropertyName("IsStale"); writer.WriteBool(isStale); writer.WriteComma(); writer.WriteArray("StalenessReasons", stalenessReasons); writer.WriteEndObject(); } return(Task.CompletedTask); }
public Task GetErrors() { var names = GetStringValuesQueryString("name", required: false); List <Index> indexes; if (names.Count == 0) { indexes = Database.IndexStore.GetIndexes().ToList(); } else { indexes = new List <Index>(); foreach (var name in names) { var index = Database.IndexStore.GetIndex(name); if (index == null) { IndexDoesNotExistException.ThrowFor(name); } indexes.Add(index); } } using (ContextPool.AllocateOperationContext(out DocumentsOperationContext context)) using (var writer = new BlittableJsonTextWriter(context, ResponseBodyStream())) { writer.WriteStartObject(); writer.WriteArray(context, "Results", indexes, (w, c, index) => { w.WriteStartObject(); w.WritePropertyName("Name"); w.WriteString(index.Name); w.WriteComma(); w.WriteArray(c, "Errors", index.GetErrors(), (ew, ec, error) => { ew.WriteStartObject(); ew.WritePropertyName(nameof(error.Timestamp)); ew.WriteDateTime(error.Timestamp, isUtc: true); ew.WriteComma(); ew.WritePropertyName(nameof(error.Document)); ew.WriteString(error.Document); ew.WriteComma(); ew.WritePropertyName(nameof(error.Action)); ew.WriteString(error.Action); ew.WriteComma(); ew.WritePropertyName(nameof(error.Error)); ew.WriteString(error.Error); ew.WriteEndObject(); }); w.WriteEndObject(); }); writer.WriteEndObject(); } return(Task.CompletedTask); }
public async Task SetPriority(string name, IndexPriority priority) { await _indexLocker.WaitAsync(); try { var index = GetIndex(name); if (index == null) { IndexDoesNotExistException.ThrowFor(name); } var faultyInMemoryIndex = index as FaultyInMemoryIndex; if (faultyInMemoryIndex != null) { faultyInMemoryIndex.SetPriority(priority); // this will throw proper exception return; } var command = new SetIndexPriorityCommand(name, priority, _documentDatabase.Name); var(etag, _) = await _serverStore.SendToLeaderAsync(command); await _documentDatabase.RachisLogIndexNotifications.WaitForIndexNotification(etag); } finally { _indexLocker.Release(); } }
public async Task Dump() { var name = GetStringQueryString("name"); var path = GetStringQueryString("path"); var index = Database.IndexStore.GetIndex(name); if (index == null) { IndexDoesNotExistException.ThrowFor(name); return; //never hit } var operationId = Database.Operations.GetNextOperationId(); var token = CreateTimeLimitedQueryOperationToken(); _ = Database.Operations.AddOperation( Database, "Dump index " + name + " to " + path, Operations.Operations.OperationType.DumpRawIndexData, onProgress => { var totalFiles = index.Dump(path, onProgress); return(Task.FromResult((IOperationResult) new DumpIndexResult { Message = $"Dumped {totalFiles} files from {name}", })); }, operationId, token: token); using (ContextPool.AllocateOperationContext(out DocumentsOperationContext context)) await using (var writer = new AsyncBlittableJsonTextWriter(context, ResponseBodyStream())) { writer.WriteOperationIdAndNodeTag(context, operationId, ServerStore.NodeTag); } }
public void EnsureIsAcceptable(string indexName, StreamResult result) { if (result != null) return; if (indexName != null) IndexDoesNotExistException.ThrowFor(indexName); }
public Index GetIndex(string indexName) { var index = Database.IndexStore.GetIndex(indexName); if (index == null) { IndexDoesNotExistException.ThrowFor(indexName); } return(index); }
public Index ResetIndex(string name) { var index = GetIndex(name); if (index == null) { IndexDoesNotExistException.ThrowFor(name); } return(ResetIndexInternal(index)); }
public void StartIndex(string name) { var index = GetIndex(name); if (index == null) { IndexDoesNotExistException.ThrowFor(name); } index.Start(); }
public Task Disable() { var name = GetStringQueryString("name"); var index = Database.IndexStore.GetIndex(name); if (index == null) { IndexDoesNotExistException.ThrowFor(name); } index.Disable(); return(NoContent()); }
public Index GetIndex(string indexName, bool throwIfNotExists = true) { var index = Database.IndexStore.GetIndex(indexName); if (index == null && throwIfNotExists) { IndexDoesNotExistException.ThrowFor(indexName); } if (index?.IsPending == true) { throw new PendingRollingIndexException($"Cannot use index `{indexName}` on node {Database.ServerStore.NodeTag} because a rolling index deployment is still pending on this node."); } return(index); }
public void StopIndex(string name) { var index = GetIndex(name); if (index == null) { IndexDoesNotExistException.ThrowFor(name); } index.Stop(); _documentDatabase.Changes.RaiseNotifications(new IndexChange { Name = name, Type = IndexChangeTypes.IndexPaused }); }
public override async Task <IndexEntriesQueryResult> ExecuteIndexEntriesQuery(IndexQueryServerSide query, DocumentsOperationContext context, long?existingResultEtag, OperationCancelToken token) { var index = await MatchIndex(query, false, null, context, token.Token); if (index == null) { IndexDoesNotExistException.ThrowFor(query.Metadata.CollectionName); } if (existingResultEtag.HasValue) { var etag = index.GetIndexEtag(); if (etag == existingResultEtag) { return(IndexEntriesQueryResult.NotModifiedResult); } } return(index.IndexEntries(query, context, token)); }
public Task Progress() { var name = GetQueryStringValueAndAssertIfSingleAndNotEmpty("name"); using (ContextPool.AllocateOperationContext(out DocumentsOperationContext context)) using (var writer = new BlittableJsonTextWriter(context, ResponseBodyStream())) using (context.OpenReadTransaction()) { var index = Database.IndexStore.GetIndex(name); if (index == null) { IndexDoesNotExistException.ThrowFor(name); } var progress = index.GetProgress(context); writer.WriteIndexProgress(context, progress); } return(Task.CompletedTask); }
public async Task DeleteIndex(string name) { await _indexLocker.WaitAsync(); try { var index = GetIndex(name); if (index == null) { IndexDoesNotExistException.ThrowFor(name); } var(newEtag, _) = await _serverStore.SendToLeaderAsync(new DeleteIndexCommand(index.Name, _documentDatabase.Name)); await _documentDatabase.RachisLogIndexNotifications.WaitForIndexNotification(newEtag); } finally { _indexLocker.Release(); } }
protected async Task WaitForIndexAsync(DocumentStore store, string databaseName, string indexName, TimeSpan?timeout = null) { if (timeout == null) { timeout = TimeSpan.FromMinutes(10); } var admin = store.Maintenance.ForDatabase(databaseName); var sp = Stopwatch.StartNew(); while (sp.Elapsed < timeout.Value) { var indexStats = await admin.SendAsync(new GetIndexStatisticsOperation(indexName)); if (indexStats == null) { IndexDoesNotExistException.ThrowFor(indexName); } if (indexStats.Status != IndexRunningStatus.Running) { throw new InvalidOperationException($"Index '{indexName}' is not running!"); } if (indexStats.State != IndexState.Idle && indexStats.State != IndexState.Normal) { throw new InvalidOperationException($"Index '{indexName}' state ({indexStats.State}) is invalid!"); } if (indexStats.IsStale == false) { return; } await Task.Delay(32); } throw new TimeoutException($"The index '{indexName}' stayed stale for more than {timeout.Value}."); }
public async Task <IndexEntriesQueryResult> ExecuteIndexEntries(IndexQueryServerSide query, long?existingResultEtag) { var tuple = await MatchIndex(query, false); var index = tuple.Index; if (index == null) { IndexDoesNotExistException.ThrowFor(query.Metadata.CollectionName); } if (existingResultEtag.HasValue) { var etag = index.GetIndexEtag(); if (etag == existingResultEtag) { return(IndexEntriesQueryResult.NotModifiedResult); } } return(index.IndexEntries(query, _context, _token)); }
public async Task Disable() { var raftRequestId = GetRaftRequestIdFromQuery(); var name = GetStringQueryString("name"); var clusterWide = GetBoolValueQueryString("clusterWide", false) ?? false; var index = Database.IndexStore.GetIndex(name); if (index == null) { IndexDoesNotExistException.ThrowFor(name); } if (clusterWide) { await Database.IndexStore.SetState(name, IndexState.Disabled, $"{raftRequestId}/{index}"); } else { index.Disable(); } NoContentStatus(); }