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

[Fix] Part-2 - LevelDbStore #3415

Open
wants to merge 17 commits into
base: master
Choose a base branch
from

Conversation

cschuchardt88
Copy link
Member

Description

This fixes the store's dotnet memory management for GC, a long with adding new feature options, easier Exception catching.

Change Log

  • Added LevelDbStoreTests for unit testing DB and Iterator

Type of change

  • Optimization (the change is only an optimization)
  • Style (the change is only a code style for better maintenance or standard purpose)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Unit tests

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@cschuchardt88 cschuchardt88 added blocked This issue can't be worked at the moment waiting for review Plugins labels Jul 9, 2024
// Keep whole blockchain open plus future files
// at lease up to block index 10_000_000
MaxOpenFiles = 4096,
FilterPolicy = 10,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
FilterPolicy = 10,
FilterPolicy = Native.leveldb_filterpolicy_create_bloom(15),

?

Copy link
Member Author

@cschuchardt88 cschuchardt88 Jul 11, 2024

Choose a reason for hiding this comment

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

No need for extra, 5 bits. Bloom filters should be as small as possible for datasets without that many collisions. 10 is way more than enough. Speed is key...

Comment on lines 53 to 54
? _db.Seek(prefix, new ReadOptions { FillCache = false, })
: _db.SeekPrev(prefix, new ReadOptions { FillCache = false, });
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
? _db.Seek(prefix, new ReadOptions { FillCache = false, })
: _db.SeekPrev(prefix, new ReadOptions { FillCache = false, });
? _db.Seek(prefix, ReadOptions.Default)
: _db.SeekPrev(prefix, ReadOptions.Default);

Copy link
Member Author

Choose a reason for hiding this comment

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

This will cause problem, because ReadOptions.Default is static readonly and will use the same instance. So if someone changes ReadOptions.Default parameters will cause problems for us. Thats why I coded it this way.

Copy link
Member Author

Choose a reason for hiding this comment

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

ReadOptions.Default isnt the same as new ReadOptions { FillCache = false, }

src/Plugins/LevelDBStore/IO/Data/LevelDB/WriteBatch.cs Outdated Show resolved Hide resolved
Comment on lines +42 to +52
if (disposing)
{
FreeManagedObjects();
}
if (Handle != nint.Zero)
{
FreeUnManagedObjects();
Handle = nint.Zero;
}
_disposed = true;
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (disposing)
{
FreeManagedObjects();
}
if (Handle != nint.Zero)
{
FreeUnManagedObjects();
Handle = nint.Zero;
}
_disposed = true;
}
_disposed = true;
if (disposing)
{
FreeManagedObjects();
}
if (Handle != nint.Zero)
{
FreeUnManagedObjects();
Handle = nint.Zero;
}
}

Copy link
Member Author

@cschuchardt88 cschuchardt88 Jul 11, 2024

Choose a reason for hiding this comment

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

Leveldb handle isnt disposed until FreeManagedObjects() is completed and Handle is zeroed. Even though dotnet class is disposed you can still call dispose method of a disposed class to dispose again.

@superboyiii superboyiii mentioned this pull request Sep 6, 2024
14 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked This issue can't be worked at the moment Plugins
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants