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

Tag table with backwards compatibility #68

Merged
merged 27 commits into from
Feb 3, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
660f637
index creation app example
to11mtm Jan 9, 2022
fec6cf5
WIP Tag Table with backwards compatibility
to11mtm Mar 19, 2022
8b65724
fix incomplete rename refactor, re-add case to guarantee manifest is …
to11mtm Mar 19, 2022
adc8ce4
fix: code for journal queries was not always respecting isdeleted
to11mtm Mar 20, 2022
6936c1e
Added WIP Tag-join-via UUID Support for users who may want faster wri…
to11mtm Apr 17, 2022
627d159
Try refactoring to make older compiler happy about expressions.
to11mtm Apr 17, 2022
bc52579
Try Unwinding ternarys to make compiler happy.
to11mtm Apr 17, 2022
3778099
WIP Allow proper handling of EventManifest
to11mtm Apr 17, 2022
4c2dc03
Merge branch 'dev' into tag-table-with-backwards-compat
Aaronontheweb Jul 18, 2022
34570b9
Rename Class1.cs to JournalIndexHelper.cs
Aaronontheweb Jul 18, 2022
d41e3c1
Merge branch 'dev' into tag-table-with-backwards-compat
Arkatufus Nov 23, 2022
f5e59b3
Move dangling projects into src folder
Arkatufus Nov 23, 2022
56777fa
Cleanup property names
Arkatufus Nov 23, 2022
f67450d
Merge branch 'dev' into tag-table-with-backwards-compat
Arkatufus Nov 23, 2022
d4e2984
Fix merge issues
Arkatufus Nov 23, 2022
060da94
Fix table column name compatibility problem
Arkatufus Nov 23, 2022
5a4595b
Fix logical delete compatibility problem
Arkatufus Nov 23, 2022
67bd601
Merge branch 'dev' into tag-table-with-backwards-compat
Arkatufus Nov 28, 2022
9e32549
Merge branch 'dev' into tag-table-with-backwards-compat
Arkatufus Nov 30, 2022
095b0dd
post-merge cleanup
Arkatufus Dec 1, 2022
969116b
Convert unit tests to use TestKit
Arkatufus Dec 1, 2022
bfe4f86
Fix unit tests
Arkatufus Dec 1, 2022
3455e3c
Merge branch 'dev' into tag-table-with-backwards-compat
Arkatufus Jan 31, 2023
1db2523
Merge branch 'dev' into tag-table-with-backwards-compat
Arkatufus Feb 1, 2023
d7a283d
Add SqlServer SQL script migration spec
Arkatufus Feb 2, 2023
b2a3329
Add PostgreSql and MySql SQL script spec
Arkatufus Feb 2, 2023
c59c980
Remove bit flag
Arkatufus Feb 2, 2023
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
15 changes: 15 additions & 0 deletions Akka.Linq2Db.Sandbox/Akka.Linq2Db.Sandbox.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Akka.Streams" Version="1.4.21" />
<PackageReference Include="linq2db" Version="3.4.1" />
<PackageReference Include="Reactive.Streams" Version="1.0.2" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Akka.Persistence.Linq2Db.IndexHelperLib\Akka.Persistence.Linq2Db.IndexHelperLib.csproj" />
<ProjectReference Include="..\src\Akka.Persistence.Sql.Linq2Db.Tests\Akka.Persistence.Sql.Linq2Db.Tests.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.8.0" />
<PackageReference Include="FluentMigrator.Runner" Version="3.3.1" />
</ItemGroup>

<ItemGroup>
<None Remove="example.hocon" />
<Content Include="example.hocon">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>

</Project>
22 changes: 22 additions & 0 deletions Akka.Persistence.Linq2Db.IndexHelperApp/Options.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using CommandLine;

