-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1f06f5b
commit 46563b1
Showing
17 changed files
with
176 additions
and
80 deletions.
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
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
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,67 @@ | ||
package pruning | ||
|
||
import "cosmossdk.io/store/v2" | ||
|
||
// Manager is a struct that manages the pruning of old versions of the SC and SS. | ||
type Manager struct { | ||
// scPruner is the pruner for the SC. | ||
scPruner store.Pruner | ||
// scPruningOptions are the pruning options for the SC. | ||
scPruningOptions *store.PruneOptions | ||
// ssPruner is the pruner for the SS. | ||
ssPruner store.Pruner | ||
// ssPruningOptions are the pruning options for the SS. | ||
ssPruningOptions *store.PruneOptions | ||
} | ||
|
||
// NewManager creates a new Pruning Manager. | ||
func NewManager(scPruner, ssPruner store.Pruner, scPruningOptions, ssPruningOptions *store.PruneOptions) *Manager { | ||
return &Manager{ | ||
scPruner: scPruner, | ||
scPruningOptions: scPruningOptions, | ||
ssPruner: ssPruner, | ||
ssPruningOptions: ssPruningOptions, | ||
} | ||
} | ||
|
||
// Prune prunes the SC and SS to the provided version. | ||
// | ||
// NOTE: It can be called outside of the store manually. | ||
func (m *Manager) Prune(version uint64) error { | ||
// Prune the SC. | ||
if m.scPruningOptions != nil { | ||
if prune, pruneTo := m.scPruningOptions.ShouldPrune(version); prune { | ||
if err := m.scPruner.Prune(pruneTo); err != nil { | ||
return err | ||
} | ||
} | ||
} | ||
|
||
// Prune the SS. | ||
if m.ssPruningOptions != nil { | ||
if prune, pruneTo := m.ssPruningOptions.ShouldPrune(version); prune { | ||
if err := m.ssPruner.Prune(pruneTo); err != nil { | ||
return err | ||
} | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// SignalCommit signals to the manager that a commit has started or finished. | ||
// This is used to avoid concurrent writes while pruning. | ||
func (m *Manager) SignalCommit(start bool, version uint64) error { | ||
if scPausablePruner, ok := m.scPruner.(store.PausablePruner); ok { | ||
scPausablePruner.PausePruning(start) | ||
} | ||
if ssPausablePruner, ok := m.ssPruner.(store.PausablePruner); ok { | ||
ssPausablePruner.PausePruning(start) | ||
} | ||
|
||
if !start { | ||
return m.Prune(version) | ||
} | ||
|
||
return nil | ||
} |
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
Oops, something went wrong.