Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Properly filtering out already deleted items by prefetching behavior …

…- there was a bug when deleted etag was greater that an etag of a checked document
  • Loading branch information...
commit afd2d107eb76596123a7fba06eb0251b670609e2 1 parent 803e0af
@arekais arekais authored
View
2  Raven.Database/Prefetching/PrefetchingBehavior.cs
@@ -404,7 +404,7 @@ public void CleanupDocuments(Etag lastIndexedEtag)
public bool FilterDocuments(JsonDocument document)
{
HashSet<Etag> etags;
- return (documentsToRemove.TryGetValue(document.Key, out etags) && etags.Contains(document.Etag)) == false;
+ return (documentsToRemove.TryGetValue(document.Key, out etags) && etags.Any(x => x.CompareTo(document.Etag) >= 0)) == false;
}
public void AfterDelete(string key, Etag deletedEtag)
View
24 Raven.Tests/Bugs/PrefetchingBug.cs
@@ -84,5 +84,29 @@ public void ShouldHandleUpdateWhenPrefetchingDocsIsDisabled()
Assert.Equal(putResult3.ETag, docs[1].Etag);
}
}
+
+
+ [Fact]
+ public void ShouldFilterOutDeletedDocsIfDeletedDocsListContainsAnyItemWithHigherEtag()
+ {
+ using (var store = NewDocumentStore())
+ {
+ store.DocumentDatabase.WorkContext.StopIndexing(); // stop indexing to be able manually manage the prefetcher
+ store.DocumentDatabase.WorkContext.Configuration.MaxNumberOfItemsToPreFetchForIndexing = 1;
+
+ var putResult1 = store.DocumentDatabase.Put("key/1", null, new RavenJObject(), new RavenJObject(), null); // will go to prefetching queue
+ var putResult2 = store.DocumentDatabase.Put("key/1", null, new RavenJObject(), new RavenJObject(), null); // update - will not go into prefetching queue because MaxNumberOfItemsToPreFetchForIndexing = 1;
+
+ var deleted = store.DocumentDatabase.Delete("key/1", null, null); // delete
+
+ Assert.True(deleted);
+
+ var prefetchingBehavior = store.DocumentDatabase.Prefetcher.GetPrefetchingBehavior(PrefetchingUser.Indexer, null);
+ var docs = prefetchingBehavior.GetDocumentsBatchFrom(putResult1.ETag.IncrementBy(-1)); // here we can get a document
+ var filteredDocs = docs.Where(prefetchingBehavior.FilterDocuments).ToList(); // but here we should filter it out because it's already deleted!!!
+
+ Assert.Equal(0, filteredDocs.Count);
+ }
+ }
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.