namespace Akka.Persistence.Linq2Db.IndexHelperApp
{
public class Options
{
[Option('f',"file", Required=true, HelpText = "Specify the HOCON file to use")]
public string File { get; set; }

[Option('p',"path", Required = true, HelpText = "The Path to the Akka.Persistence.Linq2Db Config in the HOCON.")]
public string HoconPath { get; set; }

[Option("OrderingIdx", Required = true, Group = "IndexType", HelpText = "Generates the SQL Text for an Ordering index")]
public bool GenerateOrdering { get; set; }

[Option("PidSeqNoIdx", Required = true, Group = "IndexType", HelpText = "Generates the SQL Text for an index on PersistenceID and SeqNo")]
public bool GeneratePidSeqNo { get; set; }

[Option("TimeStampIdx", Required = true, Group = "IndexType", HelpText = "Generates the SQL Text for a Timestamp Index")]
public bool GenerateTimestamp { get; set; }
}
}
141 changes: 141 additions & 0 deletions Akka.Persistence.Linq2Db.IndexHelperApp/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
using System;
using System.IO;
using Akka.Configuration;
using Akka.Persistence.Linq2Db.IndexHelperLib;
using Akka.Persistence.Sql.Linq2Db.Config;
using Akka.Persistence.Sql.Linq2Db.Tests;
using CommandLine;
using FluentMigrator.Expressions;
using FluentMigrator.Runner.Generators;
using FluentMigrator.Runner.Generators.Generic;
using FluentMigrator.Runner.Generators.MySql;
using FluentMigrator.Runner.Generators.Oracle;
using FluentMigrator.Runner.Generators.Postgres;
using FluentMigrator.Runner.Generators.Postgres92;
using FluentMigrator.Runner.Generators.SQLite;
using FluentMigrator.Runner.Generators.SqlServer;
using FluentMigrator.Runner.Processors.Postgres;
using LinqToDB;
using Microsoft.Extensions.Options;
using Newtonsoft.Json;

