/// <inheritdoc /> public virtual bool TryStartPruning(bool duplicateReads, out IPruningContext context) { RocksDbSettings ClonedDbSettings() { RocksDbSettings clonedDbSettings = _settings.Clone(); clonedDbSettings.DeleteOnStart = true; return(clonedDbSettings); } // create new pruning context with new sub DB and try setting it as current // returns true when new pruning is started // returns false only on multithreaded access, returns started pruning context then PruningContext newContext = new(this, CreateDb(ClonedDbSettings()), duplicateReads); PruningContext?pruningContext = Interlocked.CompareExchange(ref _pruningContext, newContext, null); context = pruningContext ?? newContext; if (pruningContext is null) { PruningStarted?.Invoke(this, new PruningEventArgs(context)); return(true); } return(false); }
protected virtual void RunPruning(IPruningContext pruning, Keccak statRoot) { try { pruning.MarkStart(); using CopyTreeVisitor copyTreeVisitor = new(pruning, _logManager); VisitingOptions visitingOptions = new() { MaxDegreeOfParallelism = _pruningConfig.FullPruningMaxDegreeOfParallelism }; _stateReader.RunTreeVisitor(copyTreeVisitor, statRoot, visitingOptions); if (!pruning.CancellationTokenSource.IsCancellationRequested) { void CommitOnNewBLock(object o, BlockEventArgs e) { _blockTree.NewHeadBlock -= CommitOnNewBLock; // ReSharper disable AccessToDisposedClosure pruning.Commit(); _lastPruning = DateTime.Now; pruning.Dispose(); // ReSharper restore AccessToDisposedClosure } _blockTree.NewHeadBlock += CommitOnNewBLock; copyTreeVisitor.Finish(); } else { pruning.Dispose(); } } catch (Exception) { pruning.Dispose(); throw; } }
private void SetCurrentPruning(IPruningContext pruningContext) { IPruningContext?oldPruning = Interlocked.Exchange(ref _currentPruning, pruningContext); if (oldPruning is not null) { Task.Run(() => oldPruning.Dispose()); } }
public CopyTreeVisitor( IPruningContext pruningContext, ILogManager logManager) { _pruningContext = pruningContext; _cancellationToken = pruningContext.CancellationTokenSource.Token; _logger = logManager.GetClassLogger(); _stopwatch = new Stopwatch(); }
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); }
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); }
protected override void RunPruning(IPruningContext pruning, Keccak stateRoot) { base.RunPruning(pruning, stateRoot); WaitHandle.Set(); }
public bool CanStartPruning => _pruningContext is null; // we can start pruning only if no pruning is in progress public bool TryStartPruning(out IPruningContext context) => TryStartPruning(true, out context);
public PruningEventArgs(IPruningContext context) { Context = context; }
public PruningEventArgs(IPruningContext context, bool success) { Context = context; Success = success; }