Skip to content

Commit 0bc81ec

Browse files
committed
Added mdb_env_info to native methods
1 parent 99afdcf commit 0bc81ec

File tree

5 files changed

+60
-0
lines changed

5 files changed

+60
-0
lines changed

src/LightningDB/LightningDB.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
<Compile Include="LightningTransaction.cs" />
110110
<Compile Include="LightningVersionInfo.cs" />
111111
<Compile Include="Native\MarshalValueStructure.cs" />
112+
<Compile Include="Native\MDBEnvInfo.cs" />
112113
<Compile Include="Native\MDBStat.cs" />
113114
<Compile Include="Native\Native.cs" />
114115
<Compile Include="Native\NativeLibraryFacades.cs">

src/LightningDB/Native/INativeLibraryFacade.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,14 @@ interface INativeLibraryFacade
304304
/// <param name="path">The directory in which the copy will reside. This directory must already exist and be writable but must otherwise be empty.</param>
305305
/// <returns>A non-zero error value on failure and 0 on success.</returns>
306306
int mdb_env_copy(IntPtr env, string path); //OK
307+
308+
/// <summary>
309+
/// Return information about the LMDB environment.
310+
/// </summary>
311+
/// <param name="env">An environment handle returned by mdb_env_create()</param>
312+
/// <param name="stat">The address of an MDB_envinfo structure where the information will be copied</param>
313+
/// <returns></returns>
314+
int mdb_env_info (IntPtr env, out MDBEnvInfo stat);
307315

308316
/// <summary>
309317
/// Flush the data buffers to disk.

src/LightningDB/Native/MDBEnvInfo.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Runtime.InteropServices;
5+
using System.Text;
6+
7+
namespace LightningDB.Native
8+
{
9+
[StructLayout(LayoutKind.Sequential)]
10+
struct MDBEnvInfo
11+
{
12+
public IntPtr me_mapaddr;
13+
public IntPtr me_mapsize;
14+
public IntPtr me_last_pgno;
15+
public IntPtr me_last_txnid;
16+
public uint me_maxreaders;
17+
public uint me_numreaders;
18+
}
19+
}

src/LightningDB/Native/NativeLibraryFacades.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ class Native32BitLibraryFacade : INativeLibraryFacade
7373
[DllImport(LibraryName, CallingConvention = CallingConvention.Cdecl)]
7474
private static extern int mdb_env_copy(IntPtr env, string path);
7575

76+
[DllImport(LibraryName, CallingConvention = CallingConvention.Cdecl)]
77+
private static extern int mdb_env_info (IntPtr env, out MDBEnvInfo stat);
78+
7679
[DllImport(LibraryName, CallingConvention = CallingConvention.Cdecl)]
7780
private static extern int mdb_env_sync(IntPtr env, bool force);
7881

@@ -220,6 +223,11 @@ int INativeLibraryFacade.mdb_env_copy(IntPtr env, string path)
220223
return Native32BitLibraryFacade.mdb_env_copy(env, path);
221224
}
222225

226+
int INativeLibraryFacade.mdb_env_info (IntPtr env, out MDBEnvInfo stat)
227+
{
228+
return Native32BitLibraryFacade.mdb_env_info(env, out stat);
229+
}
230+
223231
int INativeLibraryFacade.mdb_env_sync(IntPtr env, bool force)
224232
{
225233
return Native32BitLibraryFacade.mdb_env_sync(env, force);
@@ -342,6 +350,9 @@ class Native64BitLibraryFacade : INativeLibraryFacade
342350
[DllImport(LibraryName, CallingConvention = CallingConvention.Cdecl)]
343351
private static extern int mdb_env_copy(IntPtr env, string path);
344352

353+
[DllImport(LibraryName, CallingConvention = CallingConvention.Cdecl)]
354+
private static extern int mdb_env_info (IntPtr env, out MDBEnvInfo stat);
355+
345356
[DllImport(LibraryName, CallingConvention = CallingConvention.Cdecl)]
346357
private static extern int mdb_env_sync(IntPtr env, bool force);
347358

@@ -477,6 +488,11 @@ int INativeLibraryFacade.mdb_env_copy(IntPtr env, string path)
477488
return Native64BitLibraryFacade.mdb_env_copy(env, path);
478489
}
479490

491+
int INativeLibraryFacade.mdb_env_info (IntPtr env, out MDBEnvInfo stat)
492+
{
493+
return Native64BitLibraryFacade.mdb_env_info(env, out stat);
494+
}
495+
480496
int INativeLibraryFacade.mdb_env_sync(IntPtr env, bool force)
481497
{
482498
return Native64BitLibraryFacade.mdb_env_sync(env, force);
@@ -599,6 +615,9 @@ class FallbackLibraryFacade : INativeLibraryFacade
599615
[DllImport(LibraryName, CallingConvention = CallingConvention.Cdecl)]
600616
private static extern int mdb_env_copy(IntPtr env, string path);
601617

618+
[DllImport(LibraryName, CallingConvention = CallingConvention.Cdecl)]
619+
private static extern int mdb_env_info (IntPtr env, out MDBEnvInfo stat);
620+
602621
[DllImport(LibraryName, CallingConvention = CallingConvention.Cdecl)]
603622
private static extern int mdb_env_sync(IntPtr env, bool force);
604623

@@ -746,6 +765,11 @@ int INativeLibraryFacade.mdb_env_copy(IntPtr env, string path)
746765
return FallbackLibraryFacade.mdb_env_copy(env, path);
747766
}
748767

768+
int INativeLibraryFacade.mdb_env_info (IntPtr env, out MDBEnvInfo stat)
769+
{
770+
return FallbackLibraryFacade.mdb_env_info(env, out stat);
771+
}
772+
749773
int INativeLibraryFacade.mdb_env_sync(IntPtr env, bool force)
750774
{
751775
return FallbackLibraryFacade.mdb_env_sync(env, force);

src/LightningDB/Native/NativeLibraryFacades.tt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ namespace LightningDB.Native
8888
[DllImport(LibraryName, CallingConvention = CallingConvention.Cdecl)]
8989
private static extern int mdb_env_copy(IntPtr env, string path);
9090

91+
[DllImport(LibraryName, CallingConvention = CallingConvention.Cdecl)]
92+
private static extern int mdb_env_info (IntPtr env, out MDBEnvInfo stat);
93+
9194
[DllImport(LibraryName, CallingConvention = CallingConvention.Cdecl)]
9295
private static extern int mdb_env_sync(IntPtr env, bool force);
9396

@@ -239,6 +242,11 @@ namespace LightningDB.Native
239242
return <#= pair.Value #>LibraryFacade.mdb_env_copy(env, path);
240243
}
241244

245+
int INativeLibraryFacade.mdb_env_info (IntPtr env, out MDBEnvInfo stat)
246+
{
247+
return <#= pair.Value #>LibraryFacade.mdb_env_info(env, out stat);
248+
}
249+
242250
int INativeLibraryFacade.mdb_env_sync(IntPtr env, bool force)
243251
{
244252
return <#= pair.Value #>LibraryFacade.mdb_env_sync(env, force);

0 commit comments

Comments
 (0)