Skip to content

Commit a6cee1e

Browse files
authored
Making Windows auto resize work with netcore3.1 and net5.0 (#138)
Making Windows auto resize work with netcore3.1 and net5.0
1 parent 057e841 commit a6cee1e

File tree

14 files changed

+178
-261
lines changed

14 files changed

+178
-261
lines changed

.github/workflows/dotnetcoretest.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ jobs:
2828
run: make
2929
if: matrix.os == 'ubuntu-latest'
3030
- name: Setup .NET Core
31-
uses: actions/setup-dotnet@v1
31+
uses: actions/setup-dotnet@v1.8.0
3232
with:
33-
dotnet-version: 3.1.101
33+
dotnet-version: 5.0.301
3434
- name: Install dependencies
3535
working-directory: ${{ runner.workspace }}/Lightning.NET
3636
run: dotnet restore
@@ -39,9 +39,9 @@ jobs:
3939
run: dotnet build --configuration Release --no-restore
4040
- name: Test (Linux)
4141
working-directory: ${{ runner.workspace }}/Lightning.NET
42-
run: LD_LIBRARY_PATH=${{ runner.workspace}}/Lightning.NET/lmdb/libraries/liblmdb/:$LD_LIBRARY_PATH dotnet test -f netcoreapp3.1 --no-restore --verbosity normal
42+
run: LD_LIBRARY_PATH=${{ runner.workspace}}/Lightning.NET/lmdb/libraries/liblmdb/:$LD_LIBRARY_PATH dotnet test -f net5.0 --no-restore --verbosity normal
4343
if: matrix.os == 'ubuntu-latest'
4444
- name: Test (Windows or Mac)
4545
working-directory: ${{ runner.workspace }}/Lightning.NET
46-
run: dotnet test -f netcoreapp3.1 --no-restore --verbosity normal
46+
run: dotnet test -f net5.0 --no-restore --verbosity normal
4747
if: matrix.os == 'windows-latest' || matrix.os == 'macos-latest'

src/LightningDB.Benchmarks/LightningDB.Benchmarks.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
<TargetFrameworks>netcoreapp3.1;net5.0</TargetFrameworks>
66
</PropertyGroup>
77

88
<ItemGroup>

src/LightningDB.Tests/EnvironmentTests.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.IO;
3+
using System.Runtime.InteropServices;
34
using Xunit;
45

56
namespace LightningDB.Tests
@@ -142,5 +143,29 @@ public void CanOpenEnvironmentMoreThan50Mb()
142143

143144
_env.Open();
144145
}
146+
147+
148+
#if (NETCOREAPP3_1 || NET5_0)
149+
[Fact(Skip = "Run manually, behavior will override all tests with auto resize")]
150+
public void CreateEnvironmentWithAutoResize()
151+
{
152+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
153+
{
154+
using (var env = new LightningEnvironment(_path, new EnvironmentConfiguration
155+
{
156+
MapSize = 10 * 1024 * 1024,
157+
AutoResizeWindows = true,
158+
}))
159+
{
160+
env.Open();
161+
}
162+
163+
using (var dbFile = File.OpenRead(Path.Combine(_path, "data.mdb")))
164+
{
165+
Assert.Equal(8192, dbFile.Length);
166+
}
167+
}
168+
}
169+
#endif
145170
}
146171
}

src/LightningDB.Tests/LightningDB.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp3.1</TargetFramework>
4+
<TargetFrameworks>netcoreapp3.1;net5.0</TargetFrameworks>
55
<AssemblyName>LightningDB.Tests</AssemblyName>
66
<PackageId>LightningDB.Tests</PackageId>
77
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>

src/LightningDB/EnvironmentConfiguration.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ public class EnvironmentConfiguration
88
private long? _mapSize;
99
private int? _maxReaders;
1010
private int? _maxDatabases;
11+
12+
#if NETCOREAPP3_1 || NET5_0
13+
private bool? _autoResizeWindows;
14+
15+
public bool AutoResizeWindows
16+
{
17+
get { return _autoResizeWindows ?? false; }
18+
set { _autoResizeWindows = value; }
19+
}
20+
#endif
1121

1222
public long MapSize
1323
{

src/LightningDB/LightningDB.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<Description>LightningDB</Description>
55
<VersionPrefix>0.13.0</VersionPrefix>
66
<Authors>Ilya Lukyanov;Corey Kaylor</Authors>
7-
<TargetFramework>netstandard2.0</TargetFramework>
7+
<TargetFrameworks>netstandard2.0;netcoreapp3.1;net5.0</TargetFrameworks>
88
<AssemblyName>LightningDB</AssemblyName>
99
<PackageId>LightningDB</PackageId>
1010
<PackageLicenseFile>LICENSE</PackageLicenseFile>

src/LightningDB/LightningDB.targets

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,19 @@
99
<Link>lmdb.dll</Link>
1010
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
1111
</None>
12+
<None Include="$(MSBuildThisFileDirectory)$(LightningDBTargetRuntimeRelativePath)runtimes\win-x64\native\lmdbautoresize.dll">
13+
<Visible>false</Visible>
14+
<Link>lmdbautoresize.dll</Link>
15+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
16+
</None>
1217
</ItemGroup>
1318
<ItemGroup Condition="'$([MSBuild]::IsOsPlatform(Windows))' And '$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)'=='X86'">
1419
<None Include="$(MSBuildThisFileDirectory)$(LightningDBTargetRuntimeRelativePath)runtimes\win-x86\native\lmdb.dll">
20+
<Visible>false</Visible>
21+
<Link>lmdbautoresize.dll</Link>
22+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
23+
</None>
24+
<None Include="$(MSBuildThisFileDirectory)$(LightningDBTargetRuntimeRelativePath)runtimes\win-x86\native\lmdbautoresize.dll">
1525
<Visible>false</Visible>
1626
<Link>lmdb.dll</Link>
1727
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>

src/LightningDB/LightningEnvironment.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,21 @@ public LightningEnvironment(string path, EnvironmentConfiguration configuration
2424
{
2525
if (string.IsNullOrWhiteSpace(path))
2626
throw new ArgumentException("Invalid directory name");
27+
28+
var config = configuration ?? _config;
29+
#if NETCOREAPP3_1 || NET5_0
30+
if (config.AutoResizeWindows)
31+
{
32+
LoadWindowsAutoResizeLibrary();
33+
}
34+
#endif
2735

2836
mdb_env_create(out _handle).ThrowOnError();
37+
config.Configure(this);
38+
_config = config;
2939

3040
Path = path;
3141

32-
var config = configuration ?? _config;
33-
config.Configure(this);
34-
_config = config;
3542
}
3643

3744
public IntPtr Handle()

src/LightningDB/LightningExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public static (MDBResultCode resultCode, MDBValue key, MDBValue value) ThrowOnRe
5252
[MethodImpl(MethodImplOptions.AggressiveInlining)]
5353
private static string mdb_strerror(int err)
5454
{
55-
var ptr = LmdbMethods.mdb_strerror(err);
55+
var ptr = Lmdb.mdb_strerror(err);
5656
return Marshal.PtrToStringAnsi(ptr);
5757
}
5858

0 commit comments

Comments
 (0)