Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixing a bug in Munin where it wouldn't select the proper etag value …

…when checking reduced items
  • Loading branch information...
commit 1c713b3a8219467777cbfe54faa1ec071d083ae1 1 parent 64ce3cb
@ayende ayende authored
View
7 Modules/Munin/Raven.Munin/ComparableByteArray.cs
@@ -18,6 +18,13 @@ public ComparableByteArray(byte[] inner)
public int CompareTo(ComparableByteArray other)
{
+ if (inner == null && other.inner == null)
+ return 0;
+ if (inner == null)
+ return 1;
+ if (other.inner == null)
+ return -1;
+
if (inner.Length != other.inner.Length)
return inner.Length - other.inner.Length;
for (int i = 0; i < inner.Length; i++)
View
13 Modules/Munin/Raven.Munin/SecondaryIndex.cs
@@ -104,7 +104,7 @@ public IEnumerable<RavenJToken> SkipBefore(RavenJToken key)
}
- public RavenJToken LowestEqual(RavenJObject key, Predicate<RavenJToken> predicate)
+ public RavenJToken GreatestEqual(RavenJObject key, Predicate<RavenJToken> predicate)
{
return persistentSource.Read(
() =>
@@ -113,9 +113,14 @@ public RavenJToken LowestEqual(RavenJObject key, Predicate<RavenJToken> predicat
if (nearest.IsEmpty)
return null;
- while (nearest.Left.IsEmpty == false && predicate(nearest.Left.Value.Value))
- nearest = nearest.Left;
- return nearest.Value.Value;
+ var binarySearchTree = nearest.ValuesInOrder
+ .SkipWhile(x => predicate(x.Value) == false)
+ .TakeWhile(x => predicate(x.Value))
+ .LastOrDefault();
+ if (binarySearchTree == null)
+ return null;
+ return binarySearchTree.Value;
+
});
}
View
6 Modules/Munin/Raven.Munin/Tree/AVLTree.cs
@@ -318,6 +318,12 @@ public IEnumerable<TKey> KeysInOrder
get { return from t in EnumerateInOrder() select t.Key; }
}
+
+ public IEnumerable<TKey> KeysInReverseOrder
+ {
+ get { return from t in EnumerateInReverseOrder() select t.Key; }
+ }
+
public IEnumerable<TValue> ValuesInOrder
{
get { return from t in EnumerateInOrder() select t.Value; }
View
6 Modules/Munin/Raven.Munin/Tree/EmptyAVLTree.cs
@@ -143,6 +143,12 @@ public IEnumerable<TKey> KeysInOrder
get { yield break; }
}
+ public IEnumerable<TKey> KeysInReverseOrder
+ {
+ get { yield break; }
+ }
+
+
public IEnumerable<TValue> ValuesInOrder
{
get { yield break; }
View
1  Modules/Munin/Raven.Munin/Tree/IBinarySearchTree.cs
@@ -27,6 +27,7 @@ public interface IBinarySearchTree<TKey, TValue>
IBinarySearchTree<TKey, TValue> Right { get; }
TKey Key { get; }
IEnumerable<TKey> KeysInOrder { get; }
+ IEnumerable<TKey> KeysInReverseOrder { get; }
IEnumerable<TValue> ValuesInOrder { get; }
IEnumerable<TValue> ValuesInReverseOrder { get; }
IEnumerable<KeyValuePair<TKey, TValue>> Pairs { get; }
View
4 Raven.Storage.Managed/Impl/TableStorage.cs
@@ -48,7 +48,9 @@ public TableStorage(IPersistentSource persistentSource)
{
{"ByViewAndReduceKey", x => Tuple.Create(x.Value<string>("view"), x.Value<string>("reduceKey"))},
{"ByViewAndDocumentId", x => Tuple.Create(x.Value<string>("view"), x.Value<string>("docId"))},
- {"ByViewAndEtag", x => Tuple.Create(x.Value<string>("view"), new ReverseComparableByteArrayWhichIgnoresNull(x.Value<byte[]>("etag")))}
+ {"ByViewAndEtagDesc", x => Tuple.Create(x.Value<string>("view"), new ReverseComparableByteArrayWhichIgnoresNull(x.Value<byte[]>("etag")))},
+ {"ByViewAndEtag", x => Tuple.Create(x.Value<string>("view"), new ComparableByteArray(x.Value<byte[]>("etag")))}
+
});
Queues = Add(new Table(x => new RavenJObject
View
2  Raven.Storage.Managed/MappedResultsStorageAction.cs
@@ -92,7 +92,7 @@ public void DeleteMappedResultsForView(string view)
public IEnumerable<MappedResultInfo> GetMappedResultsReduceKeysAfter(string indexName, Guid lastReducedEtag, bool loadData)
{
- return storage.MappedResults["ByViewAndEtag"]
+ return storage.MappedResults["ByViewAndEtagDesc"]
// the index is sorted view ascending and then etag descending
// we index before this index, then backward toward the last one.
.SkipBefore(new RavenJObject { { "view", indexName }, {"etag", lastReducedEtag.ToByteArray()}})
View
2  Raven.Storage.Managed/StalenessStorageActions.cs
@@ -135,7 +135,7 @@ public Guid GetMostRecentDocumentEtag()
public Guid? GetMostRecentReducedEtag(string name)
{
var keyWithHighestEqualTo = storage.MappedResults["ByViewAndEtag"]
- .LowestEqual(new RavenJObject {{"view", name}}, token => token.Value<string>("view") == name);
+ .GreatestEqual(new RavenJObject {{"view", name}}, token => token.Value<string>("view") == name);
if(keyWithHighestEqualTo == null)
return null;
View
6 Raven.Storage.Managed/TransactionalStorage.cs
@@ -31,6 +31,12 @@ public class TransactionalStorage : ITransactionalStorage
private readonly InMemoryRavenConfiguration configuration;
private readonly Action onCommit;
private TableStorage tableStroage;
+
+ public TableStorage TableStroage
+ {
+ get { return tableStroage; }
+ }
+
private IPersistentSource persistenceSource;
private volatile bool disposed;
private readonly ReaderWriterLockSlim disposerLock = new ReaderWriterLockSlim();
View
14 Raven.Tests/Bugs/CompiledIndexesNhsevidence.cs
@@ -30,7 +30,7 @@ public void CanGetCorrectResults()
{
AddRecord(store, 1);
}
- ReadRecords(store, 600);
+ ReadRecords(store, 60);
}
}
}
@@ -42,15 +42,7 @@ private static void ReadRecords(IDocumentStore store, int shouldBe)
for (int i = 0; i < 6; i++)
{
int count = session.Advanced.LuceneQuery<object>("view" + (i+1)).WaitForNonStaleResults().QueryResult.TotalResults;
- if(count != shouldBe)
- {
- var boundedMemoryTarget = LogManager.Configuration.AllTargets.OfType<BoundedMemoryTarget>().FirstOrDefault();
- var logEventInfos = boundedMemoryTarget.GeneralLog.ToArray();
- foreach (var logEventInfo in logEventInfos)
- {
- Console.WriteLine(logEventInfo);
- }
- }
+
Assert.Equal(count, shouldBe);
}
}
@@ -63,7 +55,7 @@ private static void AddRecord(IDocumentStore store,int records)
for (int i = 0; i < records; i++)
{
var item = new TestClass {Items = new List<Item>()};
- for (int j = 0; j < 50; j++)
+ for (int j = 0; j < 5; j++)
{
item.Items.Add(new Item()
{
Please sign in to comment.
Something went wrong with that request. Please try again.