-
Notifications
You must be signed in to change notification settings - Fork 465
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
Full pruning #3096
Merged
Merged
Full pruning #3096
Changes from all commits
Commits
Show all changes
80 commits
Select commit
Hold shift + click to select a range
e06b879
Add HighestPersistedState to BlockTree
LukaszRozmej c61f779
RocksDbSettings cloning
LukaszRozmej 6b24404
MemDbFactoryAdapter to use IRocksDbFactory
LukaszRozmej 5edf619
Pruning Triggers
LukaszRozmej 265cab3
Add StateDbDuplicateWrites metrics
LukaszRozmej 903630a
Add FullPruningDb
LukaszRozmej 1e02ad7
Add FullPruner and CopyTreeVisitor
LukaszRozmej d67c0c2
CopyTreeVisitor add logs
LukaszRozmej d879f97
CopyTreeVisitor add tests
LukaszRozmej f4e13b2
Rename RocksDbSizePruningTrigger to PathSizePruningTrigger
LukaszRozmej 5ad5cf0
add tests for PathSizePruningTrigger
LukaszRozmej 12948ef
Move test projects to c# 9
LukaszRozmej c5c9b7c
Add DiskFreeSpacePruningTrigger Tests
LukaszRozmej 8c7c8ec
Add Build.A.Trie and TrieBuilder
LukaszRozmej 432471c
Move PruningConfig add PruningMode
LukaszRozmej ee9df91
FullPruningInnerDbFactory to correctly read db index
LukaszRozmej 6e97196
Add RocksDbSettings clone test
LukaszRozmej 0825f42
Change FullPruningDb, add tests for it
LukaszRozmej 3afc8f6
Rename MemDbFactoryToRocksDbAdapter
LukaszRozmej 5e7b467
Change StandardDbInitializer to support full pruning
LukaszRozmej b5e66e9
Add FullPruner tests
LukaszRozmej 9f9ec28
Add TrieStoreBondryWatcher to encapsulate and reuse connection betwee…
LukaszRozmej 40cd8b3
Fix HighestPersistedState null serialization
LukaszRozmej 5edb1f6
Fix DbOnTheRocks Clear by delete (needed dispose first) and special p…
LukaszRozmej 9cdde84
Add FullPruningDiskTest
LukaszRozmej c486b31
Merge remote-tracking branch 'origin/master' into FullPruning
LukaszRozmej 37e256c
Add PruningConfig.FullPruningThresholdMb and PruningConfig.FullPrunin…
LukaszRozmej e9d127a
Add IFullPruningDb.GetPath
LukaszRozmej 0987fb1
Initialize FullPruner
LukaszRozmej 99461de
Better metrics
LukaszRozmej 612359f
BlockTree highest persisted state fix
LukaszRozmej f8722b7
fixes
LukaszRozmej 23a8c15
Duplicate batches in pruning, start full pruning only between blocks,…
LukaszRozmej 3d64580
Merge remote-tracking branch 'origin/master' into FullPruning
LukaszRozmej de80437
Fix FullPruningDb canellation
LukaszRozmej 96cf067
Fix indexing db in PathSizePruningTrigger
LukaszRozmej 66c42bd
Fix FullPruner, use head.StateRoot
LukaszRozmej db7f3ee
fix delete database
LukaszRozmej af91f1f
Merge remote-tracking branch 'origin/master' into FullPruning
LukaszRozmej c0d110c
fix tests
LukaszRozmej c3097bb
fix tests
LukaszRozmej 51882f6
Change config a bit
LukaszRozmej 0cb7237
Merge remote-tracking branch 'origin/master' into FullPruning
LukaszRozmej 0caeb24
Make CopyTreeVisitor parallel
LukaszRozmej 2a8fbc7
Move to VisitingOptions
LukaszRozmej 000561f
add FullPruningMaxDegreeOfParallelism config option
LukaszRozmej 9c51de9
Remove SupportsParallelVisits
LukaszRozmej e177d2c
changes
LukaszRozmej 3de599a
Merge remote-tracking branch 'origin/master' into FullPruning2
LukaszRozmej 270c714
Add full pruned configs
jmederosalvarado 4e14e9f
Merge remote-tracking branch 'origin/master' into FullPruning
LukaszRozmej b26bfe2
Fix issues with TrieStore with both archive and mem pruning modes.
LukaszRozmej 92bae42
Refactor + comments
LukaszRozmej 515b80f
FIx initialize pruning trigger when only Manual pruning is enabled
LukaszRozmej 08a0be3
Move parallelism to be based on Semaphore
LukaszRozmej 1b0d37d
PruningTriggerPersistenceStrategy experiment
LukaszRozmej 02c50ee
Add description how Full Pruning works
LukaszRozmej a2237a5
Merge remote-tracking branch 'origin/master' into FullPrunning-trigger
LukaszRozmej 55163c8
Fix issues with hybrid pruning
LukaszRozmej 7ef8b55
fix resolving storage root
LukaszRozmej 9dc7bfc
Merge remote-tracking branch 'origin/master' into FullPrunning-trigger
LukaszRozmej 49e5800
Merge branch 'FullPrunning-trigger' into FullPruning
LukaszRozmej b508446
refactor merge
LukaszRozmej 366943e
Add pruning delay to make sure we won't break ssds
LukaszRozmej b9fbc2d
optimize ShouldPersist
LukaszRozmej cab11d4
Add TrieStats Levels
LukaszRozmej e8e634d
Make TrieStats collecting parallel
LukaszRozmej 1ae5cac
Make Trie Stats collecting in the background
LukaszRozmej 0ed890f
Hide PruningConfig.Enabled from docs
LukaszRozmej b73598c
Merge remote-tracking branch 'origin/FullPrunning-trigger' into FullP…
LukaszRozmej b80d8aa
Log Exception when collecting trie stats
dceleda 05d3902
Always register FullPruningDb if someone disables it in the future
LukaszRozmej 37b95b8
small refactor
LukaszRozmej d8d1b97
Merge branch 'FullPrunning-trigger' into FullPruning
LukaszRozmej 382ecae
Set VisitContext.MaxDegreeOfParallelism default to 1
LukaszRozmej 3af5453
Remove IDb.Innermost
LukaszRozmej 7ed8b08
Remove non-default module types
LukaszRozmej 23d5f53
fix tests
LukaszRozmej 5476935
review comments
LukaszRozmej be4e38c
Merge remote-tracking branch 'origin/master' into FullPruning
LukaszRozmej 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
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
85 changes: 85 additions & 0 deletions
85
src/Nethermind/Nethermind.Blockchain.Test/FullPruning/CopyTreeVisitorTests.cs
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,85 @@ | ||
// Copyright (c) 2021 Demerzel Solutions Limited | ||
// This file is part of the Nethermind library. | ||
// | ||
// The Nethermind library is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Lesser General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// The Nethermind library is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public License | ||
// along with the Nethermind. If not, see <http://www.gnu.org/licenses/>. | ||
// | ||
|
||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using FluentAssertions; | ||
using Nethermind.Blockchain.FullPruning; | ||
using Nethermind.Core.Test.Builders; | ||
using Nethermind.Db; | ||
using Nethermind.Db.FullPruning; | ||
using Nethermind.Logging; | ||
using Nethermind.State; | ||
using Nethermind.Trie; | ||
using Nethermind.Trie.Pruning; | ||
using NSubstitute; | ||
using NUnit.Framework; | ||
|
||
namespace Nethermind.Blockchain.Test.FullPruning | ||
{ | ||
[Parallelizable(ParallelScope.All)] | ||
public class CopyTreeVisitorTests | ||
{ | ||
[Test] | ||
public void copies_state_between_dbs() | ||
{ | ||
MemDb trieDb = new(); | ||
MemDb clonedDb = new(); | ||
CopyDb(StartPruning(trieDb, clonedDb), trieDb, clonedDb); | ||
|
||
clonedDb.Count.Should().Be(132); | ||
clonedDb.Keys.Should().BeEquivalentTo(trieDb.Keys); | ||
clonedDb.Values.Should().BeEquivalentTo(trieDb.Values); | ||
} | ||
|
||
[Test] | ||
public async Task cancel_coping_state_between_dbs() | ||
{ | ||
MemDb trieDb = new(); | ||
MemDb clonedDb = new(); | ||
IPruningContext pruningContext = StartPruning(trieDb, clonedDb); | ||
Task task = Task.Run(() => CopyDb(pruningContext, trieDb, clonedDb)); | ||
|
||
pruningContext?.CancellationTokenSource.Cancel(); | ||
|
||
await task; | ||
|
||
clonedDb.Count.Should().BeLessThan(trieDb.Count); | ||
} | ||
|
||
private static IPruningContext CopyDb(IPruningContext pruningContext, MemDb trieDb, MemDb clonedDb) | ||
{ | ||
LimboLogs logManager = LimboLogs.Instance; | ||
PatriciaTree trie = Build.A.Trie(trieDb).WithAccountsByIndex(0, 100).TestObject; | ||
IStateReader stateReader = new StateReader(new TrieStore(trieDb, logManager), new MemDb(), logManager); | ||
|
||
using CopyTreeVisitor copyTreeVisitor = new(pruningContext, logManager); | ||
stateReader.RunTreeVisitor(copyTreeVisitor, trie.RootHash); | ||
return pruningContext; | ||
} | ||
|
||
private static IPruningContext StartPruning(MemDb trieDb, MemDb clonedDb) | ||
{ | ||
IRocksDbFactory rocksDbFactory = Substitute.For<IRocksDbFactory>(); | ||
rocksDbFactory.CreateDb(Arg.Any<RocksDbSettings>()).Returns(trieDb, clonedDb); | ||
|
||
FullPruningDb fullPruningDb = new(new RocksDbSettings("Test", "Test"), rocksDbFactory); | ||
fullPruningDb.TryStartPruning(out IPruningContext pruningContext); | ||
return pruningContext; | ||
} | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
src/Nethermind/Nethermind.Blockchain.Test/FullPruning/DiskFreeSpacePruningTriggerTests.cs
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,55 @@ | ||
// Copyright (c) 2021 Demerzel Solutions Limited | ||
// This file is part of the Nethermind library. | ||
// | ||
// The Nethermind library is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Lesser General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// The Nethermind library is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public License | ||
// along with the Nethermind. If not, see <http://www.gnu.org/licenses/>. | ||
// | ||
|
||
using System; | ||
using System.IO.Abstractions; | ||
using FluentAssertions; | ||
using MathGmp.Native; | ||
using Nethermind.Blockchain.FullPruning; | ||
using Nethermind.Core.Timers; | ||
using NSubstitute; | ||
using NUnit.Framework; | ||
|
||
namespace Nethermind.Blockchain.Test.FullPruning | ||
{ | ||
[Parallelizable(ParallelScope.All)] | ||
public class DiskFreeSpacePruningTriggerTests | ||
{ | ||
[TestCase(999, ExpectedResult = true)] | ||
[TestCase(1000, ExpectedResult = false)] | ||
public bool triggers_on_low_free_space(int availableFreeSpace) | ||
{ | ||
ITimerFactory timerFactory = Substitute.For<ITimerFactory>(); | ||
ITimer timer = Substitute.For<ITimer>(); | ||
timerFactory.CreateTimer(Arg.Any<TimeSpan>()).Returns(timer); | ||
|
||
string path = "path"; | ||
IFileSystem fileSystem = Substitute.For<IFileSystem>(); | ||
fileSystem.Path.GetFullPath(path).Returns(path); | ||
fileSystem.Path.GetPathRoot(path).Returns(path); | ||
fileSystem.DriveInfo.FromDriveName(path).AvailableFreeSpace.Returns(availableFreeSpace); | ||
|
||
bool triggered = false; | ||
|
||
DiskFreeSpacePruningTrigger trigger = new(path, 1000, timerFactory, fileSystem); | ||
trigger.Prune += (o, e) => triggered = true; | ||
|
||
timer.Elapsed += Raise.Event(); | ||
return triggered; | ||
} | ||
} | ||
} |
Oops, something went wrong.
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.
It is an API that can be used by externally written plugins. In order to minimize disruption to external plugins in the future this class should be replaced with an interface, possibly a simple one called ITrigger or IPruningTrigger if it requires some data.
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 idea here is that there can be multiple triggers, but we need a central place to collect them, hence the class that can handle multiple interface items via Add.