diff --git a/Changelog.md b/Changelog.md index 2cbefca50..b1eea109a 100644 --- a/Changelog.md +++ b/Changelog.md @@ -3,6 +3,7 @@ ## 9.0.0 - Added support for .net 6 [#493](https://github.com/NEventStore/NEventStore/issues/493). +- Change / Optimization: Commit and CommitAttempt do not create internal readonly collections anymore, it can be useless given the fact we can change properties of events. ## 8.0.0 diff --git a/src/NEventStore.Persistence.AcceptanceTests/PersistenceTests.cs b/src/NEventStore.Persistence.AcceptanceTests/PersistenceTests.cs index b5c549648..7af9d8d6a 100644 --- a/src/NEventStore.Persistence.AcceptanceTests/PersistenceTests.cs +++ b/src/NEventStore.Persistence.AcceptanceTests/PersistenceTests.cs @@ -1,6 +1,6 @@ + #pragma warning disable 169 // ReSharper disable InconsistentNaming #pragma warning disable IDE1006 // Naming Styles -#pragma warning disable S101 // Types should be named in PascalCase namespace NEventStore.Persistence.AcceptanceTests { @@ -124,15 +124,13 @@ public void should_correctly_persist_the_headers() [Fact] public void should_correctly_persist_the_events() { - _persisted.Events.Count.Should().Be(_attempt.Events.Length); + _persisted.Events.Count.Should().Be(_attempt.Events.Count); } [Fact] public void should_cause_the_stream_to_be_found_in_the_list_of_streams_to_snapshot() { -#pragma warning disable RCS1202 // Avoid NullReferenceException. Persistence.GetStreamsToSnapshot(1).FirstOrDefault(x => x.StreamId == _streamId).Should().NotBeNull(); -#pragma warning restore RCS1202 // Avoid NullReferenceException. } } @@ -611,9 +609,7 @@ protected override void Because() [Fact] public void should_find_the_stream_in_the_set_of_streams_to_be_snapshot_when_within_the_threshold() { -#pragma warning disable RCS1202 // Avoid NullReferenceException. Persistence.GetStreamsToSnapshot(WithinThreshold).FirstOrDefault(x => x.StreamId == _streamId).Should().NotBeNull(); -#pragma warning restore RCS1202 // Avoid NullReferenceException. } [Fact] @@ -1288,7 +1284,7 @@ protected virtual void Dispose(bool disposing) /// This code was meant to be run right before every test in the fixture to give time /// to do further initialization before the PersistenceEngineFixture was created. /// Unfortunately the 3 frameworks - /// have very different ways of doing this: + /// have very different ways of doing this: /// - NUnit: TestFixtureSetUp /// - MSTest: ClassInitialize (not inherited, will be ignored if defined on a base class) /// - xUnit: IUseFixture + SetFixture @@ -1380,6 +1376,5 @@ protected virtual void Dispose(bool disposing) } } -#pragma warning restore S101 // Types should be named in PascalCase #pragma warning restore 169 // ReSharper disable InconsistentNaming #pragma warning restore IDE1006 // Naming Styles diff --git a/src/NEventStore.Serialization.Binary.Tests/SerializerFixture.cs b/src/NEventStore.Serialization.Binary.Tests/SerializerFixture.cs index c1167b029..4550891cc 100644 --- a/src/NEventStore.Serialization.Binary.Tests/SerializerFixture.cs +++ b/src/NEventStore.Serialization.Binary.Tests/SerializerFixture.cs @@ -7,9 +7,11 @@ namespace NEventStore.Serialization.AcceptanceTests public partial class SerializerFixture { public SerializerFixture() - { + { +#pragma warning disable CS0618 // Type or member is obsolete _createSerializer = () => - new BinarySerializer(); + new BinarySerializer(); +#pragma warning restore CS0618 // Type or member is obsolete } } } \ No newline at end of file diff --git a/src/NEventStore.Serialization.Gzip.Tests/SerializerFixture.cs b/src/NEventStore.Serialization.Gzip.Tests/SerializerFixture.cs index 23db068bf..bbc6b8724 100644 --- a/src/NEventStore.Serialization.Gzip.Tests/SerializerFixture.cs +++ b/src/NEventStore.Serialization.Gzip.Tests/SerializerFixture.cs @@ -8,8 +8,10 @@ public partial class SerializerFixture { public SerializerFixture() { +#pragma warning disable CS0618 // Type or member is obsolete _createSerializer = () => new GzipSerializer(new BinarySerializer()); +#pragma warning restore CS0618 // Type or member is obsolete } } } \ No newline at end of file diff --git a/src/NEventStore.Serialization.Rijndael.Tests/SerializerFixture.cs b/src/NEventStore.Serialization.Rijndael.Tests/SerializerFixture.cs index a901a822d..ff2cdc480 100644 --- a/src/NEventStore.Serialization.Rijndael.Tests/SerializerFixture.cs +++ b/src/NEventStore.Serialization.Rijndael.Tests/SerializerFixture.cs @@ -8,8 +8,10 @@ public partial class SerializerFixture {0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, 0x0}; public SerializerFixture() - { - _createSerializer = () => new RijndaelSerializer(new BinarySerializer(), EncryptionKey); + { +#pragma warning disable CS0618 // Type or member is obsolete + _createSerializer = () => new RijndaelSerializer(new BinarySerializer(), EncryptionKey); +#pragma warning restore CS0618 // Type or member is obsolete } } } \ No newline at end of file diff --git a/src/NEventStore.Tests/OptimisticEventStreamTests.cs b/src/NEventStore.Tests/OptimisticEventStreamTests.cs index 3a425f3ac..633c04abb 100644 --- a/src/NEventStore.Tests/OptimisticEventStreamTests.cs +++ b/src/NEventStore.Tests/OptimisticEventStreamTests.cs @@ -213,7 +213,7 @@ protected override void Because() [Fact] public void should_throw() { - _thrown.Should().BeOfType(); + _thrown.Should().BeOfType(); } } @@ -415,7 +415,7 @@ public void should_build_the_commit_with_the_headers_provided() [Fact] public void should_build_the_commit_containing_all_uncommitted_events() { - _constructed.Events.Length.Should().Be(_headers.Count); + _constructed.Events.Count.Should().Be(_headers.Count); } [Fact] diff --git a/src/NEventStore/CommitAttempt.cs b/src/NEventStore/CommitAttempt.cs index f0e5c6c31..3758311dd 100644 --- a/src/NEventStore/CommitAttempt.cs +++ b/src/NEventStore/CommitAttempt.cs @@ -4,8 +4,6 @@ namespace NEventStore { using System; using System.Collections.Generic; - using System.Collections.ObjectModel; - using System.Linq; public class CommitAttempt { @@ -25,8 +23,8 @@ public CommitAttempt( Guid commitId, int commitSequence, DateTime commitStamp, - Dictionary headers, - EventMessage[] events) + IDictionary headers, + ICollection events) : this(Bucket.Default, streamId.ToString(), streamRevision, commitId, commitSequence, commitStamp, headers, events) { } @@ -46,15 +44,15 @@ public CommitAttempt( Guid commitId, int commitSequence, DateTime commitStamp, - Dictionary headers, - EventMessage[] events) + IDictionary headers, + ICollection events) : this(Bucket.Default, streamId, streamRevision, commitId, commitSequence, commitStamp, headers, events) { } /// /// Initializes a new instance of the Commit class. /// - /// The value which identifies bucket to which the the stream and the the commit belongs + /// The value which identifies bucket to which the stream and the commit belongs /// The value which uniquely identifies the stream in a bucket to which the commit belongs. /// The value which indicates the revision of the most recent event in the stream to which this commit applies. /// The value which uniquely identifies the commit within the stream. @@ -69,8 +67,8 @@ public CommitAttempt( Guid commitId, int commitSequence, DateTime commitStamp, - Dictionary headers, - EventMessage[] events) + IDictionary headers, + ICollection events) { Guard.NotNullOrWhiteSpace(() => bucketId, bucketId); Guard.NotNullOrWhiteSpace(() => streamId, streamId); @@ -87,14 +85,14 @@ public CommitAttempt( CommitSequence = commitSequence; CommitStamp = commitStamp; Headers = headers ?? new Dictionary(); - Events = events ?? new EventMessage[0]; + Events = events ?? Array.Empty(); //Events = events == null ? // new ReadOnlyCollection(new List()) : // new ReadOnlyCollection(events.ToList()); } /// - /// Gets the value which identifies bucket to which the the stream and the the commit belongs. + /// Gets the value which identifies bucket to which the stream and the commit belongs. /// public string BucketId { get; private set; } @@ -126,12 +124,12 @@ public CommitAttempt( /// /// Gets the metadata which provides additional, unstructured information about this commit. /// - public Dictionary Headers { get; private set; } + public IDictionary Headers { get; private set; } /// /// Gets the collection of event messages to be committed as a single unit. /// - public EventMessage[] Events { get; private set; } + public ICollection Events { get; private set; } } } diff --git a/src/NEventStore/Diagnostics/PerformanceCounterPersistenceEngine.cs b/src/NEventStore/Diagnostics/PerformanceCounterPersistenceEngine.cs index 4f1edeb19..420774308 100644 --- a/src/NEventStore/Diagnostics/PerformanceCounterPersistenceEngine.cs +++ b/src/NEventStore/Diagnostics/PerformanceCounterPersistenceEngine.cs @@ -29,7 +29,7 @@ public ICommit Commit(CommitAttempt attempt) Stopwatch clock = Stopwatch.StartNew(); ICommit commit = _persistence.Commit(attempt); clock.Stop(); - _counters.CountCommit(attempt.Events.Length, clock.ElapsedMilliseconds); + _counters.CountCommit(attempt.Events.Count, clock.ElapsedMilliseconds); return commit; } diff --git a/src/NEventStore/Helpers/DisposableAction.cs b/src/NEventStore/Helpers/DisposableAction.cs index 6704a8f45..7ad0fd91e 100644 --- a/src/NEventStore/Helpers/DisposableAction.cs +++ b/src/NEventStore/Helpers/DisposableAction.cs @@ -1,14 +1,10 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using System.Threading; namespace NEventStore.Helpers { internal sealed class DisposableAction : IDisposable { - public static readonly DisposableAction Empty = new DisposableAction(null); private Action _disposeAction; @@ -22,11 +18,7 @@ public void Dispose() { // Interlocked allows the continuation to be executed only once Action dispose = Interlocked.Exchange(ref _disposeAction, null); - if (dispose != null) - { - dispose(); - } + dispose?.Invoke(); } - } } diff --git a/src/NEventStore/ICommit.cs b/src/NEventStore/ICommit.cs index 55a98b47e..1d34c34f7 100644 --- a/src/NEventStore/ICommit.cs +++ b/src/NEventStore/ICommit.cs @@ -9,7 +9,7 @@ namespace NEventStore public interface ICommit { /// - /// Gets the value which identifies bucket to which the the stream and the the commit belongs. + /// Gets the value which identifies bucket to which the stream and the commit belongs. /// string BucketId { get; } diff --git a/src/NEventStore/IEventStream.cs b/src/NEventStore/IEventStream.cs index 58e0a1117..04328f4ff 100644 --- a/src/NEventStore/IEventStream.cs +++ b/src/NEventStore/IEventStream.cs @@ -13,7 +13,7 @@ namespace NEventStore public interface IEventStream : IDisposable { /// - /// Gets the value which identifies bucket to which the the stream belongs. + /// Gets the value which identifies bucket to which the stream belongs. /// string BucketId { get; } diff --git a/src/NEventStore/OptimisticEventStore.cs b/src/NEventStore/OptimisticEventStore.cs index bf0fd5518..c27002314 100644 --- a/src/NEventStore/OptimisticEventStore.cs +++ b/src/NEventStore/OptimisticEventStore.cs @@ -22,7 +22,7 @@ public OptimisticEventStore(IPersistStreams persistence, IEnumerable(); if (_pipelineHooks.Any()) { _persistence = new PipelineHooksAwarePersistanceDecorator(persistence, _pipelineHooks); @@ -53,7 +53,7 @@ public virtual ICommit Commit(CommitAttempt attempt) return null; } - Logger.LogTrace(Resources.CommittingAttempt, attempt.CommitId, attempt.Events?.Length ?? 0); + Logger.LogTrace(Resources.CommittingAttempt, attempt.CommitId, attempt.Events?.Count ?? 0); ICommit commit = _persistence.Commit(attempt); foreach (var hook in _pipelineHooks) diff --git a/src/NEventStore/OptimisticEventStream.cs b/src/NEventStore/OptimisticEventStream.cs index 206b252cc..d5a61f5a3 100644 --- a/src/NEventStore/OptimisticEventStream.cs +++ b/src/NEventStore/OptimisticEventStream.cs @@ -72,7 +72,7 @@ public void Add(EventMessage uncommittedEvent) if (uncommittedEvent.Body == null) { - throw new ArgumentNullException(nameof(uncommittedEvent.Body)); + throw new ArgumentException(nameof(uncommittedEvent.Body)); } Logger.LogTrace(Resources.AppendingUncommittedToStream, uncommittedEvent.Body.GetType(), StreamId, BucketId); @@ -210,7 +210,7 @@ private void PersistChanges(Guid commitId) { CommitAttempt attempt = BuildCommitAttempt(commitId); - Logger.LogDebug(Resources.PersistingCommit, commitId, StreamId, BucketId, attempt.Events?.Length ?? 0); + Logger.LogDebug(Resources.PersistingCommit, commitId, StreamId, BucketId, attempt.Events?.Count ?? 0); ICommit commit = _persistence.Commit(attempt); PopulateStream(StreamRevision + 1, attempt.StreamRevision, new[] { commit }); diff --git a/src/NEventStore/OptimisticPipelineHook.cs b/src/NEventStore/OptimisticPipelineHook.cs index 690bdd195..d28fc3074 100644 --- a/src/NEventStore/OptimisticPipelineHook.cs +++ b/src/NEventStore/OptimisticPipelineHook.cs @@ -53,7 +53,7 @@ public override bool PreCommit(CommitAttempt attempt) attempt.CommitSequence, attempt.StreamId, attempt.StreamRevision, - attempt.Events.Length + attempt.Events.Count )); } @@ -65,7 +65,7 @@ public override bool PreCommit(CommitAttempt attempt) attempt.BucketId, attempt.StreamId, attempt.StreamRevision, - attempt.Events.Length + attempt.Events.Count )); } @@ -78,17 +78,17 @@ public override bool PreCommit(CommitAttempt attempt) attempt.CommitSequence, attempt.StreamId, attempt.StreamRevision, - attempt.Events.Length + attempt.Events.Count )); // beyond the end of the stream } - if (head.StreamRevision < attempt.StreamRevision - attempt.Events.Length) + if (head.StreamRevision < attempt.StreamRevision - attempt.Events.Count) { throw new StorageException(String.Format( Messages.StorageExceptionEndOfStream, head.StreamRevision, attempt.StreamRevision, - attempt.Events.Length, + attempt.Events.Count, attempt.BucketId, attempt.StreamId, attempt.StreamRevision diff --git a/src/NEventStore/Persistence/Commit.cs b/src/NEventStore/Persistence/Commit.cs index 6796f88de..0716a79fc 100644 --- a/src/NEventStore/Persistence/Commit.cs +++ b/src/NEventStore/Persistence/Commit.cs @@ -1,23 +1,12 @@ +#pragma warning disable RCS1170 // Use read-only auto-implemented property. + namespace NEventStore.Persistence { using System; using System.Collections.Generic; - using System.Collections.ObjectModel; public class Commit : ICommit { - private static readonly ReadOnlyCollection EmptyEventMessageCollection = new ReadOnlyCollection(new List()); - - private readonly string _bucketId; - private readonly string _streamId; - private readonly int _streamRevision; - private readonly Guid _commitId; - private readonly int _commitSequence; - private readonly DateTime _commitStamp; - private readonly IDictionary _headers; - private readonly ICollection _events; - private readonly Int64 _checkpointToken; - public Commit( string bucketId, string streamId, @@ -27,108 +16,40 @@ public Commit( DateTime commitStamp, Int64 checkpointToken, IDictionary headers, - IEnumerable events) + ICollection events) { - _bucketId = bucketId; - _streamId = streamId; - _streamRevision = streamRevision; - _commitId = commitId; - _commitSequence = commitSequence; - _commitStamp = commitStamp; - _checkpointToken = checkpointToken; - _headers = headers ?? new Dictionary(); - _events = events == null ? - EmptyEventMessageCollection : - new ReadOnlyCollection(new List(events)); + BucketId = bucketId; + StreamId = streamId; + StreamRevision = streamRevision; + CommitId = commitId; + CommitSequence = commitSequence; + CommitStamp = commitStamp; + CheckpointToken = checkpointToken; + Headers = headers ?? new Dictionary(); + Events = events ?? Array.Empty(); + //Events = events == null ? + // new ReadOnlyCollection(new List()) : + // new ReadOnlyCollection(new List(events)); } - /// - /// Overloaded constructor: internally we wrap the connection in a ReadOnlyCollection - /// which accepts an IList. Creating a new List from a collection of elements - /// might be an expensive operations, let's avoid useless operations if we already have a list. - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - public Commit( - string bucketId, - string streamId, - int streamRevision, - Guid commitId, - int commitSequence, - DateTime commitStamp, - Int64 checkpointToken, - IDictionary headers, - IList events) - { - _bucketId = bucketId; - _streamId = streamId; - _streamRevision = streamRevision; - _commitId = commitId; - _commitSequence = commitSequence; - _commitStamp = commitStamp; - _checkpointToken = checkpointToken; - _headers = headers ?? new Dictionary(); - _events = events == null ? - EmptyEventMessageCollection : - new ReadOnlyCollection(events); - } - - public string BucketId - { - get { return _bucketId; } - } + public string BucketId { get; private set; } - public string StreamId - { - get { return _streamId; } - } + public string StreamId { get; private set; } - public int StreamRevision - { - get { return _streamRevision; } - } + public int StreamRevision { get; private set; } - public Guid CommitId - { - get { return _commitId; } - } + public Guid CommitId { get; private set; } - public int CommitSequence - { - get { return _commitSequence; } - } + public int CommitSequence { get; private set; } - public DateTime CommitStamp - { - get { return _commitStamp; } - } + public DateTime CommitStamp { get; private set; } - public IDictionary Headers - { - get { return _headers; } - } + public IDictionary Headers { get; private set; } - public ICollection Events - { - get - { - return _events; - } - } + public ICollection Events { get; private set; } - public Int64 CheckpointToken - { - get - { - return _checkpointToken; - } - } + public Int64 CheckpointToken { get; private set; } } -} \ No newline at end of file +} + +#pragma warning restore RCS1170 // Use read-only auto-implemented property. \ No newline at end of file diff --git a/src/NEventStore/Persistence/IPersistStreams.cs b/src/NEventStore/Persistence/IPersistStreams.cs index a6c6bbe7b..b59603e8d 100644 --- a/src/NEventStore/Persistence/IPersistStreams.cs +++ b/src/NEventStore/Persistence/IPersistStreams.cs @@ -92,14 +92,14 @@ public interface IPersistStreams : IDisposable, ICommitEvents, IAccessSnapshots /// /// Completely DESTROYS the contents of ANY and ALL streams that have been successfully persisted - /// in the specified bucket. + /// in the specified bucket. /// Use with caution. /// void Purge(string bucketId); /// /// Completely DESTROYS the contents and schema (if applicable) containting ANY and ALL streams that have been - /// successfully persisted. + /// successfully persisted. /// Use with caution. /// void Drop(); diff --git a/src/NEventStore/Persistence/InMemory/InMemoryPersistenceEngine.cs b/src/NEventStore/Persistence/InMemory/InMemoryPersistenceEngine.cs index d81db8cc3..f664f0e0e 100644 --- a/src/NEventStore/Persistence/InMemory/InMemoryPersistenceEngine.cs +++ b/src/NEventStore/Persistence/InMemory/InMemoryPersistenceEngine.cs @@ -1,57 +1,57 @@ -namespace NEventStore.Persistence.InMemory -{ - using System; - using System.Collections.Concurrent; - using System.Collections.Generic; - using System.Linq; - using System.Threading; +namespace NEventStore.Persistence.InMemory +{ + using System; + using System.Collections.Concurrent; + using System.Collections.Generic; + using System.Linq; + using System.Threading; using Microsoft.Extensions.Logging; - using NEventStore.Logging; - - public class InMemoryPersistenceEngine : IPersistStreams - { + using NEventStore.Logging; + + public class InMemoryPersistenceEngine : IPersistStreams + { private static readonly ILogger Logger = LogFactory.BuildLogger(typeof(InMemoryPersistenceEngine)); - private readonly ConcurrentDictionary _buckets = new ConcurrentDictionary(); - private bool _disposed; - private int _checkpoint; - - private Bucket this[string bucketId] - { - get { return _buckets.GetOrAdd(bucketId, _ => new Bucket()); } - } - - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - - public void Initialize() - { + private readonly ConcurrentDictionary _buckets = new ConcurrentDictionary(); + private bool _disposed; + private int _checkpoint; + + private Bucket this[string bucketId] + { + get { return _buckets.GetOrAdd(bucketId, _ => new Bucket()); } + } + + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + public void Initialize() + { Logger.LogInformation(Resources.InitializingEngine); - } - - public IEnumerable GetFrom(string bucketId, string streamId, int minRevision, int maxRevision) - { - ThrowWhenDisposed(); + } + + public IEnumerable GetFrom(string bucketId, string streamId, int minRevision, int maxRevision) + { + ThrowWhenDisposed(); Logger.LogDebug(Resources.GettingAllCommitsFromRevision, streamId, bucketId, minRevision, maxRevision); - return this[bucketId].GetFrom(streamId, minRevision, maxRevision); - } - - public IEnumerable GetFrom(string bucketId, DateTime start) - { - ThrowWhenDisposed(); + return this[bucketId].GetFrom(streamId, minRevision, maxRevision); + } + + public IEnumerable GetFrom(string bucketId, DateTime start) + { + ThrowWhenDisposed(); Logger.LogDebug(Resources.GettingAllCommitsFromTime, bucketId, start); - return this[bucketId].GetFrom(start); + return this[bucketId].GetFrom(start); } - public IEnumerable GetFrom(string bucketId, Int64 checkpointToken) - { - ThrowWhenDisposed(); + public IEnumerable GetFrom(string bucketId, Int64 checkpointToken) + { + ThrowWhenDisposed(); Logger.LogDebug(Resources.GettingAllCommitsFromBucketAndCheckpoint, bucketId, checkpointToken); - return this[bucketId].GetFrom(checkpointToken); - } - + return this[bucketId].GetFrom(checkpointToken); + } + public IEnumerable GetFromTo(string bucketId, Int64 from, Int64 to) { ThrowWhenDisposed(); @@ -59,18 +59,18 @@ public IEnumerable GetFromTo(string bucketId, Int64 from, Int64 to) return this[bucketId].GetFromTo(from, to); } - public IEnumerable GetFrom(Int64 checkpointToken) - { + public IEnumerable GetFrom(Int64 checkpointToken) + { ThrowWhenDisposed(); Logger.LogDebug(Resources.GettingAllCommitsFromCheckpoint, checkpointToken); - return _buckets - .Values + return _buckets + .Values .SelectMany(b => b.GetCommits()) - .Where(c => c.CheckpointToken.CompareTo(checkpointToken) > 0) - .OrderBy(c => c.CheckpointToken) - .ToArray(); - } - + .Where(c => c.CheckpointToken.CompareTo(checkpointToken) > 0) + .OrderBy(c => c.CheckpointToken) + .ToArray(); + } + public IEnumerable GetFromTo(Int64 from, Int64 to) { ThrowWhenDisposed(); @@ -83,276 +83,275 @@ public IEnumerable GetFromTo(Int64 from, Int64 to) .ToArray(); } - public IEnumerable GetFromTo(string bucketId, DateTime start, DateTime end) - { - ThrowWhenDisposed(); + public IEnumerable GetFromTo(string bucketId, DateTime start, DateTime end) + { + ThrowWhenDisposed(); Logger.LogDebug(Resources.GettingAllCommitsFromToTime, start, end); - return this[bucketId].GetFromTo(start, end); - } - - public ICommit Commit(CommitAttempt attempt) - { - ThrowWhenDisposed(); + return this[bucketId].GetFromTo(start, end); + } + + public ICommit Commit(CommitAttempt attempt) + { + ThrowWhenDisposed(); Logger.LogDebug(Resources.AttemptingToCommit, attempt.CommitId, attempt.StreamId, attempt.BucketId, attempt.CommitSequence); - return this[attempt.BucketId].Commit(attempt, Interlocked.Increment(ref _checkpoint)); - } - - public IEnumerable GetStreamsToSnapshot(string bucketId, int maxThreshold) - { - ThrowWhenDisposed(); + return this[attempt.BucketId].Commit(attempt, Interlocked.Increment(ref _checkpoint)); + } + + public IEnumerable GetStreamsToSnapshot(string bucketId, int maxThreshold) + { + ThrowWhenDisposed(); Logger.LogDebug(Resources.GettingStreamsToSnapshot, bucketId, maxThreshold); - return this[bucketId].GetStreamsToSnapshot(maxThreshold); - } - - public ISnapshot GetSnapshot(string bucketId, string streamId, int maxRevision) - { - ThrowWhenDisposed(); + return this[bucketId].GetStreamsToSnapshot(maxThreshold); + } + + public ISnapshot GetSnapshot(string bucketId, string streamId, int maxRevision) + { + ThrowWhenDisposed(); Logger.LogDebug(Resources.GettingSnapshotForStream, bucketId, streamId, maxRevision); - return this[bucketId].GetSnapshot(streamId, maxRevision); - } - - public bool AddSnapshot(ISnapshot snapshot) - { - ThrowWhenDisposed(); + return this[bucketId].GetSnapshot(streamId, maxRevision); + } + + public bool AddSnapshot(ISnapshot snapshot) + { + ThrowWhenDisposed(); Logger.LogDebug(Resources.AddingSnapshot, snapshot.BucketId, snapshot.StreamId, snapshot.StreamRevision); - return this[snapshot.BucketId].AddSnapshot(snapshot); - } - - public void Purge() - { - ThrowWhenDisposed(); + return this[snapshot.BucketId].AddSnapshot(snapshot); + } + + public void Purge() + { + ThrowWhenDisposed(); Logger.LogWarning(Resources.PurgingStore); - foreach (var bucket in _buckets.Values) - { - bucket.Purge(); - } - } - - public void Purge(string bucketId) - { - Bucket _; - _buckets.TryRemove(bucketId, out _); - } - - public void Drop() - { - _buckets.Clear(); - } - - public void DeleteStream(string bucketId, string streamId) - { + foreach (var bucket in _buckets.Values) + { + bucket.Purge(); + } + } + + public void Purge(string bucketId) + { + Bucket _; + _buckets.TryRemove(bucketId, out _); + } + + public void Drop() + { + _buckets.Clear(); + } + + public void DeleteStream(string bucketId, string streamId) + { Logger.LogWarning(Resources.DeletingStream, streamId, bucketId); - if (!_buckets.TryGetValue(bucketId, out Bucket bucket)) - { - return; - } - bucket.DeleteStream(streamId); - } - - public bool IsDisposed - { - get { return _disposed; } - } - + if (!_buckets.TryGetValue(bucketId, out Bucket bucket)) + { + return; + } + bucket.DeleteStream(streamId); + } + + public bool IsDisposed + { + get { return _disposed; } + } + #pragma warning disable RCS1163 // Unused parameter. #pragma warning disable IDE0060 // Remove unused parameter - private void Dispose(bool disposing) + private void Dispose(bool disposing) #pragma warning restore IDE0060 // Remove unused parameter #pragma warning restore RCS1163 // Unused parameter. - { - _disposed = true; + { + _disposed = true; Logger.LogInformation(Resources.DisposingEngine); - } - - private void ThrowWhenDisposed() - { - if (!_disposed) - { - return; - } - + } + + private void ThrowWhenDisposed() + { + if (!_disposed) + { + return; + } + Logger.LogWarning(Resources.AlreadyDisposed); - throw new ObjectDisposedException(Resources.AlreadyDisposed); - } - - private class InMemoryCommit : Commit + throw new ObjectDisposedException(Resources.AlreadyDisposed); + } + + private class InMemoryCommit : Commit { - public InMemoryCommit( - string bucketId, - string streamId, - int streamRevision, - Guid commitId, - int commitSequence, + public InMemoryCommit( + string bucketId, + string streamId, + int streamRevision, + Guid commitId, + int commitSequence, DateTime commitStamp, - Int64 checkpointToken, - IDictionary headers, - IEnumerable events) - : base(bucketId, streamId, streamRevision, commitId, commitSequence, commitStamp, checkpointToken, headers, - events is IList list ? list : events) - { } - } - - private class IdentityForConcurrencyConflictDetection - { - protected bool Equals(IdentityForConcurrencyConflictDetection other) - { + Int64 checkpointToken, + IDictionary headers, + ICollection events) + : base(bucketId, streamId, streamRevision, commitId, commitSequence, commitStamp, checkpointToken, headers, events) + { } + } + + private class IdentityForConcurrencyConflictDetection + { + protected bool Equals(IdentityForConcurrencyConflictDetection other) + { return string.Equals(this.streamId, other.streamId) && string.Equals(this.bucketId, other.bucketId) - && this.commitSequence == other.commitSequence; - } - - public override bool Equals(object obj) - { - if (obj is null) - { - return false; - } - if (ReferenceEquals(this, obj)) - { - return true; - } - if (obj.GetType() != this.GetType()) - { - return false; - } - return Equals((IdentityForConcurrencyConflictDetection)obj); - } - - public override int GetHashCode() - { - unchecked - { - int hashCode = this.streamId.GetHashCode(); - hashCode = (hashCode * 397) ^ this.bucketId.GetHashCode(); - return (hashCode * 397) ^ this.commitSequence; - } - } - - private readonly int commitSequence; - - private readonly string bucketId; - - private readonly string streamId; - - public IdentityForConcurrencyConflictDetection(CommitAttempt commitAttempt) - { - bucketId = commitAttempt.BucketId; - streamId = commitAttempt.StreamId; - commitSequence = commitAttempt.CommitSequence; - } - - public IdentityForConcurrencyConflictDetection(Commit commit) - { - bucketId = commit.BucketId; - streamId = commit.StreamId; - commitSequence = commit.CommitSequence; - } - } - - private class IdentityForDuplicationDetection - { - protected bool Equals(IdentityForDuplicationDetection other) - { + && this.commitSequence == other.commitSequence; + } + + public override bool Equals(object obj) + { + if (obj is null) + { + return false; + } + if (ReferenceEquals(this, obj)) + { + return true; + } + if (obj.GetType() != this.GetType()) + { + return false; + } + return Equals((IdentityForConcurrencyConflictDetection)obj); + } + + public override int GetHashCode() + { + unchecked + { + int hashCode = this.streamId.GetHashCode(); + hashCode = (hashCode * 397) ^ this.bucketId.GetHashCode(); + return (hashCode * 397) ^ this.commitSequence; + } + } + + private readonly int commitSequence; + + private readonly string bucketId; + + private readonly string streamId; + + public IdentityForConcurrencyConflictDetection(CommitAttempt commitAttempt) + { + bucketId = commitAttempt.BucketId; + streamId = commitAttempt.StreamId; + commitSequence = commitAttempt.CommitSequence; + } + + public IdentityForConcurrencyConflictDetection(Commit commit) + { + bucketId = commit.BucketId; + streamId = commit.StreamId; + commitSequence = commit.CommitSequence; + } + } + + private class IdentityForDuplicationDetection + { + protected bool Equals(IdentityForDuplicationDetection other) + { return string.Equals(this.streamId, other.streamId) && string.Equals(this.bucketId, other.bucketId) - && this.commitId.Equals(other.commitId); - } - - public override bool Equals(object obj) - { - if (obj is null) - { - return false; - } - if (ReferenceEquals(this, obj)) - { - return true; - } - if (obj.GetType() != this.GetType()) - { - return false; - } - return Equals((IdentityForDuplicationDetection)obj); - } - - public override int GetHashCode() - { - unchecked - { - int hashCode = this.streamId.GetHashCode(); - hashCode = (hashCode * 397) ^ this.bucketId.GetHashCode(); - return (hashCode * 397) ^ this.commitId.GetHashCode(); - } - } - - private readonly Guid commitId; - - private readonly string bucketId; - - private readonly string streamId; - - public IdentityForDuplicationDetection(CommitAttempt commitAttempt) - { - bucketId = commitAttempt.BucketId; - streamId = commitAttempt.StreamId; - commitId = commitAttempt.CommitId; - } - - public IdentityForDuplicationDetection(Commit commit) - { - bucketId = commit.BucketId; - streamId = commit.StreamId; - commitId = commit.CommitId; - } - } - - private class Bucket - { - private readonly IList _commits = new List(); - private readonly ICollection _potentialDuplicates = new HashSet(); + && this.commitId.Equals(other.commitId); + } + + public override bool Equals(object obj) + { + if (obj is null) + { + return false; + } + if (ReferenceEquals(this, obj)) + { + return true; + } + if (obj.GetType() != this.GetType()) + { + return false; + } + return Equals((IdentityForDuplicationDetection)obj); + } + + public override int GetHashCode() + { + unchecked + { + int hashCode = this.streamId.GetHashCode(); + hashCode = (hashCode * 397) ^ this.bucketId.GetHashCode(); + return (hashCode * 397) ^ this.commitId.GetHashCode(); + } + } + + private readonly Guid commitId; + + private readonly string bucketId; + + private readonly string streamId; + + public IdentityForDuplicationDetection(CommitAttempt commitAttempt) + { + bucketId = commitAttempt.BucketId; + streamId = commitAttempt.StreamId; + commitId = commitAttempt.CommitId; + } + + public IdentityForDuplicationDetection(Commit commit) + { + bucketId = commit.BucketId; + streamId = commit.StreamId; + commitId = commit.CommitId; + } + } + + private class Bucket + { + private readonly IList _commits = new List(); + private readonly ICollection _potentialDuplicates = new HashSet(); private readonly ICollection _potentialConflicts = new HashSet(); - public IEnumerable GetCommits() - { - lock (_commits) - { - return _commits.ToArray(); - } - } - - private readonly ICollection _heads = new LinkedList(); - private readonly ICollection _snapshots = new LinkedList(); - private readonly IDictionary _stamps = new Dictionary(); - - public IEnumerable GetFrom(string streamId, int minRevision, int maxRevision) - { - lock (_commits) - { - return _commits - .Where(x => x.StreamId == streamId && x.StreamRevision >= minRevision && (x.StreamRevision - x.Events.Count + 1) <= maxRevision) - .OrderBy(c => c.CommitSequence) - .ToArray(); - } - } - - public IEnumerable GetFrom(DateTime start) - { - Guid commitId = _stamps.Where(x => x.Value >= start).Select(x => x.Key).FirstOrDefault(); - if (commitId == Guid.Empty) - { - return Enumerable.Empty(); - } - - InMemoryCommit startingCommit = _commits.FirstOrDefault(x => x.CommitId == commitId); - return _commits.Skip(_commits.IndexOf(startingCommit)); + public IEnumerable GetCommits() + { + lock (_commits) + { + return _commits.ToArray(); + } + } + + private readonly ICollection _heads = new LinkedList(); + private readonly ICollection _snapshots = new LinkedList(); + private readonly IDictionary _stamps = new Dictionary(); + + public IEnumerable GetFrom(string streamId, int minRevision, int maxRevision) + { + lock (_commits) + { + return _commits + .Where(x => x.StreamId == streamId && x.StreamRevision >= minRevision && (x.StreamRevision - x.Events.Count + 1) <= maxRevision) + .OrderBy(c => c.CommitSequence) + .ToArray(); + } + } + + public IEnumerable GetFrom(DateTime start) + { + Guid commitId = _stamps.Where(x => x.Value >= start).Select(x => x.Key).FirstOrDefault(); + if (commitId == Guid.Empty) + { + return Enumerable.Empty(); + } + + InMemoryCommit startingCommit = _commits.FirstOrDefault(x => x.CommitId == commitId); + return _commits.Skip(_commits.IndexOf(startingCommit)); + } + + public IEnumerable GetFrom(Int64 checkpoint) + { + InMemoryCommit startingCommit = _commits.FirstOrDefault(x => x.CheckpointToken.CompareTo(checkpoint) == 0); + return _commits.Skip(_commits.IndexOf(startingCommit) + 1 /* GetFrom => after the checkpoint*/); } - public IEnumerable GetFrom(Int64 checkpoint) - { - InMemoryCommit startingCommit = _commits.FirstOrDefault(x => x.CheckpointToken.CompareTo(checkpoint) == 0); - return _commits.Skip(_commits.IndexOf(startingCommit) + 1 /* GetFrom => after the checkpoint*/); - } - public IEnumerable GetFromTo(Int64 from, Int64 to) { InMemoryCommit startingCommit = _commits.FirstOrDefault(x => x.CheckpointToken.CompareTo(from) == 0); @@ -360,94 +359,94 @@ public IEnumerable GetFromTo(Int64 from, Int64 to) .TakeWhile(c => c.CheckpointToken <= to); } - public IEnumerable GetFromTo(DateTime start, DateTime end) - { - IEnumerable selectedCommitIds = _stamps.Where(x => x.Value >= start && x.Value < end).Select(x => x.Key).ToArray(); - Guid firstCommitId = selectedCommitIds.FirstOrDefault(); - Guid lastCommitId = selectedCommitIds.LastOrDefault(); - if (lastCommitId == Guid.Empty && lastCommitId == Guid.Empty) - { - return Enumerable.Empty(); - } - InMemoryCommit startingCommit = _commits.FirstOrDefault(x => x.CommitId == firstCommitId); - InMemoryCommit endingCommit = _commits.FirstOrDefault(x => x.CommitId == lastCommitId); - int startingCommitIndex = (startingCommit == null) ? 0 : _commits.IndexOf(startingCommit); - int endingCommitIndex = (endingCommit == null) ? _commits.Count - 1 : _commits.IndexOf(endingCommit); - int numberToTake = endingCommitIndex - startingCommitIndex + 1; - - return _commits.Skip(_commits.IndexOf(startingCommit)).Take(numberToTake); + public IEnumerable GetFromTo(DateTime start, DateTime end) + { + IEnumerable selectedCommitIds = _stamps.Where(x => x.Value >= start && x.Value < end).Select(x => x.Key).ToArray(); + Guid firstCommitId = selectedCommitIds.FirstOrDefault(); + Guid lastCommitId = selectedCommitIds.LastOrDefault(); + if (lastCommitId == Guid.Empty && lastCommitId == Guid.Empty) + { + return Enumerable.Empty(); + } + InMemoryCommit startingCommit = _commits.FirstOrDefault(x => x.CommitId == firstCommitId); + InMemoryCommit endingCommit = _commits.FirstOrDefault(x => x.CommitId == lastCommitId); + int startingCommitIndex = (startingCommit == null) ? 0 : _commits.IndexOf(startingCommit); + int endingCommitIndex = (endingCommit == null) ? _commits.Count - 1 : _commits.IndexOf(endingCommit); + int numberToTake = endingCommitIndex - startingCommitIndex + 1; + + return _commits.Skip(_commits.IndexOf(startingCommit)).Take(numberToTake); } - public ICommit Commit(CommitAttempt attempt, Int64 checkpoint) - { - lock (_commits) - { - DetectDuplicate(attempt); - var commit = new InMemoryCommit(attempt.BucketId, - attempt.StreamId, - attempt.StreamRevision, - attempt.CommitId, - attempt.CommitSequence, - attempt.CommitStamp, - checkpoint, - attempt.Headers, - attempt.Events); - if (_potentialConflicts.Contains(new IdentityForConcurrencyConflictDetection(commit))) - { - throw new ConcurrencyException(); - } - _stamps[commit.CommitId] = commit.CommitStamp; - _commits.Add(commit); - _potentialDuplicates.Add(new IdentityForDuplicationDetection(commit)); - _potentialConflicts.Add(new IdentityForConcurrencyConflictDetection(commit)); - IStreamHead head = _heads.FirstOrDefault(x => x.StreamId == commit.StreamId); - _heads.Remove(head); + public ICommit Commit(CommitAttempt attempt, Int64 checkpoint) + { + lock (_commits) + { + DetectDuplicate(attempt); + var commit = new InMemoryCommit(attempt.BucketId, + attempt.StreamId, + attempt.StreamRevision, + attempt.CommitId, + attempt.CommitSequence, + attempt.CommitStamp, + checkpoint, + attempt.Headers, + attempt.Events); + if (_potentialConflicts.Contains(new IdentityForConcurrencyConflictDetection(commit))) + { + throw new ConcurrencyException(); + } + _stamps[commit.CommitId] = commit.CommitStamp; + _commits.Add(commit); + _potentialDuplicates.Add(new IdentityForDuplicationDetection(commit)); + _potentialConflicts.Add(new IdentityForConcurrencyConflictDetection(commit)); + IStreamHead head = _heads.FirstOrDefault(x => x.StreamId == commit.StreamId); + _heads.Remove(head); Logger.LogDebug(Resources.UpdatingStreamHead, commit.StreamId, commit.BucketId); - int snapshotRevision = head?.SnapshotRevision ?? 0; - _heads.Add(new StreamHead(commit.BucketId, commit.StreamId, commit.StreamRevision, snapshotRevision)); - return commit; - } - } - - private void DetectDuplicate(CommitAttempt attempt) - { - if (_potentialDuplicates.Contains(new IdentityForDuplicationDetection(attempt))) - { + int snapshotRevision = head?.SnapshotRevision ?? 0; + _heads.Add(new StreamHead(commit.BucketId, commit.StreamId, commit.StreamRevision, snapshotRevision)); + return commit; + } + } + + private void DetectDuplicate(CommitAttempt attempt) + { + if (_potentialDuplicates.Contains(new IdentityForDuplicationDetection(attempt))) + { throw new DuplicateCommitException(String.Format(Messages.DuplicateCommitIdException, attempt.StreamId, attempt.BucketId, attempt.CommitId)); - } - } - - public IEnumerable GetStreamsToSnapshot(int maxThreshold) - { - lock (_commits) - { - return _heads - .Where(x => x.HeadRevision >= x.SnapshotRevision + maxThreshold) - .Select(stream => new StreamHead(stream.BucketId, stream.StreamId, stream.HeadRevision, stream.SnapshotRevision)); - } - } - - public ISnapshot GetSnapshot(string streamId, int maxRevision) - { - lock (_commits) - { - return _snapshots - .Where(x => x.StreamId == streamId && x.StreamRevision <= maxRevision) - .OrderByDescending(x => x.StreamRevision) - .FirstOrDefault(); - } - } - - public bool AddSnapshot(ISnapshot snapshot) - { - lock (_commits) - { - IStreamHead currentHead = _heads.FirstOrDefault(h => h.StreamId == snapshot.StreamId); - if (currentHead == null) - { - return false; - } - + } + } + + public IEnumerable GetStreamsToSnapshot(int maxThreshold) + { + lock (_commits) + { + return _heads + .Where(x => x.HeadRevision >= x.SnapshotRevision + maxThreshold) + .Select(stream => new StreamHead(stream.BucketId, stream.StreamId, stream.HeadRevision, stream.SnapshotRevision)); + } + } + + public ISnapshot GetSnapshot(string streamId, int maxRevision) + { + lock (_commits) + { + return _snapshots + .Where(x => x.StreamId == streamId && x.StreamRevision <= maxRevision) + .OrderByDescending(x => x.StreamRevision) + .FirstOrDefault(); + } + } + + public bool AddSnapshot(ISnapshot snapshot) + { + lock (_commits) + { + IStreamHead currentHead = _heads.FirstOrDefault(h => h.StreamId == snapshot.StreamId); + if (currentHead == null) + { + return false; + } + // if the snapshot is already there do NOT add it (follow the SQL implementation) // and the original GetSnapshot behavior which was to return the first one that was // added to the collection @@ -456,46 +455,46 @@ public bool AddSnapshot(ISnapshot snapshot) return false; } - _snapshots.Add(snapshot); - _heads.Remove(currentHead); - _heads.Add(new StreamHead(currentHead.BucketId, currentHead.StreamId, currentHead.HeadRevision, snapshot.StreamRevision)); - } - return true; - } - - public void Purge() - { - lock (_commits) - { - _commits.Clear(); - _snapshots.Clear(); - _heads.Clear(); - _potentialConflicts.Clear(); - _potentialDuplicates.Clear(); - } - } - - public void DeleteStream(string streamId) - { - lock (_commits) - { - InMemoryCommit[] commits = _commits.Where(c => c.StreamId == streamId).ToArray(); - foreach (var commit in commits) - { - _commits.Remove(commit); - } - ISnapshot[] snapshots = _snapshots.Where(s => s.StreamId == streamId).ToArray(); - foreach (var snapshot in snapshots) - { - _snapshots.Remove(snapshot); - } - IStreamHead streamHead = _heads.SingleOrDefault(s => s.StreamId == streamId); - if (streamHead != null) - { - _heads.Remove(streamHead); - } - } - } - } - } + _snapshots.Add(snapshot); + _heads.Remove(currentHead); + _heads.Add(new StreamHead(currentHead.BucketId, currentHead.StreamId, currentHead.HeadRevision, snapshot.StreamRevision)); + } + return true; + } + + public void Purge() + { + lock (_commits) + { + _commits.Clear(); + _snapshots.Clear(); + _heads.Clear(); + _potentialConflicts.Clear(); + _potentialDuplicates.Clear(); + } + } + + public void DeleteStream(string streamId) + { + lock (_commits) + { + InMemoryCommit[] commits = _commits.Where(c => c.StreamId == streamId).ToArray(); + foreach (var commit in commits) + { + _commits.Remove(commit); + } + ISnapshot[] snapshots = _snapshots.Where(s => s.StreamId == streamId).ToArray(); + foreach (var snapshot in snapshots) + { + _snapshots.Remove(snapshot); + } + IStreamHead streamHead = _heads.SingleOrDefault(s => s.StreamId == streamId); + if (streamHead != null) + { + _heads.Remove(streamHead); + } + } + } + } + } } \ No newline at end of file diff --git a/src/NEventStore/Persistence/StreamHead.cs b/src/NEventStore/Persistence/StreamHead.cs index cc10e99c2..79722a1c9 100644 --- a/src/NEventStore/Persistence/StreamHead.cs +++ b/src/NEventStore/Persistence/StreamHead.cs @@ -1,79 +1,78 @@ -namespace NEventStore.Persistence -{ - using System.Collections.Generic; - - /// - /// Indicates the most recent information representing the head of a given stream. - /// - public class StreamHead : IStreamHead - { - /// - /// Initializes a new instance of the StreamHead class. - /// - /// The value which uniquely identifies bucket the stream belongs to. - /// The value which uniquely identifies the stream in the bucket where the last snapshot exceeds the allowed threshold. - /// The value which indicates the revision, length, or number of events committed to the stream. - /// The value which indicates the revision at which the last snapshot was taken. - public StreamHead(string bucketId, string streamId, int headRevision, int snapshotRevision) - : this() - { - BucketId = bucketId; - StreamId = streamId; - HeadRevision = headRevision; - SnapshotRevision = snapshotRevision; +#pragma warning disable RCS1170 // Use read-only auto-implemented property. + +namespace NEventStore.Persistence +{ + using System.Collections.Generic; + + /// + /// Indicates the most recent information representing the head of a given stream. + /// + public class StreamHead : IStreamHead + { + /// + /// Initializes a new instance of the StreamHead class. + /// + /// The value which uniquely identifies bucket the stream belongs to. + /// The value which uniquely identifies the stream in the bucket where the last snapshot exceeds the allowed threshold. + /// The value which indicates the revision, length, or number of events committed to the stream. + /// The value which indicates the revision at which the last snapshot was taken. + public StreamHead(string bucketId, string streamId, int headRevision, int snapshotRevision) + : this() + { + BucketId = bucketId; + StreamId = streamId; + HeadRevision = headRevision; + SnapshotRevision = snapshotRevision; } - private static readonly IEqualityComparer StreamIdBucketIdComparerInstance = new StreamHeadEqualityComparer(); - - public static IEqualityComparer StreamIdBucketIdComparer - { - get { return StreamIdBucketIdComparerInstance; } - } - - /// - /// Initializes a new instance of the StreamHead class. - /// - protected StreamHead() - { } - - /// - /// Gets the value which uniquely identifies the stream where the last snapshot exceeds the allowed threshold. - /// - public string BucketId { get; private set; } - - /// - /// Gets the value which uniquely identifies the stream where the last snapshot exceeds the allowed threshold. - /// - public string StreamId { get; private set; } - - /// - /// Gets the value which indicates the revision, length, or number of events committed to the stream. - /// - public int HeadRevision { get; private set; } - - /// - /// Gets the value which indicates the revision at which the last snapshot was taken. - /// - public int SnapshotRevision { get; private set; } - - /// - /// Determines whether the specified object is equal to the current object. - /// - /// The object to compare with the current object. - /// If the two objects are equal, returns true; otherwise false. - public override bool Equals(object obj) - { + public static IEqualityComparer StreamIdBucketIdComparer { get; } = new StreamHeadEqualityComparer(); + + /// + /// Initializes a new instance of the StreamHead class. + /// + protected StreamHead() + { } + + /// + /// Gets the value which uniquely identifies the stream where the last snapshot exceeds the allowed threshold. + /// + public string BucketId { get; private set; } + + /// + /// Gets the value which uniquely identifies the stream where the last snapshot exceeds the allowed threshold. + /// + public string StreamId { get; private set; } + + /// + /// Gets the value which indicates the revision, length, or number of events committed to the stream. + /// + public int HeadRevision { get; private set; } + + /// + /// Gets the value which indicates the revision at which the last snapshot was taken. + /// + public int SnapshotRevision { get; private set; } + + /// + /// Determines whether the specified object is equal to the current object. + /// + /// The object to compare with the current object. + /// If the two objects are equal, returns true; otherwise false. + public override bool Equals(object obj) + { return obj is StreamHead commit - && commit.StreamId == StreamId; - } - - /// - /// Returns the hash code for this instance. - /// - /// The hash code for this instance. - public override int GetHashCode() - { - return StreamId.GetHashCode(); - } - } -} \ No newline at end of file + && commit.StreamId == StreamId; + } + + /// + /// Returns the hash code for this instance. + /// + /// The hash code for this instance. + public override int GetHashCode() + { + return StreamId.GetHashCode(); + } + } +} + +#pragma warning restore RCS1170 // Use read-only auto-implemented property. \ No newline at end of file diff --git a/src/NEventStore/Serialization/BinarySerializer.cs b/src/NEventStore/Serialization/BinarySerializer.cs index da7305bf0..c99dce90c 100644 --- a/src/NEventStore/Serialization/BinarySerializer.cs +++ b/src/NEventStore/Serialization/BinarySerializer.cs @@ -1,11 +1,16 @@ namespace NEventStore.Serialization { + using System; using System.IO; using System.Runtime.Serialization; using System.Runtime.Serialization.Formatters.Binary; using Microsoft.Extensions.Logging; using NEventStore.Logging; + /// + /// Delegates to to perform the actual serialization. + /// + [Obsolete("BinaryFormatter serialization is obsolete and should not be used. See https://aka.ms/binaryformatter for more information.")] public class BinarySerializer : ISerialize { private static readonly ILogger Logger = LogFactory.BuildLogger(typeof (BinarySerializer)); diff --git a/src/NEventStore/SerializationWireupExtensions.cs b/src/NEventStore/SerializationWireupExtensions.cs index 87c0d65eb..c3b572e57 100644 --- a/src/NEventStore/SerializationWireupExtensions.cs +++ b/src/NEventStore/SerializationWireupExtensions.cs @@ -3,11 +3,13 @@ namespace NEventStore using Logging; using Microsoft.Extensions.Logging; using NEventStore.Serialization; + using System; public static class SerializationWireupExtensions { private static readonly ILogger Logger = LogFactory.BuildLogger(typeof(PersistenceWireup)); + [Obsolete("BinaryFormatter serialization is obsolete and should not be used. See https://aka.ms/binaryformatter for more information.")] public static SerializationWireup UsingBinarySerialization(this PersistenceWireup wireup) { Logger.LogInformation(Resources.WireupSetSerializer, "Binary");