namespace Akka.Persistence.Linq2Db.IndexHelperApp
{
class Program
{

static void Main(string[] args)
{
Parser.Default.ParseArguments<Options>(args)
.WithParsed(opts =>
{
//var str = Linq2DbJournalDefaultSpecConfig.customConfig("testGen",
// "journalTbl", "metadataTbl", ProviderName.SqlServer,
// "connStr");
var conf =
ConfigurationFactory.ParseString(
File.ReadAllText(opts.File));

var journalConf =
new Akka.Persistence.Sql.Linq2Db.Config.JournalConfig(
conf.GetConfig(
opts.HoconPath
//"akka.persistence.journal.linq2db.testGen"
)
.WithFallback(Akka.Persistence.Sql.Linq2Db
.Journal
.Linq2DbWriteJournal.DefaultConfiguration));
var generator = getGenerator(journalConf.ProviderName);
var helper = new JournalIndexHelper();
CreateIndexExpression expr = null;
GeneratePerOptions(opts, helper, journalConf, generator);
});
}

private static void GeneratePerOptions(Options opts, JournalIndexHelper helper,
JournalConfig journalConf, GenericGenerator generator)
{
CreateIndexExpression expr;
if (opts.GeneratePidSeqNo)
{
expr = new CreateIndexExpression()
{
Index = helper.JournalOrdering(journalConf.TableConfig.TableName,
journalConf.TableConfig.ColumnNames.Ordering,
journalConf.TableConfig.SchemaName)
};
GenerateWithHeaderAndFooter(generator, expr, "Ordering");
}

if (opts.GeneratePidSeqNo)
{
expr = new CreateIndexExpression()
{
Index = helper.DefaultJournalIndex(
journalConf.TableConfig.TableName,
journalConf.TableConfig.ColumnNames.PersistenceId,
journalConf.TableConfig.ColumnNames.SequenceNumber,
journalConf.TableConfig.SchemaName)
};
GenerateWithHeaderAndFooter(generator, expr, "PidAndSequenceNo");
}

if (opts.GenerateTimestamp)
{
expr = new CreateIndexExpression()
{
Index = helper.JournalTimestamp(journalConf.TableConfig.TableName,
journalConf.TableConfig.ColumnNames.Created,
journalConf.TableConfig.SchemaName)
};
GenerateWithHeaderAndFooter(generator, expr, "Timestamp");
}
}

private static void GenerateWithHeaderAndFooter(GenericGenerator generator,
CreateIndexExpression expr, string indexType)
{
Console.WriteLine("-------");
Console.WriteLine($"----{indexType} Index Create Below");
Console.WriteLine(generator.Generate(expr));
Console.WriteLine($"----{indexType} Index Create Above");
Console.WriteLine("-------");
}

static GenericGenerator getGenerator(string dbArg)
{
if (dbArg.StartsWith("sqlserver",
StringComparison.InvariantCultureIgnoreCase))
{
return new SqlServer2008Generator();
}
else if (dbArg.Contains("sqlite",
StringComparison.InvariantCultureIgnoreCase))
{
return new SQLiteGenerator();
}
else if (dbArg.Contains("postgres",
StringComparison.InvariantCultureIgnoreCase))
{
return new Postgres92Generator(
new PostgresQuoter(new PostgresOptions()),
new OptionsWrapper<GeneratorOptions>(
new GeneratorOptions()));
}
else if (dbArg.Contains("mysql",
StringComparison.InvariantCultureIgnoreCase))
{
return new MySql5Generator();
}
else if (dbArg.Contains("oracle",
StringComparison.InvariantCultureIgnoreCase))
{
return new OracleGenerator();
}
else
{
throw new Exception("IDK what to do with this!");
}
}
}
}
15 changes: 15 additions & 0 deletions Akka.Persistence.Linq2Db.IndexHelperApp/example.hocon
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
akka.persistence.journal.linq2db{
testGen {
class = "Akka.Persistence.Sql.Linq2Db.Journal.Linq2DbWriteJournal, Akka.Persistence.Sql.Linq2Db"
provider-name = "SqlServer"
connection-string = "connStr"
tables{
journal{
auto-init = true
warn-on-auto-init-fail = false
table-name = "journalTbl"
metadata-table-name = "metadataTbl"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\src\Akka.Persistence.Sql.Linq2Db\Akka.Persistence.Sql.Linq2Db.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="FluentMigrator" Version="3.3.1" />
</ItemGroup>

</Project>
50 changes: 50 additions & 0 deletions Akka.Persistence.Linq2Db.IndexHelperLib/Class1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using System;
using FluentMigrator.Model;

namespace Akka.Persistence.Linq2Db.IndexHelperLib
{
public class JournalIndexHelper
{
public IndexDefinition DefaultJournalIndex(string tableName, string persistenceIdCol, string sequenceNoCol, string schemaName = null)
{
var idx = beginCreateIndex(tableName, schemaName, $"UX_{tableName}_PID_SEQNO");
//short name for easy compat with all dbs. (*cough* oracle *cough*)
idx.Columns.Add(new IndexColumnDefinition(){ Name = persistenceIdCol });
idx.Columns.Add(new IndexColumnDefinition(){Name = sequenceNoCol, Direction = Direction.Ascending});
idx.IsUnique = true;
return idx;
}

public IndexDefinition JournalOrdering(string tableName,
string orderingCol, string schemaName = null)
{
var idx = beginCreateIndex(tableName, schemaName,$"IX_{tableName}_Ordering");
idx.Columns.Add(new IndexColumnDefinition(){Name = orderingCol});
//Should it be?
//idx.IsUnique = true;
return idx;
}

public IndexDefinition JournalTimestamp(string tableName,
string timestampCol, string schemaName = null)
{
var idx = beginCreateIndex(tableName, schemaName,
$"IX_{tableName}_TimeStamp");
idx.Columns.Add(new IndexColumnDefinition(){Name = timestampCol});
//Not unique by any stretch.
return idx;
}

private static IndexDefinition beginCreateIndex(string tableName, string schemaName, string indexName)
{
var idx = new IndexDefinition();
if (string.IsNullOrWhiteSpace(schemaName) == false)
{
idx.SchemaName = schemaName;
}
idx.TableName = tableName;
idx.Name = indexName;
return idx;
}
}
}
18 changes: 18 additions & 0 deletions Akka.Persistence.Linq2Db.sln
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Akka.Persistence.Linq2Db.Benchmark.DockerComparisonTests", "Akka.Persistence.Linq2Db.Benchmark.DockerComparisonTests\Akka.Persistence.Linq2Db.Benchmark.DockerComparisonTests.csproj", "{170698FA-DA1E-40BC-896D-AFA67976C0EB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Akka.Persistence.Linq2Db.IndexHelperLib", "Akka.Persistence.Linq2Db.IndexHelperLib\Akka.Persistence.Linq2Db.IndexHelperLib.csproj", "{AACE3FBC-51FE-4A9B-B6C4-4CCA750DB22E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Akka.Persistence.Linq2Db.IndexHelperApp", "Akka.Persistence.Linq2Db.IndexHelperApp\Akka.Persistence.Linq2Db.IndexHelperApp.csproj", "{D5C851AA-DB80-4E9F-BD2E-03E63DC3082E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Akka.Linq2Db.Sandbox", "Akka.Linq2Db.Sandbox\Akka.Linq2Db.Sandbox.csproj", "{697B9FC8-29E2-4F7D-B63B-9E4B873F6AA1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -78,6 +84,18 @@ Global
{170698FA-DA1E-40BC-896D-AFA67976C0EB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{170698FA-DA1E-40BC-896D-AFA67976C0EB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{170698FA-DA1E-40BC-896D-AFA67976C0EB}.Release|Any CPU.Build.0 = Release|Any CPU
{AACE3FBC-51FE-4A9B-B6C4-4CCA750DB22E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AACE3FBC-51FE-4A9B-B6C4-4CCA750DB22E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AACE3FBC-51FE-4A9B-B6C4-4CCA750DB22E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AACE3FBC-51FE-4A9B-B6C4-4CCA750DB22E}.Release|Any CPU.Build.0 = Release|Any CPU
{D5C851AA-DB80-4E9F-BD2E-03E63DC3082E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D5C851AA-DB80-4E9F-BD2E-03E63DC3082E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D5C851AA-DB80-4E9F-BD2E-03E63DC3082E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D5C851AA-DB80-4E9F-BD2E-03E63DC3082E}.Release|Any CPU.Build.0 = Release|Any CPU
{697B9FC8-29E2-4F7D-B63B-9E4B873F6AA1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{697B9FC8-29E2-4F7D-B63B-9E4B873F6AA1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{697B9FC8-29E2-4F7D-B63B-9E4B873F6AA1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{697B9FC8-29E2-4F7D-B63B-9E4B873F6AA1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public BaseByteArrayJournalDaoConfig(Configuration.Config config)
BufferSize = config.GetInt("buffer-size", 5000);
BatchSize = config.GetInt("batch-size", 100);
DbRoundTripBatchSize = config.GetInt("db-round-trip-max-batch-size", 1000);
DbRoundTripTagBatchSize = config.GetInt("db-round-trip-max-tag-batch-size", 1000);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

PreferParametersOnMultiRowInsert =
config.GetBoolean("prefer-parameters-on-multirow-insert",
false);
Expand Down Expand Up @@ -43,6 +44,6 @@ public BaseByteArrayJournalDaoConfig(Configuration.Config config)
public int BufferSize { get; protected set; }

public bool SqlCommonCompatibilityMode { get; protected set; }

public int DbRoundTripTagBatchSize { get; set; }
Aaronontheweb marked this conversation as resolved.
Show resolved Hide resolved
}
}
4 changes: 3 additions & 1 deletion src/Akka.Persistence.Sql.Linq2Db/Config/JournalConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public JournalConfig(Configuration.Config config)
UseSharedDb = string.IsNullOrWhiteSpace(dbConf) ? null : dbConf;
UseCloneConnection =
config.GetBoolean("use-clone-connection", false);

}

public string MaterializerDispatcher { get; protected set; }
Expand All @@ -44,6 +43,7 @@ public IDaoConfig IDaoConfig
public string ProviderName { get; }
public string ConnectionString { get; }
public bool UseCloneConnection { get; set; }

}

public interface IProviderConfig<TTable>
Expand All @@ -61,4 +61,6 @@ public interface IDaoConfig
bool SqlCommonCompatibilityMode { get; }
int Parallelism { get; }
}


}
Loading