Skip to content
Browse files

Making sure that we don't get race conditions in map/reduce indexes w…

…hen caching is involved.
  • Loading branch information...
1 parent 4cfcaa3 commit 274060ab6a3e6bc7fbcc33941c33496bc810a07b @ayende ayende committed
View
7 Raven.Database/DocumentDatabase.cs
@@ -1331,13 +1331,14 @@ public Guid GetIndexEtag(string indexName, QueryResult queryResult)
lastReducedEtag = accessor.Staleness.GetMostRecentReducedEtag(indexName);
touchCount = accessor.Staleness.GetIndexTouchCount(indexName);
});
- if (queryResult != null &&
- queryResult.IndexEtag != lastDocEtag)
+ if (queryResult != null)
{
// the index changed between the time when we got it and the time
// we actually call this, we need to return something random so that
// the next time we won't get 304
- return Guid.NewGuid();
+ if (lastReducedEtag != null && queryResult.IndexEtag != lastReducedEtag.Value ||
+ lastDocEtag != queryResult.IndexEtag)
+ return Guid.NewGuid();
}
var indexDefinition = GetIndexDefinition(indexName);
View
16 Raven.Storage.Esent/StorageActions/Staleness.cs
@@ -123,6 +123,22 @@ public bool IsMapStale(string name)
{
throw new IndexDoesNotExistsException("Could not find index named: " + name);
}
+
+ Api.JetSetCurrentIndex(session, IndexesStatsReduce, "by_key");
+ Api.MakeKey(session, IndexesStatsReduce, name, Encoding.Unicode, MakeKeyGrbit.NewKey);
+ if(Api.TrySeek(session, IndexesStatsReduce, SeekGrbit.SeekEQ))
+ {// for map-reduce indexes, we use the reduce stats
+
+ var lastReducedIndex = Api.RetrieveColumnAsDateTime(session, IndexesStatsReduce,
+ tableColumnsCache.IndexesStatsReduceColumns["last_reduced_timestamp"])
+ .Value;
+ var lastReducedEtag = Api.RetrieveColumn(session, IndexesStatsReduce,
+ tableColumnsCache.IndexesStatsReduceColumns["last_reduced_etag"]).TransfromToGuidWithProperSorting();
+ return Tuple.Create(lastReducedIndex, lastReducedEtag);
+
+ }
+
+
var lastIndexedTimestamp = Api.RetrieveColumnAsDateTime(session, IndexesStats,
tableColumnsCache.IndexesStatsColumns["last_indexed_timestamp"])
.Value;
View
9 Raven.Storage.Managed/StalenessStorageActions.cs
@@ -106,6 +106,15 @@ public bool IsMapStale(string name)
if (readResult == null)
throw new IndexDoesNotExistsException("Could not find index named: " + name);
+
+ if (readResult.Key.Value<object>("lastReducedTimestamp") != null)
+ {
+ return Tuple.Create(
+ readResult.Key.Value<DateTime>("lastReducedTimestamp"),
+ new Guid(readResult.Key.Value<byte[]>("lastReducedEtag"))
+ );
+ }
+
return Tuple.Create(
readResult.Key.Value<DateTime>("lastTimestamp"),
new Guid(readResult.Key.Value<byte[]>("lastEtag"))
View
1 Raven.StressTests/Raven.StressTests.csproj
@@ -49,6 +49,7 @@
</Reference>
</ItemGroup>
<ItemGroup>
+ <Compile Include="Races\RaceConditions.cs" />
<Compile Include="Storage\MultiThreadedStress\BatchOperationStress.cs" />
<Compile Include="Storage\MultiThreadedStress\PutOperationStress.cs" />
<Compile Include="StressTest.cs" />
View
4 Raven.Tryouts/Program.cs
@@ -31,8 +31,8 @@ private static void Main()
Environment.SetEnvironmentVariable("Run", i.ToString());
Console.Clear();
Console.WriteLine(i);
- using (var x = new MapReduce())
- x.CanUpdateReduceValue_WhenChangingReduceKey();
+ var x = new Raven.Tests.MailingList.MapReduceIssue.CanPageThroughReduceResults();
+ x.Test();
}
}
catch (Exception e)

0 comments on commit 274060a

Please sign in to comment.
Something went wrong with that request. Please try again.