Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added 2023 copyright headers, cleaned up code #281

Merged
merged 1 commit into from
Feb 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Akka.Persistence.SqlServer.sln
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{D8BAD8E8
build.cmd = build.cmd
build.fsx = build.fsx
build.sh = build.sh
src\common.props = src\common.props
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{85A25CFE-0B51-45FC-9C5E-271F9557F8D3}"
Expand Down
51 changes: 38 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ Akka Persistence journal and snapshot store backed by SQL Server database.

### Configuration

Both journal and snapshot store share the same configuration keys (however they resides in separate scopes, so they are definied distinctly for either journal or snapshot store):
Both journal and snapshot store share the same configuration keys (however they resides in separate scopes, so they are
definied distinctly for either journal or snapshot store):

Remember that connection string must be provided separately to Journal and Snapshot Store.

Please also note that unless circuit breaker settings are configured, the defaults from Akka.Persistence will be used. If these defaults are less than the Database connection timeout (default or provided in connection string) and provided command timeout, Warnings will be logged upon initialization of the Journal or Snapshot Store.
Please also note that unless circuit breaker settings are configured, the defaults from Akka.Persistence will be used.
If these defaults are less than the Database connection timeout (default or provided in connection string) and provided
command timeout, Warnings will be logged upon initialization of the Journal or Snapshot Store.

```hocon
akka.persistence{
Expand Down Expand Up @@ -83,16 +86,28 @@ akka.persistence{

### Batching journal

Since version 1.1.3 an alternative, experimental type of the journal has been released, known as batching journal. It's optimized for concurrent writes made by multiple persistent actors, thanks to the ability of batching multiple SQL operations to be executed within the same database connection. In some of those situations we've noticed over an order of magnitude in event write speed.
Since version 1.1.3 an alternative, experimental type of the journal has been released, known as batching journal. It's
optimized for concurrent writes made by multiple persistent actors, thanks to the ability of batching multiple SQL
operations to be executed within the same database connection. In some of those situations we've noticed over an order
of magnitude in event write speed.

To use batching journal, simply change `akka.persistence.journal.sql-server.class` to *Akka.Persistence.SqlServer.Journal.BatchingSqlServerJournal, Akka.Persistence.SqlServer*.
To use batching journal, simply change `akka.persistence.journal.sql-server.class` to
*Akka.Persistence.SqlServer.Journal.BatchingSqlServerJournal, Akka.Persistence.SqlServer*.

Additionally to the existing settings, batching journal introduces few more:

- `isolation-level` to define isolation level for transactions used withing event reads/writes. Possible options: *unspecified* (default), *chaos*, *read-committed*, *read-uncommitted*, *repeatable-read*, *serializable* or *snapshot*.
- `max-concurrent-operations` is used to limit the maximum number of database connections used by this journal. You can use them in situations when you want to partition the same ADO.NET pool between multiple components. Current default: *64*.
- `max-batch-size` defines the maximum number of SQL operations, that are allowed to be executed using the same connection. When there are more operations, they will chunked into subsequent connections. Current default: *100*.
- `max-buffer-size` defines maximum buffer capacity for the requests send to a journal. Once buffer gets overflown, a journal will call `OnBufferOverflow` method. By default it will reject all incoming requests until the buffer space gets freed. You can inherit from `BatchingSqlServerJournal` and override that method to provide a custom backpressure strategy. Current default: *500 000*.
- `isolation-level` to define isolation level for transactions used withing event reads/writes. Possible options:
*unspecified* (default), *chaos*, *read-committed*, *read-uncommitted*, *repeatable-read*, *serializable* or
*snapshot*.
- `max-concurrent-operations` is used to limit the maximum number of database connections used by this journal. You can
use them in situations when you want to partition the same ADO.NET pool between multiple components. Current default:
*64*.
- `max-batch-size` defines the maximum number of SQL operations, that are allowed to be executed using the same
connection. When there are more operations, they will chunked into subsequent connections. Current default: *100*.
- `max-buffer-size` defines maximum buffer capacity for the requests send to a journal. Once buffer gets overflown, a
journal will call `OnBufferOverflow` method. By default it will reject all incoming requests until the buffer space
gets freed. You can inherit from `BatchingSqlServerJournal` and override that method to provide a custom backpressure
strategy. Current default: *500 000*.

### Table Schema

Expand Down Expand Up @@ -129,7 +144,11 @@ CREATE TABLE {your_metadata_table_name} (
CONSTRAINT PK_{your_metadata_table_name} PRIMARY KEY (PersistenceID, SequenceNr)
);
```
Underneath Akka.Persistence.SqlServer uses a raw ADO.NET commands. You may choose not to use a dedicated built in ones, but to create your own being better fit for your use case. To do so, you have to create your own versions of `IJournalQueryBuilder` and `IJournalQueryMapper` (for custom journals) or `ISnapshotQueryBuilder` and `ISnapshotQueryMapper` (for custom snapshot store) and then attach inside journal, just like in the example below:

Underneath Akka.Persistence.SqlServer uses a raw ADO.NET commands. You may choose not to use a dedicated built in ones,
but to create your own being better fit for your use case. To do so, you have to create your own versions
of `IJournalQueryBuilder` and `IJournalQueryMapper` (for custom journals) or `ISnapshotQueryBuilder`
and `ISnapshotQueryMapper` (for custom snapshot store) and then attach inside journal, just like in the example below:

```C#
class MyCustomSqlServerJournal: Akka.Persistence.SqlServer.Journal.SqlServerJournal
Expand Down Expand Up @@ -162,6 +181,7 @@ ALTER TABLE {your_journal_table_name} ADD CONSTRAINT QU_{your_journal_table_name
```

#### From 1.0.8 to 1.1.0

```SQL
-- helper function to convert between DATETIME2 and BIGINT as .NET ticks
-- taken from: http://stackoverflow.com/questions/7386634/convert-sql-server-datetime-object-to-bigint-net-ticks
Expand Down Expand Up @@ -212,6 +232,7 @@ ALTER TABLE {your_journal_table_name} ADD Tags NVARCHAR(100) NULL;
```

#### From 1.0.6 to 1.0.8

```SQL
CREATE TABLE {your_metadata_table_name} (
PersistenceID NVARCHAR(255) NOT NULL,
Expand All @@ -226,6 +247,7 @@ ALTER TABLE {your_journal_table_name} ALTER COLUMN PersistenceID NVARCHAR(255) [
```

#### From 1.0.4 to 1.0.5

```SQL
ALTER TABLE dbo.EventJournal ADD Timestamp DATETIME2 NOT NULL DEFAULT GETDATE();
ALTER TABLE dbo.EventJournal DROP CONSTRAINT PK_EventJournal;
Expand All @@ -241,9 +263,12 @@ The SqlServer tests are packaged and run as part of the default "All" build task

In order to run the tests, you must do the following things:

1. Download and install SQL Server Express 2014 from: http://www.microsoft.com/en-us/server-cloud/Products/sql-server-editions/sql-server-express.aspx
1. Download and install SQL Server Express 2014
from: http://www.microsoft.com/en-us/server-cloud/Products/sql-server-editions/sql-server-express.aspx
2. Install SQL Server Express with the default settings.
3. Create a new user called `akkadotnet` with the password `akkadotnet` and give them rights to create new databases on the server.
4. The default connection string uses the following credentials: `Data Source=localhost\SQLEXPRESS;Database=akka_persistence_tests;User Id=akkadotnet;
Password=akkadotnet;`
3. Create a new user called `akkadotnet` with the password `akkadotnet` and give them rights to create new databases on
the server.
4. The default connection string uses the following
credentials: `Data Source=localhost\SQLEXPRESS;Database=akka_persistence_tests;User Id=akkadotnet;
Password=akkadotnet;`
5. A custom app.config file can be used and needs to be placed in the same folder as the dll
6 changes: 6 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
#### 1.4.35 March 23 2022 ####

* [Update Akka.NET to v1.4.35](https://github.com/akkadotnet/akka.net/releases/tag/1.4.35)

#### 1.4.32 January 19 2022 ####

* [Update Akka.NET to v1.4.32](https://github.com/akkadotnet/akka.net/releases/tag/1.4.32)

#### 1.4.31 December 20 2021 ####

* [Update Akka.NET to v1.4.31](https://github.com/akkadotnet/akka.net/releases/tag/1.4.31)

#### 1.4.29 December 15 2021 ####

* [Update Akka.NET to v1.4.29](https://github.com/akkadotnet/akka.net/releases/tag/1.4.29)
* [Update Microsoft.Data.SqlClient to v3.0.1](https://github.com/akkadotnet/Akka.Persistence.SqlServer/pull/223)

#### 1.4.25 September 9 2021 ####

* [Update Akka.NET to v1.4.25](https://github.com/akkadotnet/akka.net/releases/tag/1.4.25)
* [Update Microsoft.Data.SqlClient to v3.0.0](https://github.com/akkadotnet/Akka.Persistence.SqlServer/pull/212)

#### 1.4.18 May 12 2020 ####

* Upgrades to [Akka.NET v1.4.18](https://github.com/akkadotnet/akka.net/releases/tag/1.4.18)
* [Added Support for Microsoft AD Authentication](https://github.com/akkadotnet/Akka.Persistence.SqlServer/issues/203)
* [Load string parameters column sizes to reduce SqlServer query plans count](https://github.com/akkadotnet/Akka.Persistence.SqlServer/pull/197)
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\common.props" />
<Import Project="..\common.props"/>
<PropertyGroup Condition="'$(OS)' == 'Windows_NT'">
<TargetFrameworks>$(NetFrameworkTestVersion);$(NetCoreTestVersion)</TargetFrameworks>
<TargetFrameworks>$(NetFrameworkTestVersion);$(NetCoreTestVersion)</TargetFrameworks>
</PropertyGroup>

<!-- disable .NET Framework (Mono) on Linux-->
<PropertyGroup Condition="'$(OS)' != 'Windows_NT'">
<TargetFrameworks>$(NetCoreTestVersion)</TargetFrameworks>
<TargetFrameworks>$(NetCoreTestVersion)</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Data.SqlClient" Version="3.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(TestSdkVersion)" />
<PackageReference Include="Akka.Persistence.Sql.TestKit" Version="$(AkkaVersion)" />
<PackageReference Include="Docker.DotNet" Version="3.125.12" />
<PackageReference Include="xunit" Version="$(XunitVersion)" />
<PackageReference Include="xunit.runner.visualstudio" Version="$(XunitVersion)" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="3.0.1"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(TestSdkVersion)"/>
<PackageReference Include="Akka.Persistence.Sql.TestKit" Version="$(AkkaVersion)"/>
<PackageReference Include="Docker.DotNet" Version="3.125.12"/>
<PackageReference Include="xunit" Version="$(XunitVersion)"/>
<PackageReference Include="xunit.runner.visualstudio" Version="$(XunitVersion)"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Akka.Persistence.SqlServer\Akka.Persistence.SqlServer.csproj" />
<ProjectReference Include="..\Akka.Persistence.SqlServer\Akka.Persistence.SqlServer.csproj"/>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Akka.Actor;
using Akka.Configuration;
using Akka.Event;
using Akka.Persistence.TCK.Journal;
using Akka.TestKit;
using Akka.Util.Internal;
using Xunit;
using Xunit.Abstractions;
// -----------------------------------------------------------------------
// <copyright file="BatchingSqlJournalFailureSpec.cs" company="Akka.NET Project">
// Copyright (C) 2013 - 2023 .NET Foundation <https://github.com/akkadotnet/akka.net>
// </copyright>
// -----------------------------------------------------------------------



/*
namespace Akka.Persistence.SqlServer.Tests.Batching
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// -----------------------------------------------------------------------
// <copyright file="SqlServerEventsByTagSpec.cs" company="Akka.NET Project">
// Copyright (C) 2013 - 2019 .NET Foundation <https://github.com/akkadotnet/akka.net>
// <copyright file="BatchingSqlServerAllEventsSpec.cs" company="Akka.NET Project">
// Copyright (C) 2013 - 2023 .NET Foundation <https://github.com/akkadotnet/akka.net>
// </copyright>
// -----------------------------------------------------------------------

Expand All @@ -16,7 +16,8 @@ namespace Akka.Persistence.SqlServer.Tests.Batching
[Collection("SqlServerSpec")]
public class BatchingSqlServerAllEventsSpec : AllEventsSpec
{
public BatchingSqlServerAllEventsSpec(ITestOutputHelper output, SqlServerFixture fixture) : base(InitConfig(fixture),
public BatchingSqlServerAllEventsSpec(ITestOutputHelper output, SqlServerFixture fixture) : base(
InitConfig(fixture),
nameof(BatchingSqlServerAllEventsSpec), output)
{
ReadJournal = Sys.ReadJournalFor<SqlReadJournal>(SqlReadJournal.Identifier);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// -----------------------------------------------------------------------
// <copyright file="SqlServerEventsByTagSpec.cs" company="Akka.NET Project">
// Copyright (C) 2013 - 2019 .NET Foundation <https://github.com/akkadotnet/akka.net>
// <copyright file="BatchingSqlServerCurrentAllEventsSpec.cs" company="Akka.NET Project">
// Copyright (C) 2013 - 2023 .NET Foundation <https://github.com/akkadotnet/akka.net>
// </copyright>
// -----------------------------------------------------------------------

Expand All @@ -16,7 +16,8 @@ namespace Akka.Persistence.SqlServer.Tests.Batching
[Collection("SqlServerSpec")]
public class BatchingSqlServerCurrentAllEventsSpec : CurrentAllEventsSpec
{
public BatchingSqlServerCurrentAllEventsSpec(ITestOutputHelper output, SqlServerFixture fixture) : base(InitConfig(fixture),
public BatchingSqlServerCurrentAllEventsSpec(ITestOutputHelper output, SqlServerFixture fixture) : base(
InitConfig(fixture),
nameof(BatchingSqlServerCurrentAllEventsSpec), output)
{
ReadJournal = Sys.ReadJournalFor<SqlReadJournal>(SqlReadJournal.Identifier);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// -----------------------------------------------------------------------
// <copyright file="BatchingSqlServerEventsByPersistenceIdSpec.cs" company="Akka.NET Project">
// Copyright (C) 2013 - 2019 .NET Foundation <https://github.com/akkadotnet/akka.net>
// <copyright file="BatchingSqlServerCurrentEventsByPersistenceIdSpec.cs" company="Akka.NET Project">
// Copyright (C) 2013 - 2023 .NET Foundation <https://github.com/akkadotnet/akka.net>
// </copyright>
// -----------------------------------------------------------------------

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// -----------------------------------------------------------------------
// <copyright file="BatchingSqlServerEventsByTagSpec.cs" company="Akka.NET Project">
// Copyright (C) 2013 - 2019 .NET Foundation <https://github.com/akkadotnet/akka.net>
// <copyright file="BatchingSqlServerCurrentEventsByTagSpec.cs" company="Akka.NET Project">
// Copyright (C) 2013 - 2023 .NET Foundation <https://github.com/akkadotnet/akka.net>
// </copyright>
// -----------------------------------------------------------------------

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// -----------------------------------------------------------------------
// <copyright file="BatchingSqlServerPersistenceIdsSpec.cs" company="Akka.NET Project">
// Copyright (C) 2013 - 2019 .NET Foundation <https://github.com/akkadotnet/akka.net>
// <copyright file="BatchingSqlServerCurrentPersistenceIdsSpec.cs" company="Akka.NET Project">
// Copyright (C) 2013 - 2023 .NET Foundation <https://github.com/akkadotnet/akka.net>
// </copyright>
// -----------------------------------------------------------------------

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// -----------------------------------------------------------------------
// <copyright file="BatchingSqlServerEventsByPersistenceIdSpec.cs" company="Akka.NET Project">
// Copyright (C) 2013 - 2019 .NET Foundation <https://github.com/akkadotnet/akka.net>
// Copyright (C) 2013 - 2023 .NET Foundation <https://github.com/akkadotnet/akka.net>
// </copyright>
// -----------------------------------------------------------------------

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// -----------------------------------------------------------------------
// <copyright file="BatchingSqlServerEventsByTagSpec.cs" company="Akka.NET Project">
// Copyright (C) 2013 - 2019 .NET Foundation <https://github.com/akkadotnet/akka.net>
// Copyright (C) 2013 - 2023 .NET Foundation <https://github.com/akkadotnet/akka.net>
// </copyright>
// -----------------------------------------------------------------------

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Akka.Actor;
// -----------------------------------------------------------------------
// <copyright file="BatchingSqlServerJournalConnectionFailureSpec.cs" company="Akka.NET Project">
// Copyright (C) 2013 - 2023 .NET Foundation <https://github.com/akkadotnet/akka.net>
// </copyright>
// -----------------------------------------------------------------------

using Akka.Configuration;
using Akka.Event;
using Akka.Persistence.Sql.TestKit;
using Akka.Persistence.TCK.Journal;
using Akka.TestKit;
using Akka.Util.Internal;
using Xunit;
using Xunit.Abstractions;

Expand All @@ -18,6 +14,11 @@ namespace Akka.Persistence.SqlServer.Tests.Batching
[Collection("SqlServerSpec")]
public class BatchingSqlServerJournalConnectionFailureSpec : SqlJournalConnectionFailureSpec
{
public BatchingSqlServerJournalConnectionFailureSpec(ITestOutputHelper output)
: base(CreateSpecConfig(DefaultInvalidConnectionString), output)
{
}

private static Config CreateSpecConfig(string connectionString)
{
return ConfigurationFactory.ParseString(@"
Expand All @@ -38,10 +39,5 @@ class = ""Akka.Persistence.SqlServer.Journal.BatchingSqlServerJournal, Akka.Pers
}
}");
}

public BatchingSqlServerJournalConnectionFailureSpec(ITestOutputHelper output)
: base(CreateSpecConfig(DefaultInvalidConnectionString), output)
{
}
}
}
}
Loading