Skip to content

NH-4015 - Update Npgsql driver and enable DTC for it #630

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

Merged
merged 1 commit into from
Jun 7, 2017
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
Binary file removed lib/teamcity/postgresql/Mono.Security.dll
Binary file not shown.
Binary file modified lib/teamcity/postgresql/Npgsql.dll
Binary file not shown.
8,191 changes: 4,589 additions & 3,602 deletions lib/teamcity/postgresql/Npgsql.xml

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions lib/teamcity/postgresql/postgresql_installation.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ Installation steps for PostgreSQL for NH TeamCity:
3. Leave the port number at the default (5432), and leave the default locale;
4. The setup should install PostgreSQL on the machine;
5. Untick the option to install stack-builder at the end (it's not required).
6. Find the postgresql.conf file. It lies in the directory for the databases files.
7. Edit its max_prepared_transactions parameter to a positive integer. 100 by example. (This enables distributed transactions.)
8. Restart PostgreSQL server.

Creating the NH user:

Expand Down
2 changes: 1 addition & 1 deletion src/NHibernate.Config.Templates/PostgreSQL.cfg.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ for your own use before compile tests in VisualStudio.
<session-factory name="NHibernate.Test">
<property name="connection.driver_class">NHibernate.Driver.NpgsqlDriver</property>
<property name="connection.connection_string">
Server=localhost;Database=nhibernate;User ID=nhibernate;Password=nhibernate;
Server=localhost;Database=nhibernate;User ID=nhibernate;Password=nhibernate;Enlist=true;
</property>
<property name="dialect">NHibernate.Dialect.PostgreSQL83Dialect</property>
</session-factory>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,9 @@ public void CanDeleteItemInDtc()
}
}

// Dodging "latency" due to db still haven't actually committed a distributed tx after scope disposal.
Thread.Sleep(100);
Copy link
Member Author

Choose a reason for hiding this comment

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

I intend to put a better "dodge" logic in #627. It will apply only to database drivers showcasing the "latency" trouble.


using (var tx = new TransactionScope())
{
using (ISession s = OpenSession())
Expand All @@ -287,6 +290,9 @@ public void CanDeleteItemInDtc()
tx.Complete();
}
}

// Dodging "latency" due to db still haven't actually committed a distributed tx after scope disposal.
Thread.Sleep(100);
}

[Test]
Expand Down
3 changes: 3 additions & 0 deletions src/NHibernate.Test/NHibernate.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@
<HintPath>..\packages\System.Linq.Dynamic.1.0.7\lib\net40\System.Linq.Dynamic.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Threading.Tasks.Extensions, Version=4.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.3.0\lib\portable-net45+win8+wp8+wpa81\System.Threading.Tasks.Extensions.dll</HintPath>
</Reference>
<Reference Include="System.Transactions" />
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq">
Expand Down
15 changes: 1 addition & 14 deletions src/NHibernate.Test/TestDialects/PostgreSQL83TestDialect.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NHibernate.Test.TestDialects
namespace NHibernate.Test.TestDialects
{
public class PostgreSQL83TestDialect : TestDialect
{
Expand All @@ -21,13 +16,5 @@ public override bool SupportsNullCharactersInUtfStrings
{
get { return false; }
}

/// <summary>
/// Npgsql's DTC code seems to be somewhat broken as of 2.0.11.
/// </summary>
public override bool SupportsDistributedTransactions
Copy link
Member

Choose a reason for hiding this comment

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

Need to check when DTC become available in Postgres.

Copy link
Member Author

@fredericDelaporte fredericDelaporte Jun 6, 2017

Choose a reason for hiding this comment

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

But, it is available since long. Tests succeed. It was failing previously not because Postgres was not supporting it, but because we were not at all enlisting Postgres connection into scopes: enlist is false by default with npgsql. This PR switch it to true in the test connection string.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, sorry, I did not see that this is a dialect's test-double.

Copy link
Member

Choose a reason for hiding this comment

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

Looks good then

{
get { return false; }
}
}
}
2 changes: 2 additions & 0 deletions src/NHibernate.Test/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@
<package id="NUnit" version="3.6.0" targetFramework="net461" />
<package id="Remotion.Linq" version="1.15.15.0" targetFramework="net461" />
<package id="System.Linq.Dynamic" version="1.0.7" targetFramework="net461" />
<!-- System.Threading.Tasks.Extensions is required for dynamically loaded Npgsql.dll (Postgresql driver) -->
<package id="System.Threading.Tasks.Extensions" version="4.3.0" targetFramework="net461" />
</packages>
2 changes: 0 additions & 2 deletions src/NHibernate/Driver/NpgsqlDriver.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System;
using System.Data;
using System.Data.Common;
using System.Linq;

namespace NHibernate.Driver
{
Expand Down
2 changes: 1 addition & 1 deletion teamcity.build
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
<target name="setup-teamcity-postgresql">
<property name="nhibernate.connection.driver_class" value="NHibernate.Driver.NpgsqlDriver" />
<property name="nhibernate.dialect" value="NHibernate.Dialect.PostgreSQL83Dialect" />
<property name="nhibernate.connection.connection_string" value="Host=localhost;Port=5432;Database=nhibernate;Username=nhibernate;Password=nhibernate" />
<property name="nhibernate.connection.connection_string" value="Host=localhost;Port=5432;Database=nhibernate;Username=nhibernate;Password=nhibernate;Enlist=true" />
<copy todir="${bin.dir}">
<fileset basedir="${root.dir}/lib/teamcity/postgresql">
<include name="*.dll"/>
Expand Down