Permalink
Browse files

Introducing cancellation tokens and limited time to process queries o…

…n server side queries
  • Loading branch information...
1 parent 0341764 commit 1136a1c8434c64a99350f3ac12956f36350c24c9 @ayende ayende committed Jan 22, 2014
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
@@ -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);
}
@@ -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,17 +79,18 @@ 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,
PageSize = pageSize,
Cutoff = currentTime,
Query = query,
FieldsToFetch = new[] { "__document_id" }
- });
+ }, cts.Token);
}
if(queryResult.Results.Count == 0)
@@ -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; }
@@ -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; }
+ }
}
Oops, something went wrong.

0 comments on commit 1136a1c

Please sign in to comment.