Permalink
Browse files

Merge branch 'dev' of github.com:/EventStore/EventStore into dev

  • Loading branch information...
anakryiko committed Nov 12, 2012
2 parents f0787cb + 226a6d4 commit 1c4f72e366ff28f10668d2a3b00d0e2d1a7e646c
@@ -27,23 +27,42 @@
//
using System;
using System.IO;
+using System.Text;
using EventStore.Common.Configuration;
using EventStore.Common.Utils;
+using NLog;
+using NLog.LayoutRenderers;
namespace EventStore.Common.Log
{
+ [LayoutRenderer("logsdir")]
+ public class NLogDirectoryLayoutRendered : LayoutRenderer
+ {
+ protected override void Append(StringBuilder builder, LogEventInfo logEvent)
+ {
+ builder.Append(LogManager._logsDirectory);
+ }
+ }
+
public static class LogManager
{
+
+ static LogManager()
+ {
+ NLog.Config.ConfigurationItemFactory.Default.LayoutRenderers.RegisterDefinition("logsdir", typeof(NLogDirectoryLayoutRendered));
+ }
+
private static readonly ILogger GlobalLogger = GetLogger("GLOBAL-LOGGER");
private static bool _initialized;
+ internal static string _logsDirectory;
public static string LogsDirectory
{
get
{
if (!_initialized)
throw new InvalidOperationException("Init method must be called");
- return Environment.GetEnvironmentVariable(Constants.EnvVarPrefix + Constants.EnvVarLogsSuffix);
+ return _logsDirectory;
}
}
@@ -72,8 +91,7 @@ public static void Init(string componentName, string logsDirectory)
private static void SetLogsDirectoryInternal(string logsDirectory)
{
- const string logsDirEnvVar = Constants.EnvVarPrefix + Constants.EnvVarLogsSuffix;
- Environment.SetEnvironmentVariable(logsDirEnvVar, logsDirectory, EnvironmentVariableTarget.Process);
+ _logsDirectory = logsDirectory;
}
private static void SetComponentName(string componentName)
@@ -93,7 +93,6 @@ public override void TestFixtureSetUp()
TableIndex = new TableIndex(Path.Combine(PathName, "index"),
() => new HashListMemTable(MaxEntriesInMemTable * 2),
MaxEntriesInMemTable);
- TableIndex.Initialize();
var reader = new TFChunkReader(Db, Db.Config.WriterCheckpoint);
ReadIndex = new ReadIndex(new NoopPublisher(),
@@ -40,7 +40,7 @@
namespace EventStore.Core.Tests.Services.Storage.Transactions
{
- [TestFixture, Ignore]
+ [TestFixture]
public class when_rebuilding_index_for_partially_persisted_transaction : ReadIndexTestScenario
{
public when_rebuilding_index_for_partially_persisted_transaction(): base(maxEntriesInMemTable: 10)
@@ -58,7 +58,6 @@ public override void TestFixtureSetUp()
TableIndex = new TableIndex(Path.Combine(PathName, "index"),
() => new HashListMemTable(maxSize: 2000),
maxSizeForMemory: MaxEntriesInMemTable);
- TableIndex.Initialize();
ReadIndex = new ReadIndex(new NoopPublisher(),
2,
@@ -70,12 +69,6 @@ public override void TestFixtureSetUp()
ReadIndex.Build();
}
- public override void TestFixtureTearDown()
- {
- Thread.Sleep(500); // give chance to IndexMap to dump files
- base.TestFixtureTearDown();
- }
-
protected override void WriteTestScenario()
{
var begin = WriteTransactionBegin("ES", ExpectedVersion.Any);
@@ -62,7 +62,9 @@ public class TableIndex : ITableIndex
private long _prepareCheckpoint = -1;
private volatile bool _backgroundRunning;
- private readonly ManualResetEvent _backgroundRunningEvent = new ManualResetEvent(true);
+ private readonly ManualResetEventSlim _backgroundRunningEvent = new ManualResetEventSlim(true);
+
+ private bool _initialized;
public TableIndex(string directory,
Func<IMemTable> memTableFactory,
@@ -87,6 +89,12 @@ public class TableIndex : ITableIndex
public void Initialize()
{
//NOT THREAD SAFE (assumes one thread)
+
+ if (_initialized)
+ throw new IOException("TableIndex is already initialized.");
+
+ _initialized = true;
+
CreateIfDoesNotExist(_directory);
try
@@ -163,6 +171,7 @@ public void Add(long commitPos, uint stream, int version, long position)
_awaitingMemTables = newTables;
if (!_backgroundRunning)
{
+ _backgroundRunningEvent.Reset();
_backgroundRunning = true;
ThreadPool.QueueUserWorkItem(x => ReadOffQueue());
}
@@ -175,7 +184,6 @@ public void Add(long commitPos, uint stream, int version, long position)
private void ReadOffQueue()
{
- _backgroundRunningEvent.Reset();
try
{
while (true)
@@ -188,6 +196,7 @@ private void ReadOffQueue()
if (_awaitingMemTables.Count == 1)
{
_backgroundRunning = false;
+ _backgroundRunningEvent.Set();
return;
}
tableItem = _awaitingMemTables[_awaitingMemTables.Count - 1];
@@ -240,11 +249,6 @@ private void ReadOffQueue()
Log.ErrorException(exc, "Error in TableIndex.ReadOffQueue");
throw;
}
- finally
- {
- _backgroundRunning = false;
- _backgroundRunningEvent.Set();
- }
}
private void ReclaimMemoryIfNeeded(List<TableItem> awaitingMemTables)
@@ -442,11 +446,11 @@ private static int GetMaxOf(List<IEnumerator<IndexEntry>> enumerators)
public void ClearAll(bool removeFiles = true)
{
- _awaitingMemTables = new List<TableItem> { new TableItem(_memTableFactory(), -1, -1) };
-
- _backgroundRunningEvent.WaitOne(1000);
//this should also make sure that no background tasks are running anymore
+ if (!_backgroundRunningEvent.Wait(1000))
+ throw new TimeoutException("Could not finish background thread in reasonable time.");
+
if (_indexMap != null)
{
if (removeFiles)
@@ -38,6 +38,7 @@ public static class HttpClientMessageDto
{
#region HTTP DTO
+ [XmlType(TypeName = "event")]
public class ClientEventText
{
public Guid EventId { get; set; }
@@ -75,6 +76,7 @@ public ClientEventText(Guid eventId, string eventType, byte[] data, byte[] metaD
}
}
+ [XmlRoot(ElementName = "write-events")]
public class WriteEventsText
{
public int ExpectedVersion { get; set; }
@@ -94,6 +96,7 @@ public WriteEventsText(int expectedVersion, ClientEventText[] events)
}
}
+ [XmlRoot(ElementName = "read-event-result")]
public class ReadEventCompletedText
{
public string EventStreamId { get; set; }
@@ -101,17 +101,30 @@ private static HttpClientMessageDto.WriteEventsText LoadFromXml(string xml)
{
try
{
- xml = xml.Replace("<Events>", string.Empty).Replace("</Events>", string.Empty)
- .Replace("<write-events>", "<write-events xmlns:json='http://james.newtonking.com/projects/json'>")
- .Replace("<event>", "<Events json:Array='true'>").Replace("</event>", "</Events>");
var doc = XDocument.Parse(xml);
- var version = doc.Descendants("ExpectedVersion").Single();
- version.Remove();
+ XNamespace jsonNs = "http://james.newtonking.com/projects/json";
+ XName jsonName = XNamespace.Xmlns + "json";
- var json = JsonConvert.SerializeXNode(doc, Formatting.None, true);
- var textEvents = JsonConvert.DeserializeObject<JObject>(json)["Events"].ToObject<HttpClientMessageDto.ClientEventText[]>();
- return new HttpClientMessageDto.WriteEventsText(int.Parse(version.Value), textEvents.ToArray());
+ doc.Root.SetAttributeValue(jsonName, jsonNs);
+
+ var expectedVersion = doc.Root.Element("ExpectedVersion");
+ var events = doc.Root.Descendants("event").ToArray();
+
+ foreach (var @event in events)
+ {
+ @event.Name = "Events";
+ @event.SetAttributeValue(jsonNs + "Array", "true");
+ }
+
+ doc.Root.ReplaceNodes(events);
+
+ foreach (var element in doc.Root.Descendants("Data").Concat(doc.Root.Descendants("Metadata")))
+ element.RemoveAttributes();
+
+ var json = JsonConvert.SerializeXNode(doc, Formatting.None, false);
+ var textEvents = JsonConvert.DeserializeObject<JObject>(json)["write-events"]["Events"].ToObject<HttpClientMessageDto.ClientEventText[]>();
+ return new HttpClientMessageDto.WriteEventsText(int.Parse(expectedVersion.Value), textEvents.ToArray());
}
catch (Exception e)
{
@@ -402,7 +402,7 @@ private void WriteCompleted(ClientMessage.WriteEventsCompleted message, Action c
private void Prepare(Action onPrepared)
{
if (!Enabled)
- throw new InvalidOperationException("Disable projection cannot be prepared");
+ throw new InvalidOperationException("Disabled projection cannot be prepared");
var config = CreateDefaultProjectionConfiguration(GetMode());
@@ -8,14 +8,14 @@
<targets async="true">
<target name="fileLog"
xsi:type="File"
- fileName="${environment:variable=EVENTSTORE_LOGSDIR}/${shortdate:universalTime=true}/${environment:variable=EVENTSTORE_INT-COMPONENT-NAME}.log"
+ fileName="${logsdir}/${shortdate:universalTime=true}/${environment:variable=EVENTSTORE_INT-COMPONENT-NAME}.log"
layout="[PID:${pad:padCharacter=0:padding=2:inner=${processid}} ${date:universalTime=true:format=yyyy\.MM\.dd HH\:mm\:ss\.fff} ${level} ${logger} ${threadid}]${newline}${message}${onexception:${newline}EXCEPTION OCCURED:${newline}${exception:format=tostring:innerFormat=tostring:maxInnerExceptionLevel=20}}"/>
<target name="errorFileLog"
xsi:type="FilteringWrapper"
condition="length('${exception}')>0">
<target xsi:type="File"
- fileName="${environment:variable=EVENTSTORE_LOGSDIR}/${shortdate:universalTime=true}/${environment:variable=EVENTSTORE_INT-COMPONENT-NAME}-err.log"
+ fileName="${logsdir}/${shortdate:universalTime=true}/${environment:variable=EVENTSTORE_INT-COMPONENT-NAME}-err.log"
layout="[PID:${pad:padCharacter=0:padding=2:inner=${processid}} ${date:universalTime=true:format=yyyy\.MM\.dd HH\:mm\:ss\.fff} ${level} ${logger} ${threadid}]${newline}${message}${onexception:${newline}EXCEPTION OCCURED:${newline}${exception:format=tostring:innerFormat=tostring:maxInnerExceptionLevel=20}}"/>
</target>
@@ -32,12 +32,12 @@
<target name="statsFileLog"
xsi:type="File"
- fileName="${environment:variable=EVENTSTORE_LOGSDIR}/${shortdate:universalTime=true}/${environment:variable=EVENTSTORE_INT-COMPONENT-NAME}-stats.csv"
+ fileName="${logsdir}/${shortdate:universalTime=true}/${environment:variable=EVENTSTORE_INT-COMPONENT-NAME}-stats.csv"
layout="${message}"/>
<target name="integrationOutputFileLog"
xsi:type="File"
- fileName="${environment:variable=EVENTSTORE_LOGSDIR}/${shortdate:universalTime=true}/${environment:variable=EVENTSTORE_INT-COMPONENT-NAME}-perf-${environment:variable=EVENTSTORE_TC_RUN_NUMBER}.txt"
+ fileName="${logsdir}/${shortdate:universalTime=true}/${environment:variable=EVENTSTORE_INT-COMPONENT-NAME}-perf-${environment:variable=EVENTSTORE_TC_RUN_NUMBER}.txt"
layout="[${pad:padCharacter=0:padding=5:inner=${processid}},${pad:padCharacter=0:padding=2:inner=${threadid}},${date:format=yyyy\.MM\.dd HH\:mm\:ss\.fff}]${newline}${message}"/>
</targets>
@@ -128,8 +128,8 @@ private void WriteFlood(CommandProcessorContext context, string eventStreamId, i
"DATA" + new string('*', 256),
"METADATA" + new string('$', 100))
});
- var requestString = Codec.Json.To(write);
- client.Post(url, requestString, Codec.Json.ContentType, succHandler, exc =>
+ var requestString = Codec.Xml.To(write);
+ client.Post(url, requestString, Codec.Xml.ContentType, succHandler, exc =>
{
context.Log.ErrorException(exc, "Error during POST.");
Interlocked.Increment(ref fail);
@@ -176,7 +176,10 @@ private void WriteFlood(CommandProcessorContext context, string eventStreamId, i
string.Format("{0}-{1}-{2}-failureSuccessRate", Keyword, clientsCnt, requestsCnt),
100*fail/(fail + succ));
- context.Success();
+ if (succ < fail)
+ context.Fail(reason:"Number of failures is greater than number of successes");
+ else
+ context.Success();
}
}
}
@@ -230,7 +230,10 @@ private void WriteFlood(CommandProcessorContext context, int clientsCnt, long re
string.Format("{0}-{1}-{2}-failureSuccessRate", Keyword, clientsCnt, requestsCnt),
100*fail/(fail + succ));
- context.Success();
+ if (succ < fail)
+ context.Fail(reason: "Number of failures is greater than number of successes");
+ else
+ context.Success();
}
}
}
@@ -124,10 +124,10 @@ private void WriteFlood(CommandProcessorContext context, int clientsCnt, int req
"DATA" + new string('*', 256),
"METADATA" + new string('$', 100))
});
- var request = Codec.Json.To(write);
+ var request = Codec.Xml.To(write);
client.Post(url,
request,
- Codec.Json.ContentType,
+ Codec.Xml.ContentType,
succHandler,
exc =>
{
@@ -176,7 +176,10 @@ private void WriteFlood(CommandProcessorContext context, int clientsCnt, int req
PerfUtils.LogTeamCityGraphData(string.Format("{0}-latency-ms", Keyword),
(int)(sw.ElapsedMilliseconds / requestsCnt));
- context.Success();
+ if (succ < fail)
+ context.Fail(reason: "Number of failures is greater than number of successes");
+ else
+ context.Success();
}
}
}
@@ -180,7 +180,10 @@ private void WriteFlood(CommandProcessorContext context, int clientsCnt, int req
PerfUtils.LogTeamCityGraphData(string.Format("{0}-latency-ms", Keyword),
(int) (sw.ElapsedMilliseconds/requestsCnt));
- context.Success();
+ if (succ < fail)
+ context.Fail(reason: "Number of failures is greater than number of successes");
+ else
+ context.Success();
}
}
}
@@ -192,10 +192,10 @@ public bool Execute(CommandProcessorContext context, string[] args)
"DATA" + dataResultingSize.ToString(" 00000 ") + new string('*', dataResultingSize),
"METADATA" + new string('$', 100))
});
- var request = Codec.Json.To(write);
+ var request = Codec.Xml.To(write);
client.Post(url,
request,
- Codec.Json.ContentType,
+ Codec.Xml.ContentType,
succHandler,
exc =>
{
@@ -253,7 +253,10 @@ public bool Execute(CommandProcessorContext context, string[] args)
string.Format("{0}-{1}-{2}-failureSuccessRate", Keyword, clientsCnt, requestsCnt),
100 * fail / (fail + succ));
- context.Success();
+ if (succ < fail)
+ context.Fail(reason: "Number of failures is greater than number of successes");
+ else
+ context.Success();
}
}
}
@@ -250,7 +250,10 @@ public bool Execute(CommandProcessorContext context, string[] args)
string.Format("{0}-{1}-{2}-failureSuccessRate", Keyword, clientsCnt, requestsCnt),
100*fail/(fail + succ));
- context.Success();
+ if (succ < fail)
+ context.Fail(reason: "Number of failures is greater than number of successes");
+ else
+ context.Success();
}
}
}

0 comments on commit 1c4f72e

Please sign in to comment.