Permalink
Browse files

Provide a debug option so we can no look at the mapped results for an…

… index
  • Loading branch information...
ayende committed Sep 27, 2011
1 parent c4c2528 commit 6dbb092a6ea992538bfa1b377593a7c7579c5e4d
@@ -25,7 +25,8 @@ protected void HandleReduceForIndex(IndexToWorkOn indexToWorkOn)
reduceKeyAndEtags = actions.MappedResults.GetMappedResultsReduceKeysAfter
(
indexToWorkOn.IndexName,
- indexToWorkOn.LastIndexedEtag
+ indexToWorkOn.LastIndexedEtag,
+ loadData: false
).ToList();
if(log.IsDebugEnabled)
@@ -15,6 +15,7 @@
using Raven.Database.Extensions;
using Raven.Database.Queries;
using Raven.Database.Server.Abstractions;
+using Raven.Database.Storage;
namespace Raven.Database.Server.Responders
{
@@ -74,16 +75,44 @@ private void Put(IHttpContext context, string index)
private void OnGet(IHttpContext context, string index)
{
var definition = context.Request.QueryString["definition"];
- if ("yes".Equals(definition, StringComparison.InvariantCultureIgnoreCase))
+ var debug = context.Request.QueryString["debug"];
+ bool result;
+ if ("yes".Equals(definition, StringComparison.InvariantCultureIgnoreCase) ||
+ bool.TryParse(definition, out result) && result)
{
GetIndexDefinition(context, index);
}
- else
+ else if("map".Equals(debug,StringComparison.InvariantCultureIgnoreCase))
+ {
+ GetIndexMappedResult(context, index);
+ }
+ else if("reduce".Equals(debug,StringComparison.InvariantCultureIgnoreCase))
+ {
+ }
+ else
{
GetIndexQueryRessult(context, index);
}
}
+ private void GetIndexMappedResult(IHttpContext context, string index)
+ {
+ if(Database.IndexDefinitionStorage.GetIndexDefinition(index)==null)
+ {
+ context.SetStatusToNotFound();
+ return;
+ }
+
+ var etag = context.GetEtagFromQueryString() ?? Guid.Empty;
+ List<MappedResultInfo> mappedResult = null;
+ Database.TransactionalStorage.Batch(accessor =>
+ {
+ mappedResult = accessor.MappedResults.GetMappedResultsReduceKeysAfter(index, etag,loadData: true)
+ .Take(context.GetPageSize(Settings.MaxPageSize)).ToList();
+ });
+ context.WriteJson(mappedResult);
+ }
+
private void GetIndexQueryRessult(IHttpContext context, string index)
{
Guid indexEtag;
@@ -15,13 +15,15 @@ public interface IMappedResultsStorageAction
IEnumerable<RavenJObject> GetMappedResults(params GetMappedResultsParams[] getMappedResultsParams);
IEnumerable<string> DeleteMappedResultsForDocumentId(string documentId, string view);
void DeleteMappedResultsForView(string view);
- IEnumerable<MappedResultInfo> GetMappedResultsReduceKeysAfter(string indexName, Guid lastReducedEtag);
+ IEnumerable<MappedResultInfo> GetMappedResultsReduceKeysAfter(string indexName, Guid lastReducedEtag, bool loadData);
}
public class MappedResultInfo
{
public string ReduceKey { get; set; }
public DateTime Timestamp { get; set; }
public Guid Etag { get; set; }
+
+ public RavenJObject Data { get; set; }
}
}
@@ -111,7 +111,7 @@ public void DeleteMappedResultsForView(string view)
} while (Api.TryMoveNext(session, MappedResults));
}
- public IEnumerable<MappedResultInfo> GetMappedResultsReduceKeysAfter(string indexName, Guid lastReducedEtag)
+ public IEnumerable<MappedResultInfo> GetMappedResultsReduceKeysAfter(string indexName, Guid lastReducedEtag, bool loadData)
{
Api.JetSetCurrentIndex(session, MappedResults, "by_view_and_etag");
Api.MakeKey(session, MappedResults, indexName, Encoding.Unicode, MakeKeyGrbit.NewKey);
@@ -121,12 +121,15 @@ public IEnumerable<MappedResultInfo> GetMappedResultsReduceKeysAfter(string inde
while (Api.RetrieveColumnAsString(session, MappedResults, tableColumnsCache.MappedResultsColumns["view"]) == indexName)
{
- yield return new MappedResultInfo
- {
- ReduceKey = Api.RetrieveColumnAsString(session, MappedResults, tableColumnsCache.MappedResultsColumns["reduce_key"]),
- Etag = new Guid(Api.RetrieveColumn(session, MappedResults, tableColumnsCache.MappedResultsColumns["etag"])),
- Timestamp = Api.RetrieveColumnAsDateTime(session, MappedResults, tableColumnsCache.MappedResultsColumns["timestamp"]).Value,
- };
+ var result = new MappedResultInfo
+ {
+ ReduceKey = Api.RetrieveColumnAsString(session, MappedResults, tableColumnsCache.MappedResultsColumns["reduce_key"]),
+ Etag = new Guid(Api.RetrieveColumn(session, MappedResults, tableColumnsCache.MappedResultsColumns["etag"])),
+ Timestamp = Api.RetrieveColumnAsDateTime(session, MappedResults, tableColumnsCache.MappedResultsColumns["timestamp"]).Value,
+ };
+ if (loadData)
+ result.Data = Api.RetrieveColumn(session, MappedResults, tableColumnsCache.MappedResultsColumns["data"]).ToJObject();
+ yield return result;
// the index is view ascending and etag descending
// that means that we are going backward to go up
@@ -90,18 +90,28 @@ public void DeleteMappedResultsForView(string view)
}
}
- public IEnumerable<MappedResultInfo> GetMappedResultsReduceKeysAfter(string indexName, Guid lastReducedEtag)
+ public IEnumerable<MappedResultInfo> GetMappedResultsReduceKeysAfter(string indexName, Guid lastReducedEtag, bool loadData)
{
return storage.MappedResults["ByViewAndEtag"]
// 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()}})
.TakeWhile(x => StringComparer.InvariantCultureIgnoreCase.Equals(x.Value<string>("view"), indexName))
- .Select(key => new MappedResultInfo
+ .Select(key =>
{
- ReduceKey = key.Value<string>("reduceKey"),
- Etag = new Guid(key.Value<byte[]>("etag")),
- Timestamp = key.Value<DateTime>("timestamp")
+ var mappedResultInfo = new MappedResultInfo
+ {
+ ReduceKey = key.Value<string>("reduceKey"),
+ Etag = new Guid(key.Value<byte[]>("etag")),
+ Timestamp = key.Value<DateTime>("timestamp"),
+ };
+ if(loadData)
+ {
+ var readResult = storage.MappedResults.Read(key);
+ if (readResult != null)
+ mappedResultInfo.Data = readResult.Data().ToJObject();
+ }
+ return mappedResultInfo;
});
}
}
@@ -121,9 +121,9 @@ private static void when_there_are_multiple_map_results_and_we_ask_for_results(I
transactionalStorage.Batch(actionsAccessor =>
{
- Assert.Equal(2, actionsAccessor.MappedResults.GetMappedResultsReduceKeysAfter("a", Guid.Empty).Count());
- Assert.Equal(2, actionsAccessor.MappedResults.GetMappedResultsReduceKeysAfter("b", Guid.Empty).Count());
- Assert.Equal(2, actionsAccessor.MappedResults.GetMappedResultsReduceKeysAfter("c", Guid.Empty).Count());
+ Assert.Equal(2, actionsAccessor.MappedResults.GetMappedResultsReduceKeysAfter("a", Guid.Empty, false).Count());
+ Assert.Equal(2, actionsAccessor.MappedResults.GetMappedResultsReduceKeysAfter("b", Guid.Empty, false).Count());
+ Assert.Equal(2, actionsAccessor.MappedResults.GetMappedResultsReduceKeysAfter("c", Guid.Empty, false).Count());
});
}
@@ -180,9 +180,9 @@ private static void when_there_are_updates_to_map_reduce_results(ITransactionalS
transactionalStorage.Batch(actionsAccessor =>
{
- Assert.Equal(1, actionsAccessor.MappedResults.GetMappedResultsReduceKeysAfter("a", a).Count());
- Assert.Equal(1, actionsAccessor.MappedResults.GetMappedResultsReduceKeysAfter("b", b).Count());
- Assert.Equal(1, actionsAccessor.MappedResults.GetMappedResultsReduceKeysAfter("c", c).Count());
+ Assert.Equal(1, actionsAccessor.MappedResults.GetMappedResultsReduceKeysAfter("a", a, false).Count());
+ Assert.Equal(1, actionsAccessor.MappedResults.GetMappedResultsReduceKeysAfter("b", b, false).Count());
+ Assert.Equal(1, actionsAccessor.MappedResults.GetMappedResultsReduceKeysAfter("c", c, false).Count());
});
}
View
@@ -22,46 +22,6 @@ class Program
static void Main()
{
- try
- {
- IOExtensions.DeleteDirectory("Data");
- using (var documentStore = new EmbeddableDocumentStore())
- {
- var threads = new List<Thread>();
-
- InitDatabase(documentStore);
- for (var i = 0; i < 10; i++)
- {
- var thread = new Thread(x => InsertAndQueryLoop(documentStore));
- thread.Start();
- threads.Add(thread);
- }
-
- while (!_stop)
- {
- Thread.Sleep(5000);
- Console.WriteLine("NumberOfDocs={0}, StaleIndexes={1}",
- documentStore.DocumentDatabase.Statistics.CountOfDocuments,
- documentStore.DocumentDatabase.Statistics.StaleIndexes.Count());
- }
-
- foreach (var thread in threads)
- {
- thread.Join();
- }
-
- foreach (var exception in _exceptions)
- {
- Console.WriteLine(exception.Message);
- }
- }
- }
- catch (Exception ex)
- {
- Log.ErrorException("Bad things have happened!", ex);
- throw;
- }
- Console.WriteLine("Program stopped");
}
private static void InsertAndQueryLoop(IDocumentStore documentStore)

0 comments on commit 6dbb092

Please sign in to comment.