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

[Core Plugin] adopt more change from pr 3414 #3591

Merged
merged 8 commits into from
Nov 30, 2024

Conversation

Jim8y
Copy link
Contributor

@Jim8y Jim8y commented Nov 21, 2024

Description

3rd part of Pr #3414 and credits belong to @cschuchardt88

  • Added IEnumerable<KeyValuePair<byte[], byte[]>> to Store.cs to Iterate over the whole store.
  • Changed namespace from Neo.IO.Data.LevelDB to Neo.IO.Storage.LevelDB
  • Update IntPtr to nint

Fixes # #3414

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

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

@Jim8y Jim8y changed the title [Core Plugin] adapt more change from pr 3414 [Core Plugin] adopt more change from pr 3414 Nov 21, 2024
iterator.SeekToFirst();
while (iterator.Valid())
{
yield return new KeyValuePair<byte[], byte[]>(iterator.Key(), iterator.Value());
Copy link
Member

Choose a reason for hiding this comment

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

This behaviour maybe it's different than the previous one, because we are yield during a snapshot

Copy link
Member

@shargon shargon Nov 21, 2024

Choose a reason for hiding this comment

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

I prefer to receive the snapshot from an argument, maybe we don't wan't to use it, and avoid IEnumerable<KeyValuePair<byte[], byte[]>>

Copy link
Member

Choose a reason for hiding this comment

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

It's helpful for debugging. Better than being in the dark.

Copy link
Contributor Author

@Jim8y Jim8y Nov 22, 2024

Choose a reason for hiding this comment

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

It's helpful for debugging. Better than being in the dark.

Will this cause state difference or behavior difference? If the result is the same, i think it should be fine, this plugin can only be used here for the core.

Copy link
Member

Choose a reason for hiding this comment

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

We should receive the snapshot or null or we can have a big mistakes

Copy link
Member

@cschuchardt88 cschuchardt88 Nov 22, 2024

Choose a reason for hiding this comment

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

Will this cause state difference or behavior difference? If the result is the same, i think it should be fine, this plugin can only be used here for the core.

We should receive the snapshot or null or we can have a big mistakes

All its doing is displaying the whole database, has nothing to do with state or snapshots. The reason it takes a snapshot, so the data doesn't get changed (When viewing it).

Copy link
Member

Choose a reason for hiding this comment

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

But imagine that we use this method in a loop, when we change the data, we would not notice this error

Copy link
Member

Choose a reason for hiding this comment

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

than don't use snapshot just use

using var iterator = NewIterator(ReadOptions.Default);

Copy link
Member

Choose a reason for hiding this comment

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

Easy to forget

Copy link
Member

Choose a reason for hiding this comment

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

We can discuss in a different PR if we create the IEnumerable<KeyValuePair<byte[], byte[]>> , this one is ready to merge

Comment on lines 60 to 63
_db.GetEnumerator();

IEnumerator IEnumerable.GetEnumerator() =>
_db.GetEnumerator();
Copy link
Member

Choose a reason for hiding this comment

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

Same here

cschuchardt88
cschuchardt88 previously approved these changes Nov 23, 2024
{
/// <summary>
/// A DB is a persistent ordered map from keys to values.
/// A DB is safe for concurrent access from multiple threads without any external synchronization.
/// </summary>
public class DB : LevelDBHandle
public class DB : LevelDBHandle, IEnumerable<KeyValuePair<byte[], byte[]>>
Copy link
Member

Choose a reason for hiding this comment

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

Looks like you are missing a lot of methods for this class.

Missing Methods

  1. Throw(IntPtr error)
  2. Throw(IntPtr error, Func<string, Exception> exception)
  3. DB(string name, Options options)
  4. Get(byte[] key, ReadOptions options) - Code of function
  5. SnapShot CreateSnapshot()
  6. string PropertyValue(string name)
  7. void Repair(Options options, string name)
  8. void Destroy(Options options, string name)

Copy link
Member

@shargon shargon Nov 27, 2024

Choose a reason for hiding this comment

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

These can come in different PR

@cschuchardt88 cschuchardt88 dismissed their stale review November 26, 2024 22:40

Missing methods

@@ -44,11 +44,12 @@ public void Delete(byte[] key)
public void Dispose()
{
_snapshot.Dispose();
_options.Dispose();
Copy link
Member

Choose a reason for hiding this comment

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

This memory leak is present in master

public void Dispose()
{
_db.Dispose();
_options.Dispose();
Copy link
Member

Choose a reason for hiding this comment

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

This one also, but one per node


using var iterator = NewIterator(options);
iterator.SeekToFirst();
while (iterator.Valid())
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this while, and below is for. Might it be better to keep a consistent style?

Copy link
Member

Choose a reason for hiding this comment

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

He copied mine. but for would be better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will be fixed in another pr.

@shargon shargon merged commit 116c219 into neo-project:master Nov 30, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants