Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions go/worker/storage/statesync/prune.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package statesync

import (
"fmt"

"github.com/oasisprotocol/oasis-core/go/common/logging"
"github.com/oasisprotocol/oasis-core/go/storage/mkvs/db/api"
)

type pruneHandler struct {
logger *logging.Logger
worker *Worker
}

func (p *pruneHandler) Prune(rounds []uint64) error {
// Make sure we never prune past what was synced.
lastSycnedRound, _, _ := p.worker.GetLastSynced()

for _, round := range rounds {
if round >= lastSycnedRound {
return fmt.Errorf("worker/storage: tried to prune past last synced round (last synced: %d)",
lastSycnedRound,
)
}

// Old suggestion: Make sure we don't prune rounds that need to be checkpointed but haven't been yet.
Comment thread
peternose marked this conversation as resolved.

p.logger.Debug("pruning storage for round", "round", round)

// Prune given block.
err := p.worker.localStorage.NodeDB().Prune(round)
switch err {
case nil:
case api.ErrNotEarliest:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would keep import rename, as api is so general and is not the best name for a package.

p.logger.Debug("skipping non-earliest round",
"round", round,
)
continue
default:
p.logger.Error("failed to prune block",
"err", err,
)
return err
}
}

return nil
}
41 changes: 0 additions & 41 deletions go/worker/storage/statesync/state_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
storageApi "github.com/oasisprotocol/oasis-core/go/storage/api"
"github.com/oasisprotocol/oasis-core/go/storage/mkvs/checkpoint"
dbApi "github.com/oasisprotocol/oasis-core/go/storage/mkvs/db/api"
mkvsDB "github.com/oasisprotocol/oasis-core/go/storage/mkvs/db/api"
workerCommon "github.com/oasisprotocol/oasis-core/go/worker/common"
"github.com/oasisprotocol/oasis-core/go/worker/common/committee"
"github.com/oasisprotocol/oasis-core/go/worker/registration"
Expand Down Expand Up @@ -1364,43 +1363,3 @@ mainLoop:
// some new blocks, but only as many as were already in-flight at the point when the main
// context was canceled.
}

type pruneHandler struct {
logger *logging.Logger
worker *Worker
}

func (p *pruneHandler) Prune(rounds []uint64) error {
// Make sure we never prune past what was synced.
lastSycnedRound, _, _ := p.worker.GetLastSynced()

for _, round := range rounds {
if round >= lastSycnedRound {
return fmt.Errorf("worker/storage: tried to prune past last synced round (last synced: %d)",
lastSycnedRound,
)
}

// TODO: Make sure we don't prune rounds that need to be checkpointed but haven't been yet.

p.logger.Debug("pruning storage for round", "round", round)

// Prune given block.
err := p.worker.localStorage.NodeDB().Prune(round)
switch err {
case nil:
case mkvsDB.ErrNotEarliest:
p.logger.Debug("skipping non-earliest round",
"round", round,
)
continue
default:
p.logger.Error("failed to prune block",
"err", err,
)
return err
}
}

return nil
}