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

Commit as the final step of persistence in StatesDumper #40

Merged
merged 3 commits into from
Jan 27, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions StatesDumper/StatesDumper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,6 @@ private void OnPersistStorage(Snapshot snapshot)
uint blockIndex = snapshot.Height;
if (blockIndex >= Settings.Default.HeightToBegin)
{
string dirPath = "./Storage";
Directory.CreateDirectory(dirPath);
string path = $"{HandlePaths(dirPath, blockIndex)}/dump-block-{blockIndex.ToString()}.json";

JArray array = new JArray();

foreach (DataCache<StorageKey, StorageItem>.Trackable trackable in snapshot.Storages.GetChangeSet())
Expand Down Expand Up @@ -121,9 +117,20 @@ private void OnPersistStorage(Snapshot snapshot)
bs_item["size"] = array.Count;
bs_item["storage"] = array;
bs_cache.Add(bs_item);
}
}

public void OnCommit(Snapshot snapshot)
{
uint blockIndex = snapshot.Height;
if (bs_cache.Count > 0)
{
if ((blockIndex % Settings.Default.BlockCacheSize == 0) || (blockIndex > Settings.Default.HeightToStartRealTimeSyncing))
{
string dirPath = "./Storage";
Directory.CreateDirectory(dirPath);
string path = $"{HandlePaths(dirPath, blockIndex)}/dump-block-{blockIndex.ToString()}.json";

File.WriteAllText(path, bs_cache.ToString());
bs_cache.Clear();
}
Expand Down