From c9684755c3052de6c7791e609f7fbd46dca301cd Mon Sep 17 00:00:00 2001 From: jsolman Date: Mon, 21 Jan 2019 10:45:45 -0800 Subject: [PATCH 1/3] Support commit as the final step of persistence. --- StatesDumper/StatesDumper.cs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/StatesDumper/StatesDumper.cs b/StatesDumper/StatesDumper.cs index 1600a4543..7e6fe4571 100644 --- a/StatesDumper/StatesDumper.cs +++ b/StatesDumper/StatesDumper.cs @@ -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.Trackable trackable in snapshot.Storages.GetChangeSet()) @@ -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(); } From 5976ca7fa8a8ea926ba5e965e33d8d8208d3e4b4 Mon Sep 17 00:00:00 2001 From: jsolman Date: Wed, 23 Jan 2019 18:46:35 -0800 Subject: [PATCH 2/3] Update for new method . --- StatesDumper/StatesDumper.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/StatesDumper/StatesDumper.cs b/StatesDumper/StatesDumper.cs index 7e6fe4571..29a2f1ff4 100644 --- a/StatesDumper/StatesDumper.cs +++ b/StatesDumper/StatesDumper.cs @@ -137,6 +137,12 @@ public void OnCommit(Snapshot snapshot) } } + public bool ShouldThrowExceptionFromCommit(Exception ex) + { + Console.WriteLine($"Error writing States with StatesDumper.{Environment.NewLine}{ex}"); + return true; + } + private static string HandlePaths(string dirPath, uint blockIndex) { //Default Parameter From 09b7926903557eb758caad79a75e42e1637907fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vitor=20Naz=C3=A1rio=20Coelho?= Date: Sun, 27 Jan 2019 18:14:56 -0200 Subject: [PATCH 3/3] OnCommitStorage --- StatesDumper/StatesDumper.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/StatesDumper/StatesDumper.cs b/StatesDumper/StatesDumper.cs index 29a2f1ff4..5cc95fa3b 100644 --- a/StatesDumper/StatesDumper.cs +++ b/StatesDumper/StatesDumper.cs @@ -121,6 +121,12 @@ private void OnPersistStorage(Snapshot snapshot) } public void OnCommit(Snapshot snapshot) + { + if (Settings.Default.PersistAction.HasFlag(PersistActions.StorageChanges)) + OnCommitStorage(snapshot); + } + + public void OnCommitStorage(Snapshot snapshot) { uint blockIndex = snapshot.Height; if (bs_cache.Count > 0) @@ -136,7 +142,7 @@ public void OnCommit(Snapshot snapshot) } } } - + public bool ShouldThrowExceptionFromCommit(Exception ex) { Console.WriteLine($"Error writing States with StatesDumper.{Environment.NewLine}{ex}");