Skip to content

Commit

Permalink
Add BloomFilter to levelDB (#253)
Browse files Browse the repository at this point in the history
* Add BloomFilter to levelDB

* Code optimization

* Code optimization

* Optimize bloomfilter bits per key value

* Hard-code bloomfilter bitsPeyKey to 15

* Code optimization

Co-authored-by: Jin Qiao <[email protected]>
Co-authored-by: Shargon <[email protected]>
Co-authored-by: Erik Zhang <[email protected]>
  • Loading branch information
4 people authored Jul 16, 2020
1 parent 6dc340c commit dcd946a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/LevelDBStore/IO/Data/LevelDB/Native.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ public static class Native

[DllImport("libleveldb", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
public static extern void leveldb_options_set_filter_policy(IntPtr /*Options*/ options, IntPtr /*FilterPolicy*/ policy);

[DllImport("libleveldb", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr leveldb_filterpolicy_create_bloom(int bits_per_key);
#endregion

#region ReadOptions
Expand Down
2 changes: 1 addition & 1 deletion src/LevelDBStore/LevelDBStore/config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
{
"PluginConfiguration": {
"Path": "Data_LevelDB_{0}"
}
Expand Down
2 changes: 1 addition & 1 deletion src/LevelDBStore/Plugins/Storage/Store.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ internal class Store : IStore

public Store(string path)
{
this.db = DB.Open(path, new Options { CreateIfMissing = true });
this.db = DB.Open(path, new Options { CreateIfMissing = true, FilterPolicy = Native.leveldb_filterpolicy_create_bloom(15) });
byte[] value = db.Get(ReadOptions.Default, LHelper.CreateKey(SYS_Version));
if (value != null && Version.TryParse(Encoding.ASCII.GetString(value), out Version version) && version >= Version.Parse("3.0.0"))
return;
Expand Down

0 comments on commit dcd946a

Please sign in to comment.