Skip to content
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

[Execution] add logger to compactor and only log when we do something #1350

Merged
merged 2 commits into from
Sep 28, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/execution/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ func main() {
if err != nil {
return nil, fmt.Errorf("cannot create checkpointer: %w", err)
}
compactor := wal.NewCompactor(checkpointer, 10*time.Second, checkpointDistance, checkpointsToKeep)
compactor := wal.NewCompactor(checkpointer, 10*time.Second, checkpointDistance, checkpointsToKeep, node.Logger.With().Str("subcomponent", "checkpointer").Logger())

return compactor, nil
}).
Expand Down
11 changes: 6 additions & 5 deletions ledger/complete/wal/compactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ import (
"sync"
"time"

"github.com/rs/zerolog"

"github.com/onflow/flow-go/module/lifecycle"
"github.com/onflow/flow-go/module/observable"
)

type Compactor struct {
checkpointer *Checkpointer
logger zerolog.Logger
stopc chan struct{}
lm *lifecycle.LifecycleManager
sync.Mutex
Expand All @@ -21,12 +24,13 @@ type Compactor struct {
checkpointsToKeep uint
}

func NewCompactor(checkpointer *Checkpointer, interval time.Duration, checkpointDistance uint, checkpointsToKeep uint) *Compactor {
func NewCompactor(checkpointer *Checkpointer, interval time.Duration, checkpointDistance uint, checkpointsToKeep uint, logger zerolog.Logger) *Compactor {
if checkpointDistance < 1 {
checkpointDistance = 1
}
return &Compactor{
checkpointer: checkpointer,
logger: logger,
stopc: make(chan struct{}),
observers: make(map[observable.Observer]struct{}),
lm: lifecycle.NewLifecycleManager(),
Expand Down Expand Up @@ -105,16 +109,13 @@ func (c *Compactor) createCheckpoints() (int, error) {
return -1, fmt.Errorf("cannot get latest checkpoint: %w", err)
}

fmt.Printf("creating a checkpoint from segment %d to segment %d\n", from, to)

// we only return a positive value if the latest checkpoint index has changed
newLatestCheckpoint := -1
// more then one segment means we can checkpoint safely up to `to`-1
// presumably last segment is being written to
if to-from > int(c.checkpointDistance) {
checkpointNumber := to - 1
fmt.Printf("checkpointing to %d\n", checkpointNumber)

c.logger.Info().Msgf("creating a checkpoint from segment %d to segment %d\n", from, checkpointNumber)
err = c.checkpointer.Checkpoint(checkpointNumber, func() (io.WriteCloser, error) {
return c.checkpointer.CheckpointWriter(checkpointNumber)
})
Expand Down
4 changes: 2 additions & 2 deletions ledger/complete/wal/compactor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func Test_Compactor(t *testing.T) {
checkpointer, err := wal.NewCheckpointer()
require.NoError(t, err)

compactor := NewCompactor(checkpointer, 100*time.Millisecond, checkpointDistance, 1) //keep only latest checkpoint
compactor := NewCompactor(checkpointer, 100*time.Millisecond, checkpointDistance, 1, zerolog.Nop()) //keep only latest checkpoint
co := CompactorObserver{fromBound: 9, done: make(chan struct{})}
compactor.Subscribe(&co)

Expand Down Expand Up @@ -249,7 +249,7 @@ func Test_Compactor_checkpointInterval(t *testing.T) {
checkpointer, err := wal.NewCheckpointer()
require.NoError(t, err)

compactor := NewCompactor(checkpointer, 100*time.Millisecond, checkpointDistance, 2)
compactor := NewCompactor(checkpointer, 100*time.Millisecond, checkpointDistance, 2, zerolog.Nop())

// Generate the tree and create WAL
for i := 0; i < size; i++ {
Expand Down