Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Introducing cancellation tokens and limited time to process queries o…

…n server side queries
  • Loading branch information...
commit 1136a1c8434c64a99350f3ac12956f36350c24c9 1 parent 0341764
@ayende ayende authored
Showing with 349 additions and 238 deletions.
  1. +6 −6 Raven.Client.Embedded/EmbeddedDatabaseCommands.cs
  2. +4 −2 Raven.Database/Bundles/Expiration/ExpiredDocumentsCleaner.cs
  3. +7 −0 Raven.Database/Config/InMemoryRavenConfiguration.cs
  4. +4 −1 Raven.Database/Config/StronglyTypedRavenSettings.cs
  5. +117 −111 Raven.Database/DocumentDatabase.cs
  6. +58 −0 Raven.Database/Extensions/CancellationTokenSource.cs
  7. +10 −2 Raven.Database/Impl/DatabaseBulkOperations.cs
  8. +4 −2 Raven.Database/Indexing/Index.cs
  9. +3 −8 Raven.Database/Indexing/IndexStorage.cs
  10. +3 −2 Raven.Database/Queries/DynamicQueryExtensions.cs
  11. +4 −4 Raven.Database/Queries/DynamicQueryRunner.cs
  12. +1 −0  Raven.Database/Raven.Database.csproj
  13. +2 −2 Raven.Database/Server/HttpServer.cs
  14. +26 −21 Raven.Database/Server/Responders/DocumentBatch.cs
  15. +15 −10 Raven.Database/Server/Responders/Index.cs
  16. +11 −4 Raven.Database/Server/Responders/QueryStreams.cs
  17. +2 −1  Raven.Tests/Bugs/HierarchicalData.cs
  18. +2 −2 Raven.Tests/Bugs/IndexingBehavior.cs
  19. +2 −2 Raven.Tests/Indexes/CompiledIndex.cs
  20. +2 −1  Raven.Tests/Indexes/ComplexIndexOnNotAnalyzedField.cs
  21. +10 −10 Raven.Tests/Indexes/DocumentsToIndex.cs
  22. +5 −4 Raven.Tests/Indexes/QueryingOnDefaultIndex.cs
  23. +5 −5 Raven.Tests/Indexes/QueryingOnStaleIndexes.cs
  24. +3 −3 Raven.Tests/Indexes/Statistics.cs
  25. +3 −2 Raven.Tests/Issues/RavenDB_1007.cs
  26. +2 −2 Raven.Tests/Issues/RavenDB_1497.cs
  27. +3 −1 Raven.Tests/Issues/RavenDB_1600.cs
  28. +2 −1  Raven.Tests/MailingList/FailingBulkInsertTest.cs
  29. +10 −9 Raven.Tests/Queries/ParameterizedDynamicQuery.cs
  30. +4 −4 Raven.Tests/Spatial/SpatialIndexTest.cs
  31. +5 −4 Raven.Tests/Storage/BackupRestore.cs
  32. +2 −1  Raven.Tests/Triggers/IndexTriggers.cs
  33. +10 −9 Raven.Tests/Triggers/ReadTriggers.cs
  34. +1 −1  Raven.Tests/Views/MapReduce.cs
  35. +1 −1  Raven.Tests/Views/MapReduce_IndependentSteps.cs
