Permalink
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...
1 parent 803e0af commit afd2d107eb76596123a7fba06eb0251b670609e2 @arekpalinski arekpalinski committed Feb 5, 2014
Showing with 25 additions and 1 deletion.
  1. +1 −1 Raven.Database/Prefetching/PrefetchingBehavior.cs
  2. +24 −0 Raven.Tests/Bugs/PrefetchingBug.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)
@@ -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);
+ }
+ }
}
}

0 comments on commit afd2d10

Please sign in to comment.