-
Notifications
You must be signed in to change notification settings - Fork 100
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
Persitence Plugin for exporting storage changes #21
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
8ae834e
Persitence Plugin first draft
vncoelho 0bc0043
Fixing some compiling problems. Trackable is still not found in the l…
vncoelho dd6ab93
Merge remote-tracking branch 'upstream/master' into PersistencePlugin
vncoelho 795ed58
Minnor changes. Trackable still not found
vncoelho c480a2e
Fixing all compiling errors and Trackable
vncoelho 8a48003
Fixing StorageKey and Item get values
vncoelho 8e10961
Switch case Persist Action and fixing Storage export
vncoelho 521e666
Adding Height To Being
vncoelho 2bfab18
Moving plugin to StatesDumper
vncoelho b3c7c4c
Merge branch 'master' into PersistencePlugin
vncoelho 77149e0
minnor comments
vncoelho 905a699
remove StatesDumper.sln
erikzhang bffa39b
format
erikzhang fc468c3
remove `Settings.BlockStorageCache`
erikzhang a77191f
add `PersistActions`
erikzhang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System; | ||
|
||
namespace Neo.Plugins | ||
{ | ||
[Flags] | ||
internal enum PersistActions : byte | ||
{ | ||
StorageChanges = 0b00000001 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using Microsoft.Extensions.Configuration; | ||
using System; | ||
using System.Reflection; | ||
|
||
namespace Neo.Plugins | ||
{ | ||
internal class Settings | ||
{ | ||
/// <summary> | ||
/// Amount of storages states (heights) to be dump in a given json file | ||
/// </summary> | ||
public uint BlockCacheSize { get; } | ||
/// <summary> | ||
/// Height to begin storage dump | ||
/// </summary> | ||
public uint HeightToBegin { get; } | ||
/// <summary> | ||
/// Height to begin real-time syncing and dumping on, consequently, dumping every block into a single files | ||
/// </summary> | ||
public uint HeightToStartRealTimeSyncing { get; } | ||
/// <summary> | ||
/// Persisting actions | ||
/// </summary> | ||
public PersistActions PersistAction { get; } | ||
|
||
public static Settings Default { get; } | ||
|
||
static Settings() | ||
{ | ||
Default = new Settings(Assembly.GetExecutingAssembly().GetConfiguration()); | ||
} | ||
|
||
public Settings(IConfigurationSection section) | ||
{ | ||
/// Geting settings for storage changes state dumper | ||
this.BlockCacheSize = GetValueOrDefault(section.GetSection("BlockCacheSize"), 1000u, p => uint.Parse(p)); | ||
this.HeightToBegin = GetValueOrDefault(section.GetSection("HeightToBegin"), 0u, p => uint.Parse(p)); | ||
this.HeightToStartRealTimeSyncing = GetValueOrDefault(section.GetSection("HeightToStartRealTimeSyncing"), 2883000u, p => uint.Parse(p)); | ||
this.PersistAction = GetValueOrDefault(section.GetSection("PersistAction"), PersistActions.StorageChanges, p => (PersistActions)Enum.Parse(typeof(PersistActions), p)); | ||
} | ||
|
||
public T GetValueOrDefault<T>(IConfigurationSection section, T defaultValue, Func<string, T> selector) | ||
{ | ||
if (section.Value == null) return defaultValue; | ||
return selector(section.Value); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"PluginConfiguration": { | ||
"PersistAction": "StorageChanges", | ||
"BlockCacheSize": 1000, | ||
"HeightToBegin": 0, | ||
"HeightToRealTimeSyncing": 2883000 | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Does this prevent data loss?
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 think the only way to prevent data loss is to save the data every time the block is persisted.
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.
If
BlockCacheSize==1
there will be no data loss.In our case, we chose it
BlockCacheSize==1000
(it is a little faster instead of persisting every block when syncing for the first time) and dumped withImportPlugin chain.acc
.The chance of data loss is lower when Importing.
That is why there is an additional variable that is
HeightToStartRealTimeSyncing
which, implicitly, forcesBlockCacheSize
to 1.There could be a tool that prints it every block and later deletes the files and merge then.
We currently do it in
bash
scripts: https://github.com/NeoResearch/neo-tests/blob/master/simple-rpc-node/merge_Storage.shThere 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.
What's the difference between
BlockCacheSize=1
andBlockCacheSize=1000
? Is it related to performance?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.
The performance was not good when persisting files on every block (in particular, during import), then we created this possible cache.
What do you think, @igormcoelho?
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.
Yeah, reducing disk writes is fundamental for performance... we experimented with BlockCacheSize=1 and it was very slow during block import... the bigger the Cache the better. We found that 1000 was a good compromise between delaying disk writes and still having block offloading to disk at every few seconds (during block import only, after that behavior should go to 1 again, which is enough for every 15 seconds).