View
12 Raven.Client.Embedded/EmbeddedDatabaseCommands.cs
@@ -479,11 +479,11 @@ public QueryResult Query(string index, IndexQuery query, string[] includes, bool
string entityName = null;
if (index.StartsWith("dynamic/"))
entityName = index.Substring("dynamic/".Length);
- queryResult = database.ExecuteDynamicQuery(entityName, query.Clone());
+ queryResult = database.ExecuteDynamicQuery(entityName, query.Clone(), CancellationToken.None);
}
else
{
- queryResult = database.Query(index, query.Clone());
+ queryResult = database.Query(index, query.Clone(),CancellationToken.None);
}
var loadedIds = new HashSet<string>(
@@ -534,7 +534,7 @@ public IEnumerator<RavenJObject> StreamQuery(string index, IndexQuery query, out
// the cache for that, to avoid filling it up very quickly
using (DocumentCacher.SkipSettingDocumentsInDocumentCache())
{
- database.Query(index, query, information =>
+ database.Query(index, query, CancellationToken.None, information =>
{
localQueryHeaderInfo = information;
waitForHeaders.Set();
@@ -824,7 +824,7 @@ public Operation UpdateByIndex(string indexName, IndexQuery queryToUpdate, Scrip
public Operation UpdateByIndex(string indexName, IndexQuery queryToUpdate, PatchRequest[] patchRequests, bool allowStale)
{
CurrentOperationContext.Headers.Value = OperationsHeaders;
- var databaseBulkOperations = new DatabaseBulkOperations(database, TransactionInformation);
+ var databaseBulkOperations = new DatabaseBulkOperations(database, TransactionInformation, CancellationToken.None, null);
var state = databaseBulkOperations.UpdateByIndex(indexName, queryToUpdate, patchRequests, allowStale);
return new Operation(0, state);
}
@@ -839,7 +839,7 @@ public Operation UpdateByIndex(string indexName, IndexQuery queryToUpdate, Patch
public Operation UpdateByIndex(string indexName, IndexQuery queryToUpdate, ScriptedPatchRequest patch, bool allowStale)
{
CurrentOperationContext.Headers.Value = OperationsHeaders;
- var databaseBulkOperations = new DatabaseBulkOperations(database, RavenTransactionAccessor.GetTransactionInformation());
+ var databaseBulkOperations = new DatabaseBulkOperations(database, RavenTransactionAccessor.GetTransactionInformation(), CancellationToken.None, null);
var state = databaseBulkOperations.UpdateByIndex(indexName, queryToUpdate, patch, allowStale);
return new Operation(0, state);
}
@@ -864,7 +864,7 @@ public Operation DeleteByIndex(string indexName, IndexQuery queryToDelete)
public Operation DeleteByIndex(string indexName, IndexQuery queryToDelete, bool allowStale)
{
CurrentOperationContext.Headers.Value = OperationsHeaders;
- var databaseBulkOperations = new DatabaseBulkOperations(database, TransactionInformation);
+ var databaseBulkOperations = new DatabaseBulkOperations(database, TransactionInformation, CancellationToken.None, null);
var state = databaseBulkOperations.DeleteByIndex(indexName, queryToDelete, allowStale);
return new Operation(0, state);
}
View
6 Raven.Database/Bundles/Expiration/ExpiredDocumentsCleaner.cs
@@ -15,6 +15,7 @@
using Raven.Abstractions.Logging;
using Raven.Database;
using Raven.Database.Data;
+using Raven.Database.Extensions;
using Raven.Database.Plugins;
namespace Raven.Bundles.Expiration
@@ -78,9 +79,10 @@ private void TimerCallback(object state)
const int pageSize = 1024;
QueryResultWithIncludes queryResult;
-
+ using(var cts = new CancellationTokenSource())
using (Database.DisableAllTriggersForCurrentThread())
{
+ cts.TimeoutAfter(TimeSpan.FromMinutes(5));
queryResult = Database.Query(RavenDocumentsByExpirationDate, new IndexQuery
{
Start = start,
@@ -88,7 +90,7 @@ private void TimerCallback(object state)
Cutoff = currentTime,
Query = query,
FieldsToFetch = new[] { "__document_id" }
- });
+ }, cts.Token);
}
if(queryResult.Results.Count == 0)
View
7 Raven.Database/Config/InMemoryRavenConfiguration.cs
@@ -152,6 +152,8 @@ public void Initialize()
CreateAutoIndexesForAdHocQueriesIfNeeded = ravenSettings.CreateAutoIndexesForAdHocQueriesIfNeeded.Value;
+ DatbaseOperationTimeout = ravenSettings.DatbaseOperationTimeout.Value;
+
TimeToWaitBeforeRunningIdleIndexes = ravenSettings.TimeToWaitBeforeRunningIdleIndexes.Value;
TimeToWaitBeforeMarkingAutoIndexAsIdle = ravenSettings.TimeToWaitBeforeMarkingAutoIndexAsIdle.Value;
@@ -222,6 +224,11 @@ public void Initialize()
/// </summary>
public SemaphoreSlim ConcurrentMultiGetRequests = new SemaphoreSlim(192);
+ /// <summary>
+ /// The time to wait before canceling a database operation such as load (many) or query
+ /// </summary>
+ public TimeSpan DatbaseOperationTimeout { get; private set; }
+
public TimeSpan TimeToWaitBeforeRunningIdleIndexes { get; private set; }
public TimeSpan TimeToWaitBeforeRunningAbandonedIndexes { get; private set; }
View
5 Raven.Database/Config/StronglyTypedRavenSettings.cs
@@ -113,6 +113,8 @@ public void Setup(int defaultMaxNumberOfItemsToIndexInSingleBatch, int defaultIn
TimeSpanArgumentType.FromParse);
TimeToWaitBeforeRunningIdleIndexes = new TimeSpanSetting(settings["Raven/TimeToWaitBeforeRunningIdleIndexes"], TimeSpan.FromMinutes(10), TimeSpanArgumentType.FromParse);
+
+ DatbaseOperationTimeout = new TimeSpanSetting(settings["Raven/DatbaseOperationTimeout"], TimeSpan.FromMinutes(5), TimeSpanArgumentType.FromParse);
TimeToWaitBeforeMarkingAutoIndexAsIdle = new TimeSpanSetting(settings["Raven/TimeToWaitBeforeMarkingAutoIndexAsIdle"], TimeSpan.FromHours(1), TimeSpanArgumentType.FromParse);
@@ -248,5 +250,6 @@ private int GetDefaultMemoryCacheLimitMegabytes()
public BooleanSetting PreventAutomaticSuggestionCreation { get; set; }
public BooleanSetting DisablePerformanceCounters { get; set; }
- }
+ public TimeSpanSetting DatbaseOperationTimeout { get; private set; }
+ }
}
View
228 Raven.Database/DocumentDatabase.cs
@@ -1269,130 +1269,135 @@ private IndexCreationOptions FindIndexCreationOptions(IndexDefinition definition
return findIndexCreationOptions;
}
- public QueryResultWithIncludes Query(string index, IndexQuery query)
+ public QueryResultWithIncludes Query(string index, IndexQuery query, CancellationToken token)
{
var list = new List<RavenJObject>();
- var result = Query(index, query, null, list.Add);
+ var result = Query(index, query, token, null, list.Add);
result.Results = list;
return result;
}
- public QueryResultWithIncludes Query(string index, IndexQuery query, Action<QueryHeaderInformation> headerInfo, Action<RavenJObject> onResult)
+ public QueryResultWithIncludes Query(string index, IndexQuery query, CancellationToken externalCancellationToken, Action<QueryHeaderInformation> headerInfo, Action<RavenJObject> onResult)
{
- var queryStat = AddToCurrentlyRunningQueryList(index, query);
- try
- {
- var fixedName = IndexDefinitionStorage.FixupIndexName(index);
- var highlightings = new Dictionary<string, Dictionary<string, string[]>>();
- Func<IndexQueryResult, object> tryRecordHighlighting = queryResult =>
- {
- if (queryResult.Highligtings != null && queryResult.Key != null)
- highlightings.Add(queryResult.Key, queryResult.Highligtings);
- return null;
- };
- var stale = false;
- Tuple<DateTime, Etag> indexTimestamp = Tuple.Create(DateTime.MinValue, Etag.Empty);
- Etag resultEtag = Etag.Empty;
- var nonAuthoritativeInformation = false;
+ using (var cts = CancellationTokenSource.CreateLinkedTokenSource(externalCancellationToken, workContext.CancellationToken))
+ {
+ var cancellationToken = cts.Token;
+ var queryStat = AddToCurrentlyRunningQueryList(index, query);
+ try
+ {
+ var fixedName = IndexDefinitionStorage.FixupIndexName(index);
+ var highlightings = new Dictionary<string, Dictionary<string, string[]>>();
+ Func<IndexQueryResult, object> tryRecordHighlighting = queryResult =>
+ {
+ if (queryResult.Highligtings != null && queryResult.Key != null)
+ highlightings.Add(queryResult.Key, queryResult.Highligtings);
+ return null;
+ };
+ var stale = false;
+ Tuple<DateTime, Etag> indexTimestamp = Tuple.Create(DateTime.MinValue, Etag.Empty);
+ Etag resultEtag = Etag.Empty;
+ var nonAuthoritativeInformation = false;
- if (string.IsNullOrEmpty(query.ResultsTransformer) == false)
- {
- query.FieldsToFetch = new[] { Constants.AllFields };
- }
+ if (string.IsNullOrEmpty(query.ResultsTransformer) == false)
+ {
+ query.FieldsToFetch = new[] { Constants.AllFields };
+ }
- var duration = Stopwatch.StartNew();
- var idsToLoad = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
- TransactionalStorage.Batch(
- actions =>
- {
- var viewGenerator = IndexDefinitionStorage.GetViewGenerator(fixedName);
- if (viewGenerator == null)
- throw new IndexDoesNotExistsException("Could not find index named: " + index);
+ var duration = Stopwatch.StartNew();
+ var idsToLoad = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
+ TransactionalStorage.Batch(
+ actions =>
+ {
+ var viewGenerator = IndexDefinitionStorage.GetViewGenerator(fixedName);
+ if (viewGenerator == null)
+ throw new IndexDoesNotExistsException("Could not find index named: " + index);
- resultEtag = GetIndexEtag(fixedName, null, query.ResultsTransformer);
+ resultEtag = GetIndexEtag(fixedName, null, query.ResultsTransformer);
- stale = actions.Staleness.IsIndexStale(fixedName, query.Cutoff, query.CutoffEtag);
+ stale = actions.Staleness.IsIndexStale(fixedName, query.Cutoff, query.CutoffEtag);
- if (stale == false && query.Cutoff == null && query.CutoffEtag == null)
- {
- var indexInstance = IndexStorage.GetIndexInstance(fixedName);
- stale = stale || (indexInstance != null && indexInstance.IsMapIndexingInProgress);
- }
+ if (stale == false && query.Cutoff == null && query.CutoffEtag == null)
+ {
+ var indexInstance = IndexStorage.GetIndexInstance(fixedName);
+ stale = stale || (indexInstance != null && indexInstance.IsMapIndexingInProgress);
+ }
- indexTimestamp = actions.Staleness.IndexLastUpdatedAt(fixedName);
- var indexFailureInformation = actions.Indexing.GetFailureRate(fixedName);
- if (indexFailureInformation.IsInvalidIndex)
- {
- throw new IndexDisabledException(indexFailureInformation);
- }
- var docRetriever = new DocumentRetriever(actions, ReadTriggers, inFlightTransactionalState, query.QueryInputs, idsToLoad);
- var indexDefinition = GetIndexDefinition(fixedName);
- var fieldsToFetch = new FieldsToFetch(query.FieldsToFetch, query.AggregationOperation,
- viewGenerator.ReduceDefinition == null
- ? Constants.DocumentIdFieldName
- : Constants.ReduceKeyFieldName);
- Func<IndexQueryResult, bool> shouldIncludeInResults =
- result => docRetriever.ShouldIncludeResultInQuery(result, indexDefinition, fieldsToFetch);
- var indexQueryResults = IndexStorage.Query(fixedName, query, shouldIncludeInResults, fieldsToFetch, IndexQueryTriggers);
- indexQueryResults = new ActiveEnumerable<IndexQueryResult>(indexQueryResults);
-
- var transformerErrors = new List<string>();
- var results = GetQueryResults(query, viewGenerator, docRetriever,
- from queryResult in indexQueryResults
- let doc = docRetriever.RetrieveDocumentForQuery(queryResult, indexDefinition, fieldsToFetch)
- where doc != null
- let _ = nonAuthoritativeInformation |= (doc.NonAuthoritativeInformation ?? false)
- let __ = tryRecordHighlighting(queryResult)
- select doc, transformerErrors);
-
- if (headerInfo != null)
- {
- headerInfo(new QueryHeaderInformation
- {
- Index = index,
- IsStable = stale,
- ResultEtag = resultEtag,
- IndexTimestamp = indexTimestamp.Item1,
- IndexEtag = indexTimestamp.Item2,
- TotalResults = query.TotalSize.Value
- });
- }
- using (new CurrentTransformationScope(docRetriever))
- {
- foreach (var result in results)
- {
- onResult(result);
- }
- if (transformerErrors.Count > 0)
- {
- throw new InvalidOperationException("The transform results function failed.\r\n" + string.Join("\r\n", transformerErrors));
- }
+ indexTimestamp = actions.Staleness.IndexLastUpdatedAt(fixedName);
+ var indexFailureInformation = actions.Indexing.GetFailureRate(fixedName);
+ if (indexFailureInformation.IsInvalidIndex)
+ {
+ throw new IndexDisabledException(indexFailureInformation);
+ }
+ var docRetriever = new DocumentRetriever(actions, ReadTriggers, inFlightTransactionalState, query.QueryInputs, idsToLoad);
+ var indexDefinition = GetIndexDefinition(fixedName);
+ var fieldsToFetch = new FieldsToFetch(query.FieldsToFetch, query.AggregationOperation,
+ viewGenerator.ReduceDefinition == null
+ ? Constants.DocumentIdFieldName
+ : Constants.ReduceKeyFieldName);
+ Func<IndexQueryResult, bool> shouldIncludeInResults =
+ result => docRetriever.ShouldIncludeResultInQuery(result, indexDefinition, fieldsToFetch);
+ var indexQueryResults = IndexStorage.Query(fixedName, query, shouldIncludeInResults, fieldsToFetch, IndexQueryTriggers, cancellationToken);
+ indexQueryResults = new ActiveEnumerable<IndexQueryResult>(indexQueryResults);
+
+ var transformerErrors = new List<string>();
+ var results = GetQueryResults(query, viewGenerator, docRetriever,
+ from queryResult in indexQueryResults
+ let doc = docRetriever.RetrieveDocumentForQuery(queryResult, indexDefinition, fieldsToFetch)
+ where doc != null
+ let _ = nonAuthoritativeInformation |= (doc.NonAuthoritativeInformation ?? false)
+ let __ = tryRecordHighlighting(queryResult)
+ select doc, transformerErrors, cancellationToken);
+
+ if (headerInfo != null)
+ {
+ headerInfo(new QueryHeaderInformation
+ {
+ Index = index,
+ IsStable = stale,
+ ResultEtag = resultEtag,
+ IndexTimestamp = indexTimestamp.Item1,
+ IndexEtag = indexTimestamp.Item2,
+ TotalResults = query.TotalSize.Value
+ });
+ }
+ using (new CurrentTransformationScope(docRetriever))
+ {
+ foreach (var result in results)
+ {
+ cancellationToken.ThrowIfCancellationRequested();
+ onResult(result);
+ }
+ if (transformerErrors.Count > 0)
+ {
+ throw new InvalidOperationException("The transform results function failed.\r\n" + string.Join("\r\n", transformerErrors));
+ }
- }
+ }
- });
+ });
- return new QueryResultWithIncludes
- {
- IndexName = index,
- IsStale = stale,
- NonAuthoritativeInformation = nonAuthoritativeInformation,
- SkippedResults = query.SkippedResults.Value,
- TotalResults = query.TotalSize.Value,
- IndexTimestamp = indexTimestamp.Item1,
- IndexEtag = indexTimestamp.Item2,
- ResultEtag = resultEtag,
- IdsToInclude = idsToLoad,
- LastQueryTime = SystemTime.UtcNow,
- Highlightings = highlightings,
- DurationMilliseconds = duration.ElapsedMilliseconds
- };
- }
- finally
- {
- RemoveFromCurrentlyRunningQueryList(index, queryStat);
- }
+ return new QueryResultWithIncludes
+ {
+ IndexName = index,
+ IsStale = stale,
+ NonAuthoritativeInformation = nonAuthoritativeInformation,
+ SkippedResults = query.SkippedResults.Value,
+ TotalResults = query.TotalSize.Value,
+ IndexTimestamp = indexTimestamp.Item1,
+ IndexEtag = indexTimestamp.Item2,
+ ResultEtag = resultEtag,
+ IdsToInclude = idsToLoad,
+ LastQueryTime = SystemTime.UtcNow,
+ Highlightings = highlightings,
+ DurationMilliseconds = duration.ElapsedMilliseconds
+ };
+ }
+ finally
+ {
+ RemoveFromCurrentlyRunningQueryList(index, queryStat);
+ }
+ }
}
private void RemoveFromCurrentlyRunningQueryList(string index, ExecutingQueryInfo queryStat)
@@ -1416,7 +1421,8 @@ private ExecutingQueryInfo AddToCurrentlyRunningQueryList(string index, IndexQue
AbstractViewGenerator viewGenerator,
DocumentRetriever docRetriever,
IEnumerable<JsonDocument> results,
- List<string> transformerErrors)
+ List<string> transformerErrors,
+ CancellationToken token)
{
if (query.PageSize <= 0) // maybe they just want the stats?
{
@@ -1444,7 +1450,7 @@ private ExecutingQueryInfo AddToCurrentlyRunningQueryList(string index, IndexQue
return results.Select(x => x.ToJson());
var dynamicJsonObjects = results.Select(x => new DynamicLuceneOrParentDocumntObject(docRetriever, x.ToJson()));
- var robustEnumerator = new RobustEnumerator(workContext.CancellationToken, 100)
+ var robustEnumerator = new RobustEnumerator(token, 100)
{
OnError =
(exception, o) =>
@@ -1457,7 +1463,7 @@ private ExecutingQueryInfo AddToCurrentlyRunningQueryList(string index, IndexQue
.Select(JsonExtensions.ToJObject);
}
- public IEnumerable<string> QueryDocumentIds(string index, IndexQuery query, out bool stale)
+ public IEnumerable<string> QueryDocumentIds(string index, IndexQuery query, CancellationToken token, out bool stale)
{
var queryStat = AddToCurrentlyRunningQueryList(index,query);
try
@@ -1481,7 +1487,7 @@ public IEnumerable<string> QueryDocumentIds(string index, IndexQuery query, out
{
throw new IndexDisabledException(indexFailureInformation);
}
- loadedIds = new HashSet<string>(from queryResult in IndexStorage.Query(index, query, result => true, new FieldsToFetch(null, AggregationOperation.None, Constants.DocumentIdFieldName), IndexQueryTriggers)
+ loadedIds = new HashSet<string>(from queryResult in IndexStorage.Query(index, query, result => true, new FieldsToFetch(null, AggregationOperation.None, Constants.DocumentIdFieldName), IndexQueryTriggers, token)
select queryResult.Key);
});
stale = isStale;
View
58 Raven.Database/Extensions/CancellationTokenSource.cs
@@ -0,0 +1,58 @@
+// -----------------------------------------------------------------------
+// <copyright file="CancellationTokenSource.cs" company="Hibernating Rhinos LTD">
+// Copyright (c) Hibernating Rhinos LTD. All rights reserved.
+// </copyright>
+// -----------------------------------------------------------------------
+using System;
+using System.Threading;
+
+namespace Raven.Database.Extensions
+{
+ public static class CancellationTokenSourceExtensions
+ {
+ public static CancellationTimeout TimeoutAfter(this CancellationTokenSource cts, TimeSpan dueTime)
+ {
+ return new CancellationTimeout(cts, dueTime);
+ }
+
+ public class CancellationTimeout : IDisposable
+ {
+ private readonly CancellationTokenSource source;
+ private readonly Timer timer;
+ private readonly long dueTime;
+
+ public CancellationTimeout(CancellationTokenSource source, TimeSpan dueTime)
+ {
+ if (source == null)
+ throw new ArgumentNullException("source");
+ if (dueTime < TimeSpan.Zero)
+ throw new ArgumentOutOfRangeException("dueTime");
+
+ this.source = source;
+ this.dueTime = (long) dueTime.TotalMilliseconds;
+ timer = new Timer(self =>
+ {
+ timer.Dispose();
+ try
+ {
+ this.source.Cancel();
+ }
+ catch (ObjectDisposedException)
+ {
+ }
+ }, null, this.dueTime, -1);
+ }
+
+ public void Delay()
+ {
+ timer.Change(dueTime,-1);
+ }
+
+ public void Dispose()
+ {
+ timer.Dispose();
+ }
+ }
+
+ }
+}
View
12 Raven.Database/Impl/DatabaseBulkOperations.cs
@@ -4,6 +4,8 @@
// </copyright>
//-----------------------------------------------------------------------
using System;
+using System.Threading;
+using Raven.Database.Extensions;
using Raven.Imports.Newtonsoft.Json;
using Raven.Imports.Newtonsoft.Json.Linq;
using Raven.Abstractions.Data;
@@ -19,11 +21,15 @@ public class DatabaseBulkOperations
{
private readonly DocumentDatabase database;
private readonly TransactionInformation transactionInformation;
+ private readonly CancellationToken token;
+ private readonly CancellationTokenSourceExtensions.CancellationTimeout timeout;
- public DatabaseBulkOperations(DocumentDatabase database, TransactionInformation transactionInformation)
+ public DatabaseBulkOperations(DocumentDatabase database, TransactionInformation transactionInformation, CancellationToken token, CancellationTokenSourceExtensions.CancellationTimeout timeout)
{
this.database = database;
this.transactionInformation = transactionInformation;
+ this.token = token;
+ this.timeout = timeout;
}
public RavenJArray DeleteByIndex(string indexName, IndexQuery queryToDelete, bool allowStale)
@@ -70,7 +76,7 @@ private RavenJArray PerformBulkOperation(string index, IndexQuery indexQuery, bo
};
bool stale;
- var queryResults = database.QueryDocumentIds(index, bulkIndexQuery, out stale);
+ var queryResults = database.QueryDocumentIds(index, bulkIndexQuery, token, out stale);
if (stale && allowStale == false)
{
@@ -83,6 +89,8 @@ private RavenJArray PerformBulkOperation(string index, IndexQuery indexQuery, bo
{
while (true)
{
+ if (timeout != null)
+ timeout.Delay();
var batchCount = 0;
database.TransactionalStorage.Batch(actions =>
{
View
6 Raven.Database/Indexing/Index.cs
@@ -925,7 +925,7 @@ public IEnumerable<RavenJObject> IndexEntries(Reference<int> totalResults)
}
}
- public IEnumerable<IndexQueryResult> Query()
+ public IEnumerable<IndexQueryResult> Query(CancellationToken token)
{
parent.MarkQueried();
using (IndexStorage.EnsureInvariantCulture())
@@ -965,6 +965,7 @@ public IEnumerable<IndexQueryResult> Query()
int moreRequired;
do
{
+ token.ThrowIfCancellationRequested();
search = ExecuteQuery(indexSearcher, luceneQuery, start, pageSize, indexQuery);
moreRequired = recorder.RecordResultsAlreadySeenForDistinctQuery(search, adjustStart, pageSize, ref start);
pageSize += moreRequired * 2;
@@ -1067,7 +1068,7 @@ private Query ApplyIndexTriggers(Query luceneQuery)
return luceneQuery;
}
- public IEnumerable<IndexQueryResult> IntersectionQuery()
+ public IEnumerable<IndexQueryResult> IntersectionQuery(CancellationToken token)
{
using (IndexStorage.EnsureInvariantCulture())
{
@@ -1094,6 +1095,7 @@ public IEnumerable<IndexQueryResult> IntersectionQuery()
do
{
+ token.ThrowIfCancellationRequested();
if (skippedResultsInCurrentLoop > 0)
{
// We get here because out first attempt didn't get enough docs (after INTERSECTION was calculated)
View
11 Raven.Database/Indexing/IndexStorage.cs
@@ -740,12 +740,7 @@ public Query GetLuceneQuery(string index, IndexQuery query, OrderedPartCollectio
return new Index.IndexQueryOperation(value, query, _ => false, fieldsToFetch, indexQueryTriggers).GetLuceneQuery();
}
- public IEnumerable<IndexQueryResult> Query(
- string index,
- IndexQuery query,
- Func<IndexQueryResult, bool> shouldIncludeInResults,
- FieldsToFetch fieldsToFetch,
- OrderedPartCollection<AbstractIndexQueryTrigger> indexQueryTriggers)
+ public IEnumerable<IndexQueryResult> Query(string index, IndexQuery query, Func<IndexQueryResult, bool> shouldIncludeInResults, FieldsToFetch fieldsToFetch, OrderedPartCollection<AbstractIndexQueryTrigger> indexQueryTriggers, CancellationToken token)
{
Index value;
if (indexes.TryGetValue(index, out value) == false)
@@ -782,10 +777,10 @@ public Query GetLuceneQuery(string index, IndexQuery query, OrderedPartCollectio
var indexQueryOperation = new Index.IndexQueryOperation(value, query, shouldIncludeInResults, fieldsToFetch, indexQueryTriggers);
if (query.Query != null && query.Query.Contains(Constants.IntersectSeparator))
- return indexQueryOperation.IntersectionQuery();
+ return indexQueryOperation.IntersectionQuery(token);
- return indexQueryOperation.Query();
+ return indexQueryOperation.Query(token);
}
public IEnumerable<RavenJObject> IndexEntires(
View
5 Raven.Database/Queries/DynamicQueryExtensions.cs
@@ -5,6 +5,7 @@
//-----------------------------------------------------------------------
using System.Collections.Generic;
+using System.Threading;
using Raven.Abstractions.Data;
using Raven.Database.Data;
using Raven.Abstractions.Extensions;
@@ -13,10 +14,10 @@ namespace Raven.Database.Queries
{
public static class DynamicQueryExtensions
{
- public static QueryResultWithIncludes ExecuteDynamicQuery(this DocumentDatabase self, string entityName, IndexQuery indexQuery)
+ public static QueryResultWithIncludes ExecuteDynamicQuery(this DocumentDatabase self, string entityName, IndexQuery indexQuery, CancellationToken token)
{
var dynamicQueryRunner = (DynamicQueryRunner)self.ExtensionsState.GetOrAdd(typeof(DynamicQueryExtensions).AssemblyQualifiedName, o => new DynamicQueryRunner(self));
- return dynamicQueryRunner.ExecuteDynamicQuery(entityName, indexQuery);
+ return dynamicQueryRunner.ExecuteDynamicQuery(entityName, indexQuery, token);
}
public static string FindDynamicIndexName(this DocumentDatabase self, string entityName, IndexQuery query)
View
8 Raven.Database/Queries/DynamicQueryRunner.cs
@@ -25,7 +25,7 @@ public DynamicQueryRunner(DocumentDatabase database)
documentDatabase = database;
}
- public QueryResultWithIncludes ExecuteDynamicQuery(string entityName, IndexQuery query)
+ public QueryResultWithIncludes ExecuteDynamicQuery(string entityName, IndexQuery query, CancellationToken token)
{
// Create the map
var map = DynamicQueryMapping.Create(documentDatabase, query, entityName);
@@ -41,7 +41,7 @@ public QueryResultWithIncludes ExecuteDynamicQuery(string entityName, IndexQuery
UpdateFieldsInArray(map, query.GroupBy);
- return ExecuteActualQuery(query, map, touchTemporaryIndexResult, realQuery);
+ return ExecuteActualQuery(query, map, touchTemporaryIndexResult, realQuery, token);
}
private static void UpdateFieldNamesForSortedFields(IndexQuery query, DynamicQueryMapping map)
@@ -67,7 +67,7 @@ private static void UpdateFieldsInArray(DynamicQueryMapping map, string[] fields
}
}
- private QueryResultWithIncludes ExecuteActualQuery(IndexQuery query, DynamicQueryMapping map, Tuple<string, bool> touchTemporaryIndexResult, string realQuery)
+ private QueryResultWithIncludes ExecuteActualQuery(IndexQuery query, DynamicQueryMapping map, Tuple<string, bool> touchTemporaryIndexResult, string realQuery, CancellationToken token)
{
// Perform the query until we have some results at least
QueryResultWithIncludes result;
@@ -75,7 +75,7 @@ private QueryResultWithIncludes ExecuteActualQuery(IndexQuery query, DynamicQuer
while (true)
{
var indexQuery = CreateIndexQuery(query, map, realQuery);
- result = documentDatabase.Query(map.IndexName, indexQuery);
+ result = documentDatabase.Query(map.IndexName, indexQuery, token);
if (!touchTemporaryIndexResult.Item2 ||
!result.IsStale ||
View
1  Raven.Database/Raven.Database.csproj
@@ -204,6 +204,7 @@
<Compile Include="Bundles\SqlReplication\RelationalDatabaseWriter.cs" />
<Compile Include="Bundles\SqlReplication\SqlReplicationScriptedJsonPatcher.cs" />
<Compile Include="Bundles\SqlReplication\SqlReplicationStatistics.cs" />
+ <Compile Include="Extensions\CancellationTokenSource.cs" />
<Compile Include="Impl\DTC\EsentInFlightTransactionalState.cs" />
<Compile Include="Impl\DTC\EsentTransactionContext.cs" />
<Compile Include="Impl\DTC\MuninInFlightTransactionalState.cs" />
View
4 Raven.Database/Server/HttpServer.cs
@@ -201,7 +201,7 @@ private void TenantDatabaseRemoved(object sender, TenantDatabaseModified.Event @
if (@event.Database != SystemDatabase)
return; // we ignore anything that isn't from the root db
- logger.Info("Shutting down database {0} because the tenant database has been removed", @event.Name);
+ logger.Info("Shutting down database {0} because the tenant database has been updated or removed", @event.Name);
CleanupDatabase(@event.Name, skipIfActive: false);
}
@@ -330,7 +330,7 @@ public void Dispose()
try
{
- logger.Info("Delyaed shut down database {0} because we are shutting down the server", task.Result.Name);
+ logger.Info("Delayed shut down database {0} because we are shutting down the server", task.Result.Name);
task.Result.Dispose();
}
catch (Exception e)
View
47 Raven.Database/Server/Responders/DocumentBatch.cs
@@ -8,6 +8,7 @@
using System.Diagnostics;
using System.Linq;
using System.Text;
+using System.Threading;
using System.Threading.Tasks;
using Raven.Abstractions.Data;
using Raven.Abstractions.Logging;
@@ -34,27 +35,31 @@ public override string[] SupportedVerbs
public override void Respond(IHttpContext context)
{
- var databaseBulkOperations = new DatabaseBulkOperations(Database, GetRequestTransaction(context));
- switch (context.Request.HttpMethod)
- {
- case "POST":
- Batch(context);
- break;
- case "DELETE":
- OnBulkOperation(context, databaseBulkOperations.DeleteByIndex);
- break;
- case "PATCH":
- var patchRequestJson = context.ReadJsonArray();
- var patchRequests = patchRequestJson.Cast<RavenJObject>().Select(PatchRequest.FromJson).ToArray();
- OnBulkOperation(context, (index, query, allowStale) =>
- databaseBulkOperations.UpdateByIndex(index, query, patchRequests, allowStale));
- break;
- case "EVAL":
- var advPatchRequestJson = context.ReadJsonObject<RavenJObject>();
- var advPatch = ScriptedPatchRequest.FromJson(advPatchRequestJson);
- OnBulkOperation(context, (index, query, allowStale) =>
- databaseBulkOperations.UpdateByIndex(index, query, advPatch, allowStale));
- break;
+ using (var cts = new CancellationTokenSource())
+ {
+ var timeout = cts.TimeoutAfter(Settings.DatbaseOperationTimeout);
+ var databaseBulkOperations = new DatabaseBulkOperations(Database, GetRequestTransaction(context), cts.Token, timeout);
+ switch (context.Request.HttpMethod)
+ {
+ case "POST":
+ Batch(context);
+ break;
+ case "DELETE":
+ OnBulkOperation(context, databaseBulkOperations.DeleteByIndex);
+ break;
+ case "PATCH":
+ var patchRequestJson = context.ReadJsonArray();
+ var patchRequests = patchRequestJson.Cast<RavenJObject>().Select(PatchRequest.FromJson).ToArray();
+ OnBulkOperation(context, (index, query, allowStale) =>
+ databaseBulkOperations.UpdateByIndex(index, query, patchRequests, allowStale));
+ break;
+ case "EVAL":
+ var advPatchRequestJson = context.ReadJsonObject<RavenJObject>();
+ var advPatch = ScriptedPatchRequest.FromJson(advPatchRequestJson);
+ OnBulkOperation(context, (index, query, allowStale) =>
+ databaseBulkOperations.UpdateByIndex(index, query, advPatch, allowStale));
+ break;
+ }
}
}
View
25 Raven.Database/Server/Responders/Index.cs
@@ -9,6 +9,7 @@
using System.Globalization;
using System.Text;
using System.Text.RegularExpressions;
+using System.Threading;
using Raven.Abstractions;
using Raven.Abstractions.Data;
using Raven.Abstractions.Exceptions;
@@ -445,9 +446,13 @@ private void GetIndexReducedResult(IHttpContext context, string index)
private void GetIndexQueryResult(IHttpContext context, string index)
{
Etag indexEtag;
- var queryResult = ExecuteQuery(context, index, out indexEtag);
-
- if (queryResult == null)
+ QueryResultWithIncludes queryResult;
+ using (var cts = new CancellationTokenSource())
+ {
+ cts.TimeoutAfter(Settings.DatbaseOperationTimeout);
+ queryResult = ExecuteQuery(context, index, cts.Token, out indexEtag);
+ }
+ if (queryResult == null)
return;
var includes = context.Request.QueryString.GetValues("include") ?? new string[0];
@@ -501,15 +506,15 @@ private void GetIndexSource(IHttpContext context, string index)
context.Write(viewGenerator.SourceCode);
}
- private QueryResultWithIncludes ExecuteQuery(IHttpContext context, string index, out Etag indexEtag)
+ private QueryResultWithIncludes ExecuteQuery(IHttpContext context, string index, CancellationToken token, out Etag indexEtag)
{
var indexQuery = context.GetIndexQueryFromHttpContext(Database.Configuration.MaxPageSize);
RewriteDateQueriesFromOldClients(context, indexQuery);
var sp = Stopwatch.StartNew();
var result = index.StartsWith("dynamic/", StringComparison.OrdinalIgnoreCase) || index.Equals("dynamic", StringComparison.OrdinalIgnoreCase) ?
- PerformQueryAgainstDynamicIndex(context, index, indexQuery, out indexEtag) :
- PerformQueryAgainstExistingIndex(context, index, indexQuery, out indexEtag);
+ PerformQueryAgainstDynamicIndex(context, index, indexQuery, token, out indexEtag) :
+ PerformQueryAgainstExistingIndex(context, index, indexQuery, token, out indexEtag);
sp.Stop();
@@ -560,7 +565,7 @@ private void RewriteDateQueriesFromOldClients(IHttpContext context, IndexQuery i
indexQuery.Query = builder.ToString();
}
- private QueryResultWithIncludes PerformQueryAgainstExistingIndex(IHttpContext context, string index, IndexQuery indexQuery, out Etag indexEtag)
+ private QueryResultWithIncludes PerformQueryAgainstExistingIndex(IHttpContext context, string index, IndexQuery indexQuery, CancellationToken token, out Etag indexEtag)
{
indexEtag = Database.GetIndexEtag(index, null, indexQuery.ResultsTransformer);
if (context.MatchEtag(indexEtag))
@@ -570,12 +575,12 @@ private QueryResultWithIncludes PerformQueryAgainstExistingIndex(IHttpContext co
return null;
}
- var queryResult = Database.Query(index, indexQuery);
+ var queryResult = Database.Query(index, indexQuery, token);
indexEtag = Database.GetIndexEtag(index, queryResult.ResultEtag, indexQuery.ResultsTransformer);
return queryResult;
}
- private QueryResultWithIncludes PerformQueryAgainstDynamicIndex(IHttpContext context, string index, IndexQuery indexQuery, out Etag indexEtag)
+ private QueryResultWithIncludes PerformQueryAgainstDynamicIndex(IHttpContext context, string index, IndexQuery indexQuery, CancellationToken token, out Etag indexEtag)
{
string entityName;
var dynamicIndexName = GetDynamicIndexName(index, indexQuery, out entityName);
@@ -606,7 +611,7 @@ private QueryResultWithIncludes PerformQueryAgainstDynamicIndex(IHttpContext con
return null;
}
- var queryResult = Database.ExecuteDynamicQuery(entityName, indexQuery);
+ var queryResult = Database.ExecuteDynamicQuery(entityName, indexQuery, token);
// have to check here because we might be getting the index etag just
// as we make a switch from temp to auto, and we need to refresh the etag
View
15 Raven.Database/Server/Responders/QueryStreams.cs
@@ -10,6 +10,7 @@
using System.IO;
using System.Linq;
using System.Text;
+using System.Threading;
using Raven.Abstractions;
using Raven.Abstractions.Util;
using Raven.Database.Extensions;
@@ -55,8 +56,10 @@ public override void Respond(IHttpContext context)
// of them aren't going to be relevant for other ops, so we are going to skip
// the cache for that, to avoid filling it up very quickly
using (DocumentCacher.SkipSettingDocumentsInDocumentCache())
+ using (var cts = new CancellationTokenSource())
{
- Database.Query(index, query, information =>
+ var timeout = cts.TimeoutAfter(Settings.DatbaseOperationTimeout);
+ Database.Query(index, query, cts.Token, information =>
{
context.Response.AddHeader("Raven-Result-Etag", information.ResultEtag.ToString());
context.Response.AddHeader("Raven-Index-Etag", information.IndexEtag.ToString());
@@ -64,13 +67,17 @@ public override void Respond(IHttpContext context)
context.Response.AddHeader("Raven-Index", information.Index);
context.Response.AddHeader("Raven-Total-Results", information.TotalResults.ToString(CultureInfo.InvariantCulture));
context.Response.AddHeader("Raven-Index-Timestamp",
- information.IndexTimestamp.ToString(Default.DateTimeFormatsToWrite,
- CultureInfo.InvariantCulture));
+ information.IndexTimestamp.ToString(Default.DateTimeFormatsToWrite,
+ CultureInfo.InvariantCulture));
if (isHeadRequest)
return;
writer.WriteHeader();
- }, writer.Write);
+ }, o =>
+ {
+ timeout.Delay();
+ writer.Write(o);
+ });
}
}
}
View
3  Raven.Tests/Bugs/HierarchicalData.cs
@@ -3,6 +3,7 @@
// Copyright (c) Hibernating Rhinos LTD. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
+using System.Threading;
using Raven.Abstractions.Data;
using Raven.Abstractions.Indexing;
using Raven.Client.Embedded;
@@ -57,7 +58,7 @@ public void CanCreateHierarchicalIndexes()
queryResult = db.Query("test", new IndexQuery
{
Query = "Text:abc"
- });
+ }, CancellationToken.None);
} while (queryResult.IsStale);
Assert.Equal(1, queryResult.Results.Count);
View
4 Raven.Tests/Bugs/IndexingBehavior.cs
@@ -103,7 +103,7 @@ public void AfterEnoughFailuresIndexWillBeDisabled()
Assert.Throws<IndexDisabledException>(() =>
{
- var queryResult = db.Query("test", new IndexQuery { Query = "User:Ayende" });
+ var queryResult = db.Query("test", new IndexQuery { Query = "User:Ayende" }, CancellationToken.None);
});
}
@@ -131,7 +131,7 @@ public void AfterDeletingAndStoringTheDocumentIsIndexed()
{
Query = "Tag:[[Foos]]",
PageSize = 10
- });
+ }, CancellationToken.None);
} while (queryResult.IsStale);
Assert.Equal(1, queryResult.TotalResults);
View
4 Raven.Tests/Indexes/CompiledIndex.cs
@@ -54,7 +54,7 @@ public void CanGetDataFromCompiledIndex()
queryResult = db.Query("Compiled/View", new IndexQuery
{
Query = "CustomerId:users/ayende"
- });
+ }, CancellationToken.None);
if (queryResult.IsStale)
Thread.Sleep(100);
} while (queryResult.IsStale);
@@ -126,7 +126,7 @@ public void CompileIndexWillTurnEventsToAggregate()
QueryResult queryResult = null;
for (int i = 0; i < 500; i++)
{
- queryResult = db.Query("Aggregates/ShoppingCart", new IndexQuery());
+ queryResult = db.Query("Aggregates/ShoppingCart", new IndexQuery(), CancellationToken.None);
if (queryResult.IsStale)
Thread.Sleep(100);
else
View
3  Raven.Tests/Indexes/ComplexIndexOnNotAnalyzedField.cs
@@ -3,6 +3,7 @@
// Copyright (c) Hibernating Rhinos LTD. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
+using System.Threading;
using Raven.Abstractions.Data;
using Raven.Abstractions.Indexing;
using Raven.Client.Embedded;
@@ -52,7 +53,7 @@ public void CanQueryOnKey()
{
Query = "Partner:companies/49",
PageSize = 10
- });
+ }, CancellationToken.None);
} while (queryResult.IsStale);
Assert.Equal("Hibernating Rhinos", queryResult.Results[0].Value<string>("Name"));
View
20 Raven.Tests/Indexes/DocumentsToIndex.cs
@@ -68,7 +68,7 @@ public void Can_Read_values_from_index()
Query = "some:val",
Start = 0,
PageSize = 10
- });
+ }, CancellationToken.None);
if (docs.IsStale)
Thread.Sleep(100);
} while (docs.IsStale);
@@ -99,7 +99,7 @@ public void Can_update_values_in_index_with_where_clause()
{
Start = 0,
PageSize = 10
- });
+ }, CancellationToken.None);
if (docs.IsStale)
Thread.Sleep(100);
} while (docs.IsStale);
@@ -116,7 +116,7 @@ public void Can_update_values_in_index_with_where_clause()
{
Start = 0,
PageSize = 10
- });
+ }, CancellationToken.None);
if (docs.IsStale)
Thread.Sleep(100);
} while (docs.IsStale);
@@ -149,7 +149,7 @@ public void Can_Read_Values_Using_Deep_Nesting()
Query = "project_name:raven",
Start = 0,
PageSize = 10
- });
+ }, CancellationToken.None);
if (docs.IsStale)
Thread.Sleep(100);
} while (docs.IsStale);
@@ -183,7 +183,7 @@ public void Can_Read_Values_Using_MultipleValues_From_Deep_Nesting()
Query = "+project_name:raven +project_num:6",
Start = 0,
PageSize = 10
- });
+ }, CancellationToken.None);
if (docs.IsStale)
Thread.Sleep(100);
} while (docs.IsStale);
@@ -225,7 +225,7 @@ public void Can_Read_values_when_two_indexes_exist()
Query = "some:val",
Start = 0,
PageSize = 10
- });
+ }, CancellationToken.None);
if (docs.IsStale)
Thread.Sleep(100);
} while (docs.IsStale);
@@ -267,7 +267,7 @@ public void Updating_an_index_will_result_in_new_values()
Query = "other:var",
Start = 0,
PageSize = 10
- });
+ }, CancellationToken.None);
if (docs.IsStale)
Thread.Sleep(100);
} while (docs.IsStale);
@@ -299,7 +299,7 @@ public void Can_read_values_from_index_of_documents_already_in_db()
Query = "other:var",
Start = 0,
PageSize = 10
- });
+ }, CancellationToken.None);
if (docs.IsStale)
Thread.Sleep(100);
} while (docs.IsStale);
@@ -335,7 +335,7 @@ public void Can_read_values_from_indexes_of_documents_already_in_db_when_multipl
Query = "other:var",
Start = 0,
PageSize = 10
- });
+ }, CancellationToken.None);
if (docs.IsStale)
Thread.Sleep(100);
} while (docs.IsStale);
@@ -368,7 +368,7 @@ public void Can_query_by_stop_words()
Query = "Region:[[A]]",
Start = 0,
PageSize = 10
- });
+ }, CancellationToken.None);
if (docs.IsStale)
Thread.Sleep(100);
} while (docs.IsStale);
View
9 Raven.Tests/Indexes/QueryingOnDefaultIndex.cs
@@ -3,6 +3,7 @@
// Copyright (c) Hibernating Rhinos LTD. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
+using System.Threading;
using Raven.Abstractions.Data;
using Raven.Client.Embedded;
using Raven.Json.Linq;
@@ -45,7 +46,7 @@ public void CanQueryOverDefaultIndex()
{
Query = "Tag:[[Users]]",
PageSize = 10
- });
+ }, CancellationToken.None);
} while (queryResult.IsStale);
Assert.Equal("ayende@ayende.com", queryResult.Results[0].Value<string>("email"));
@@ -73,7 +74,7 @@ public void CanPageOverDefaultIndex()
Start = 0,
PageSize = 2,
SortedFields = new [] { new SortedField("__document_id"), }
- });
+ }, CancellationToken.None);
} while (queryResultPageOne.IsStale);
do
{
@@ -83,7 +84,7 @@ public void CanPageOverDefaultIndex()
Start = 1,
PageSize = 2,
SortedFields = new [] { new SortedField("__document_id"), }
- });
+ }, CancellationToken.None);
} while (queryResultPageTwo.IsStale);
do
@@ -94,7 +95,7 @@ public void CanPageOverDefaultIndex()
Start = 2,
PageSize = 2,
SortedFields = new []{new SortedField("__document_id"), }
- });
+ }, CancellationToken.None);
} while (queryResultPageThree.IsStale);
// Page one
View
10 Raven.Tests/Indexes/QueryingOnStaleIndexes.cs
@@ -43,7 +43,7 @@ public void WillGetStaleResultWhenThereArePendingTasks()
{
PageSize = 2,
Start = 0,
- }).IsStale);
+ }, CancellationToken.None).IsStale);
}
[Fact]
@@ -57,7 +57,7 @@ public void WillGetNonStaleResultWhenAskingWithCutoffDate()
{
PageSize = 2,
Start = 0,
- });
+ }, CancellationToken.None);
if (queryResult.IsStale == false)
break;
Thread.Sleep(100);
@@ -67,7 +67,7 @@ public void WillGetNonStaleResultWhenAskingWithCutoffDate()
{
PageSize = 2,
Start = 0,
- }).IsStale);
+ }, CancellationToken.None).IsStale);
db.StopBackgroundWorkers();
@@ -78,14 +78,14 @@ public void WillGetNonStaleResultWhenAskingWithCutoffDate()
{
PageSize = 2,
Start = 0,
- }).IsStale);
+ }, CancellationToken.None).IsStale);
Assert.False(db.Query("Raven/DocumentsByEntityName", new IndexQuery
{
PageSize = 2,
Start = 0,
Cutoff = SystemTime.UtcNow.AddHours(-1)
- }).IsStale);
+ }, CancellationToken.None).IsStale);
}
}
View
6 Raven.Tests/Indexes/Statistics.cs
@@ -76,7 +76,7 @@ public void Can_get_stats_for_indexing()
Query = "f:val",
Start = 0,
PageSize = 10
- });
+ }, CancellationToken.None);
if (docs.IsStale)
Thread.Sleep(100);
} while (docs.IsStale);
@@ -123,7 +123,7 @@ public void Can_get_stats_for_indexing_including_errors()
Query = "f:val",
Start = 0,
PageSize = 10
- });
+ }, CancellationToken.None);
if (docs.IsStale)
Thread.Sleep(100);
} while (docs.IsStale);
@@ -159,7 +159,7 @@ public void Can_get_details_about_indexing_errors()
Query = "f:val",
Start = 0,
PageSize = 10
- });
+ }, CancellationToken.None);
if (docs.IsStale)
Thread.Sleep(100);
} while (docs.IsStale);
View
5 Raven.Tests/Issues/RavenDB_1007.cs
@@ -6,6 +6,7 @@
using System.IO;
using System.Linq;
using System.Text;
+using System.Threading;
using Raven.Abstractions.Data;
using Raven.Client.Indexes;
using Raven.Database;
@@ -86,7 +87,7 @@ public void AfterFailedRestoreOfIndex_ShouldGenerateWarningAndResetIt()
{
Query = "Tag:[[Users]]",
PageSize = 10
- });
+ }, CancellationToken.None);
} while (queryResult.IsStale);
Assert.Equal(3, queryResult.Results.Count);
}
@@ -151,7 +152,7 @@ public void AfterFailedRestoreOfIndex_ShouldGenerateWarningAndResetIt()
{
Query = "Tag:[[Users]]",
PageSize = 10
- });
+ }, CancellationToken.None);
} while (queryResult.IsStale);
Assert.Equal(3, queryResult.Results.Count);
}
View
4 Raven.Tests/Issues/RavenDB_1497.cs
@@ -130,7 +130,7 @@ public void AfterRestoreOfIncrementalBackupAllIndexesShouldWork()
Query = "Name:*",
Start = 0,
PageSize = 10
- });
+ }, CancellationToken.None);
Assert.Equal(2, docs.Results.Count);
@@ -139,7 +139,7 @@ public void AfterRestoreOfIncrementalBackupAllIndexesShouldWork()
Query = "Name:*",
Start = 0,
PageSize = 10
- });
+ }, CancellationToken.None);
Assert.Equal(2, docs.Results.Count);
View
4 Raven.Tests/Issues/RavenDB_1600.cs
@@ -3,6 +3,8 @@
// Copyright (c) Hibernating Rhinos LTD. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
+using System.Threading;
+
namespace Raven.Tests.Issues
{
using System;
@@ -63,7 +65,7 @@ public void ShouldNotSetAutoIndexesToAbandonedPriorityAfterDatabaseRecovery()
Start = 0,
Cutoff = SystemTime.UtcNow,
Query = "Name:Arek"
- });
+ }, CancellationToken.None);
WaitForIndexing(db);
View
3  Raven.Tests/MailingList/FailingBulkInsertTest.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
+using System.Threading;
using System.Threading.Tasks;
using Raven.Abstractions.Data;
using Raven.Client.Embedded;
@@ -124,7 +125,7 @@ public void CanBulkInsert_LowLevel()
WaitForIndexing(store);
- var queryResultWithIncludes = store.DocumentDatabase.Query("Raven/DocumentsByEntityName", new IndexQuery());
+ var queryResultWithIncludes = store.DocumentDatabase.Query("Raven/DocumentsByEntityName", new IndexQuery(), CancellationToken.None);
Assert.Equal(12, queryResultWithIncludes.TotalResults);
}
View
19 Raven.Tests/Queries/ParameterizedDynamicQuery.cs
@@ -4,6 +4,7 @@
// </copyright>
//-----------------------------------------------------------------------
using System.Linq;
+using System.Threading;
using Raven.Abstractions;
using Raven.Abstractions.Data;
using Raven.Client.Embedded;
@@ -62,7 +63,7 @@ public void CanPerformDynamicQueryAndGetValidResults()
Start = 0,
Cutoff = SystemTime.UtcNow,
Query = "Title.Length:3 AND Category:Rhinos"
- });
+ }, CancellationToken.None);
Assert.Equal(1, results.Results.Count);
Assert.Equal("two", results.Results[0].Value<string>("Title"));
@@ -99,21 +100,21 @@ public void SimpleQueriesDoNotGeneratedMultipleIndexes()
Start = 0,
Cutoff = SystemTime.UtcNow,
Query = "Title.Length:3 AND Category:Rhinos"
- });
+ }, CancellationToken.None);
db.ExecuteDynamicQuery(null, new IndexQuery()
{
PageSize = 128,
Start = 0,
Cutoff = SystemTime.UtcNow,
Query = "Title.Length:3 AND Category:Rhinos"
- });
+ }, CancellationToken.None);
db.ExecuteDynamicQuery(null, new IndexQuery()
{
PageSize = 128,
Start = 0,
Cutoff = SystemTime.UtcNow,
Query = "Category:Rhinos AND Title.Length:3"
- });
+ }, CancellationToken.None);
Assert.True(db.Statistics.CountOfIndexes == initialIndexCount + 1);
@@ -131,7 +132,7 @@ public void SingleInvokedQueryShouldCreateAutoIndex()
Start = 0,
Cutoff = SystemTime.UtcNow,
Query = "Title.Length:3 AND Category:Rhinos"
- });
+ }, CancellationToken.None);
var autoIndexName = db.IndexDefinitionStorage.IndexNames.Where(x => x.StartsWith("Auto")).SingleOrDefault();
@@ -169,7 +170,7 @@ public void LengthPropertySupportsRangedQueries()
Start = 0,
Cutoff = SystemTime.UtcNow,
Query = "Title.Length_Range:[0x00000004 TO 0x00000009]"
- });
+ }, CancellationToken.None);
Assert.Equal(1, results.TotalResults);
}
@@ -212,7 +213,7 @@ public void NestedCollectionPropertiesCanBeQueried()
Start = 0,
Cutoff = SystemTime.UtcNow,
Query = "Tags,Name:[[birds]]"
- });
+ }, CancellationToken.None);
Assert.Equal(1, results.Results.Count);
Assert.Equal("one", results.Results[0].Value<string>("Title"));
@@ -251,7 +252,7 @@ public void NestedPropertiesCanBeQueried()
Start = 0,
Cutoff = SystemTime.UtcNow,
Query = "User.Name:rob"
- });
+ }, CancellationToken.None);
Assert.Equal(1, results.Results.Count);
Assert.Equal("three", results.Results[0].Value<string>("Title"));
@@ -279,7 +280,7 @@ public void NestedCollectionPropertiesCanBeQueriedWithProjection()
Cutoff = SystemTime.UtcNow,
Query = "Tags,Name:[[birds]]",
FieldsToFetch = new string[] { "Title", "Category" }
- });
+ }, CancellationToken.None);
Assert.Equal(1, results.Results.Count);
Assert.Equal("one", results.Results[0].Value<string>("Title"));
View
8 Raven.Tests/Spatial/SpatialIndexTest.cs
@@ -74,7 +74,7 @@ public void CanPerformSpatialSearch()
SpatialRelation = SpatialRelation.Within,
SpatialFieldName = Constants.DefaultSpatialFieldName,
SortedFields = new[] { new SortedField("__distance"), }
- });
+ }, CancellationToken.None);
if (queryResult.IsStale)
Thread.Sleep(100);
} while (queryResult.IsStale);
@@ -122,7 +122,7 @@ public void CanPerformSpatialSearchWithNulls()
{
Query = "Tag:[[Event]]",
SortedFields = new[] { new SortedField("__distance"), }
- });
+ }, CancellationToken.None);
if (queryResult.IsStale)
Thread.Sleep(100);
} while (queryResult.IsStale);
@@ -178,7 +178,7 @@ public void CanSortByDistanceAndAnotherProp()
new SortedField("__distance"),
new SortedField("Venue"),
}
- });
+ }, CancellationToken.None);
if (queryResult.IsStale)
Thread.Sleep(100);
} while (queryResult.IsStale);
@@ -241,7 +241,7 @@ public void CanSortByAnotherPropAnddistance()
new SortedField("Venue"),
new SortedField("__distance"),
}
- });
+ }, CancellationToken.None);
if (queryResult.IsStale)
Thread.Sleep(100);
} while (queryResult.IsStale);
View
9 Raven.Tests/Storage/BackupRestore.cs
@@ -5,6 +5,7 @@
//-----------------------------------------------------------------------
using System.IO;
using System.Linq;
+using System.Threading;
using Raven.Abstractions.Data;
using Raven.Abstractions.Extensions;
using Raven.Client.Indexes;
@@ -83,7 +84,7 @@ public void AfterBackupRestoreCanQueryIndex_CreatedAfterRestore()
{
Query = "Tag:[[Users]]",
PageSize = 10
- });
+ }, CancellationToken.None);
} while (queryResult.IsStale);
Assert.Equal(1, queryResult.Results.Count);
}
@@ -100,7 +101,7 @@ public void AfterBackupRestoreCanQueryIndex_CreatedBeforeRestore()
{
Query = "Tag:[[Users]]",
PageSize = 10
- });
+ }, CancellationToken.None);
} while (queryResult.IsStale);
Assert.Equal(1, queryResult.Results.Count);
@@ -118,7 +119,7 @@ public void AfterBackupRestoreCanQueryIndex_CreatedBeforeRestore()
{
Query = "Tag:[[Users]]",
PageSize = 10
- });
+ }, CancellationToken.None);
Assert.Equal(1, queryResult.Results.Count);
}
@@ -134,7 +135,7 @@ public void AfterFailedBackupRestoreCanDetectError()
{
Query = "Tag:[[Users]]",
PageSize = 10
- });
+ }, CancellationToken.None);
} while (queryResult.IsStale);
Assert.Equal(1, queryResult.Results.Count);
View
3  Raven.Tests/Triggers/IndexTriggers.cs
@@ -4,6 +4,7 @@
// </copyright>
//-----------------------------------------------------------------------
using System.ComponentModel.Composition.Hosting;
+using System.Threading;
using Raven.Abstractions.Data;
using Raven.Abstractions.Indexing;
using Raven.Client.Embedded;
@@ -44,7 +45,7 @@ public void CanReplicateValuesFromIndexToDataTable()
QueryResult queryResult;
do
{
- queryResult = store.DocumentDatabase.Query("test", new IndexQuery { Start = 0, PageSize = 2, Query = "Project:RavenDB" });
+ queryResult = store.DocumentDatabase.Query("test", new IndexQuery { Start = 0, PageSize = 2, Query = "Project:RavenDB" }, CancellationToken.None);
} while (queryResult.IsStale);
var indexToDataTable = store.DocumentDatabase.IndexUpdateTriggers.OfType<IndexToDataTable>().Single();
View
19 Raven.Tests/Triggers/ReadTriggers.cs
@@ -6,6 +6,7 @@
using System.ComponentModel.Composition.Hosting;
using System.Linq;
+using System.Threading;
using Raven.Abstractions.Data;
using Raven.Abstractions.Indexing;
using Raven.Database;
@@ -79,7 +80,7 @@ public void CanFilterAccessToDocumentUsingTrigger_Query()
{
Query = "name:abC",
PageSize = 10
- });
+ }, CancellationToken.None);
} while (queryResult.IsStale);
Assert.Equal("Upper case characters in the 'name' property means the document is a secret!",
@@ -100,7 +101,7 @@ public void CanRemoveFilteredDocumentsFromIndexes()
Query = "name:abc",
PageSize = 10,
FieldsToFetch = new[] { "__document_id" }
- });
+ }, CancellationToken.None);
} while (queryResult.IsStale);
Assert.Equal(1, queryResult.Results.Count);
@@ -114,7 +115,7 @@ public void CanRemoveFilteredDocumentsFromIndexes()
Query = "name:abC",
PageSize = 10,
FieldsToFetch = new[] { "__document_id" }
- });
+ }, CancellationToken.None);
} while (queryResult.IsStale);
Assert.Equal(0, queryResult.Results.Count);
@@ -152,7 +153,7 @@ public void CanCompleteHideDocumentUsingTrigger_Query()
{
Query = "name:abC",
PageSize = 10
- });
+ }, CancellationToken.None);
} while (queryResult.IsStale);
Assert.Empty(queryResult.Results);
@@ -174,7 +175,7 @@ public void CanPageThroughFilteredQuery()
queryResult = db.Query("ByName", new IndexQuery
{
PageSize = 10
- });
+ }, CancellationToken.None);
} while (queryResult.IsStale);
Assert.Equal(7, queryResult.Results.Count);
@@ -197,7 +198,7 @@ public void CanPageThroughFilteredQuery_Page1()
{
PageSize = 3,
SortedFields = new[] { new SortedField("__document_id"), }
- });
+ }, CancellationToken.None);
} while (queryResult.IsStale);
Assert.Equal(3, queryResult.Results.Count);
@@ -223,7 +224,7 @@ public void CanPageThroughFilteredQuery_Page2()
{
PageSize = 3,
SortedFields = new[] { new SortedField("__document_id"), }
- });
+ }, CancellationToken.None);
} while (queryResult.IsStale);
queryResult = db.Query("ByName", new IndexQuery
@@ -231,7 +232,7 @@ public void CanPageThroughFilteredQuery_Page2()
PageSize = 3,
Start = queryResult.SkippedResults + queryResult.Results.Count,
SortedFields = new[] { new SortedField("__document_id"), }
- });
+ }, CancellationToken.None);
Assert.Equal(3, queryResult.Results.Count);
var array = queryResult.Results.Select(x => int.Parse(x["@metadata"].Value<string>("@id"))).OrderBy(x => x).ToArray();
@@ -273,7 +274,7 @@ public void CanModifyDocumentUsingTrigger_Query()
{
Query = "name:abC",
PageSize = 10
- });
+ }, CancellationToken.None);
} while (queryResult.IsStale);
Assert.Equal("ABC", queryResult.Results[0].Value<string>("name"));
View
2  Raven.Tests/Views/MapReduce.cs
@@ -103,7 +103,7 @@ private QueryResult GetUnstableQueryResult(string query)
Query = query,
Start = 0,
PageSize = 10
- });
+ }, CancellationToken.None);
if (q.IsStale)
Thread.Sleep(100);
} while (q.IsStale && count++ < 100);
View
2  Raven.Tests/Views/MapReduce_IndependentSteps.cs
@@ -82,7 +82,7 @@ public void CanGetReducedValues()
Query = "blog_id:3",
Start = 0,
PageSize = 10
- });
+ }, CancellationToken.None);
Thread.Sleep(100);
} while (q.IsStale);
}
Please sign in to comment.
Something went wrong with that request. Please try again.