-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Conversation
iterator.SeekToFirst(); | ||
while (iterator.Valid()) | ||
{ | ||
yield return new KeyValuePair<byte[], byte[]>(iterator.Key(), iterator.Value()); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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[]>>
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Easy to forget
There was a problem hiding this comment.
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
_db.GetEnumerator(); | ||
|
||
IEnumerator IEnumerable.GetEnumerator() => | ||
_db.GetEnumerator(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
{ | ||
/// <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[]>> |
There was a problem hiding this comment.
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
Throw(IntPtr error)
Throw(IntPtr error, Func<string, Exception> exception)
DB(string name, Options options)
Get(byte[] key, ReadOptions options)
- Code of functionSnapShot CreateSnapshot()
string PropertyValue(string name)
void Repair(Options options, string name)
void Destroy(Options options, string name)
There was a problem hiding this comment.
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
@@ -44,11 +44,12 @@ public void Delete(byte[] key) | |||
public void Dispose() | |||
{ | |||
_snapshot.Dispose(); | |||
_options.Dispose(); |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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()) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Description
3rd part of Pr #3414 and credits belong to @cschuchardt88
Fixes # #3414
Type of change
Checklist: