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

v10 SQLite support + distributed locking abstractions #11922

Merged
merged 87 commits into from Mar 11, 2022

Conversation

Copy link
Member

@p-m-j p-m-j commented Jan 28, 2022

No description provided.

@p-m-j p-m-j force-pushed the v10/feature/sqlite-support branch 5 times, most recently from 2216813 to 1e52264 Compare Jan 31, 2022
@p-m-j p-m-j force-pushed the v10/feature/sqlite-support branch 4 times, most recently from 94f94ee to 2748670 Compare Feb 11, 2022
.From<UserLoginDto>()
.Where<UserLoginDto>(x => x.SessionId == SqlTemplate.Arg<Guid>("sessionId"))
.ForUpdate());
.ForUpdate()
.SelectTop(1)); // Stick at end, SQL server syntax provider will insert at start of query after "select ", but sqlite will append limit to end.
Copy link
Member Author

@p-m-j p-m-j Feb 12, 2022

Choose a reason for hiding this comment

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

Npoco (and our extension) expression builders are pretty linear, the final query is written in order.

The SelectTop extension will add "TOP {n}" at the first select found in the current query.
But for RDBMS with Limit it's hard for us to know when/where to append to query as later statements may still be chained into the builder.

This kindof sucks but if you always put SelectTop last for a query (or sub query) it always works.


namespace Umbraco.Cms.Infrastructure.Persistence;

public abstract class ScalarMapper<T> : IScalarMapper
Copy link
Member Author

@p-m-j p-m-j Feb 12, 2022

Choose a reason for hiding this comment

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

NPoco + MS.Data.Sqlite workaround sad times.

ExecuteScalar<T> in npoco only works for types supported by Convert.ChangeType (e.g. not byte[] or string -> Guid which we need) so we have to workaround for now.

Not a problem with System.Data.Sqlite whose upstream object ExecuteScalar returns Guid by magic, MS team wanted less magic so we get string or byte[].

I don't think there is a way around this, however perhaps the setup should be more consistent with the rest of the provider bundle (e.g. as part of DbProviderFactoryCreator)


foreach (var record in records)
{
database.Insert(record);
Copy link
Member Author

@p-m-j p-m-j Feb 12, 2022

Choose a reason for hiding this comment

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

If we convert to query text we can instantiate params a single time and rebind (future performance enhancement, not top priority)

{1B28FC3E-3D5B-4A46-8961-5483835548D7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1B28FC3E-3D5B-4A46-8961-5483835548D7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1B28FC3E-3D5B-4A46-8961-5483835548D7}.Release|Any CPU.Build.0 = Release|Any CPU
{2A5027D9-F71D-4957-929E-F7A56AA1B95A}.SkipTests|Any CPU.ActiveCfg = Debug|Any CPU
Copy link
Member Author

@p-m-j p-m-j Feb 12, 2022

Choose a reason for hiding this comment

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

stops codeql kicking off about passwords in test projects etc

connection.Open();

using SqliteCommand command = connection.CreateCommand();
command.CommandText = "PRAGMA journal_mode = wal;";
Copy link
Member Author

@p-m-j p-m-j Feb 12, 2022

Choose a reason for hiding this comment

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

not settable on connection string for MS.Data.Sqlite

@p-m-j p-m-j force-pushed the v10/feature/sqlite-support branch from 7cad38c to ff825fd Compare Feb 13, 2022
@@ -8,5 +8,5 @@ public static class Constants
/// <summary>
/// SQLite provider name.
/// </summary>
public const string ProviderName = "System.Data.SQLite";
public const string ProviderName = "Microsoft.Data.SQLite";
Copy link
Member Author

@p-m-j p-m-j Feb 14, 2022

Choose a reason for hiding this comment

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

We switched to support (MacOS) osx-arm (native interop library for sys.data missing osx-arm binaries)

_globalSettings = globalSettings;
_log = log;

_scalarMappers = new Dictionary<Type, IScalarMapper>
Copy link
Member Author

@p-m-j p-m-j Feb 14, 2022

Choose a reason for hiding this comment

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

should this move to DbProviderFactoryCreator?

@p-m-j p-m-j force-pushed the v10/feature/sqlite-support branch 3 times, most recently from 487bc3a to 7d7eb57 Compare Feb 15, 2022
@p-m-j p-m-j force-pushed the v10/feature/sqlite-support branch from 9ea8b57 to 86e4cd2 Compare Feb 25, 2022
@p-m-j p-m-j marked this pull request as ready for review Mar 1, 2022
@p-m-j p-m-j force-pushed the v10/feature/sqlite-support branch from eb51053 to 263c454 Compare Mar 2, 2022
p-m-j added 22 commits Mar 11, 2022
TODO: InMemoryDistributedLockingMechanism.

Note: Nuked SqlServerDistributedLockingMechanismTests, will still sleep
at night.
Is covered by Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.LockTests
InMemoryDistributedMechanism was pretty rubbish and now we have
a decent implementation for SQLite as we no longer block readers
see 8d1f42b.

Also drop the CollectionBuilder setup, instead do the same as we do
for syntax providers etc, it's more automagical so we never require an
explicit selection although we are allowing for it.

However keeping the optional IUmbracoBuilder constructor param for
CollectionBuilders as it's extremely useful.
Doesn't seem worth it to extract db name from connection string.
There's no point in running the query just to make a single test pass.
@p-m-j p-m-j force-pushed the v10/feature/sqlite-support branch from 15e077f to a74c984 Compare Mar 11, 2022
@p-m-j p-m-j changed the title V10 SQLite support v10 SQLite support + Distributed Locking abstractions Mar 11, 2022
@p-m-j p-m-j changed the title v10 SQLite support + Distributed Locking abstractions v10 SQLite support + d]istributed locking abstractions Mar 11, 2022
@p-m-j p-m-j changed the title v10 SQLite support + d]istributed locking abstractions v10 SQLite support + distributed locking abstractions Mar 11, 2022
@bergmania bergmania merged commit 3961c4c into v10/dev Mar 11, 2022
17 checks passed
@bergmania bergmania deleted the v10/feature/sqlite-support branch Mar 11, 2022
@p-m-j
Copy link
Member Author

@p-m-j p-m-j commented Mar 11, 2022

🎉 !!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants