-
Notifications
You must be signed in to change notification settings - Fork 215
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
code review feedback and delay pruning of activeset to next update
- Loading branch information
1 parent
8d879e0
commit 5a20c04
Showing
17 changed files
with
309 additions
and
187 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 was deleted.
Oops, something went wrong.
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,11 @@ | ||
package prune | ||
|
||
import ( | ||
"github.com/spacemeshos/go-spacemesh/common/types" | ||
) | ||
|
||
//go:generate mockgen -typed -package=prune -destination=./mocks.go -source=./interface.go | ||
|
||
type layerClock interface { | ||
CurrentLayer() types.LayerID | ||
} |
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,22 @@ | ||
package prune | ||
|
||
import ( | ||
"github.com/prometheus/client_golang/prometheus" | ||
|
||
"github.com/spacemeshos/go-spacemesh/metrics" | ||
) | ||
|
||
const namespace = "prune" | ||
|
||
var ( | ||
pruneLatency = metrics.NewHistogramWithBuckets( | ||
"prune_seconds", | ||
namespace, | ||
"prune time in seconds", | ||
[]string{"step"}, | ||
prometheus.ExponentialBuckets(0.01, 2, 10), | ||
) | ||
proposalLatency = pruneLatency.WithLabelValues("proposal") | ||
certLatency = pruneLatency.WithLabelValues("cert") | ||
propTxLatency = pruneLatency.WithLabelValues("proptxs") | ||
) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,60 @@ | ||
package prune | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"go.uber.org/zap" | ||
|
||
"github.com/spacemeshos/go-spacemesh/common/types" | ||
"github.com/spacemeshos/go-spacemesh/sql" | ||
"github.com/spacemeshos/go-spacemesh/sql/certificates" | ||
"github.com/spacemeshos/go-spacemesh/sql/proposals" | ||
"github.com/spacemeshos/go-spacemesh/sql/transactions" | ||
) | ||
|
||
func Prune( | ||
ctx context.Context, | ||
logger *zap.Logger, | ||
db sql.Executor, | ||
lc layerClock, | ||
safeDist uint32, | ||
interval time.Duration, | ||
) { | ||
logger.With().Info("db pruning launched", | ||
zap.Uint32("dist", safeDist), | ||
zap.Duration("interval", interval), | ||
) | ||
for { | ||
select { | ||
case <-ctx.Done(): | ||
return | ||
case <-time.After(interval): | ||
oldest := lc.CurrentLayer() - types.LayerID(safeDist) | ||
t0 := time.Now() | ||
if err := proposals.DeleteBefore(db, oldest); err != nil { | ||
logger.Error("failed to delete proposals", | ||
zap.Stringer("lid", oldest), | ||
zap.Error(err), | ||
) | ||
} | ||
proposalLatency.Observe(time.Since(t0).Seconds()) | ||
t1 := time.Now() | ||
if err := certificates.DeleteCertBefore(db, oldest); err != nil { | ||
logger.Error("failed to delete certificates", | ||
zap.Stringer("lid", oldest), | ||
zap.Error(err), | ||
) | ||
} | ||
certLatency.Observe(time.Since(t1).Seconds()) | ||
t2 := time.Now() | ||
if err := transactions.DeleteProposalTxsBefore(db, oldest); err != nil { | ||
logger.Error("failed to delete proposal tx mapping", | ||
zap.Stringer("lid", oldest), | ||
zap.Error(err), | ||
) | ||
} | ||
propTxLatency.Observe(time.Since(t2).Seconds()) | ||
} | ||
} | ||
} |
Oops, something went wrong.