Skip to content

Commit

Permalink
link checkpoint on bootstrapping
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangchiqing committed Jul 3, 2024
1 parent 82de39d commit 54a7a7a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 14 deletions.
11 changes: 6 additions & 5 deletions cmd/execution_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -1391,6 +1391,7 @@ func (exeNode *ExecutionNode) LoadBootstrapper(node *NodeConfig) error {

// if the execution database does not exist, then we need to bootstrap the execution database.
if !bootstrapped {

err := wal.CheckpointHasRootHash(
node.Logger,
path.Join(node.BootstrapDir, bootstrapFilenames.DirnameExecutionState),
Expand Down Expand Up @@ -1498,16 +1499,16 @@ func copyBootstrapState(dir, trie string) error {
from, to := path.Join(dir, bootstrapFilenames.DirnameExecutionState), trie

log.Info().Str("dir", dir).Str("trie", trie).
Msgf("copying checkpoint file %v from directory: %v, to: %v", filename, from, to)
Msgf("linking checkpoint file %v from directory: %v, to: %v", filename, from, to)

copiedFiles, err := wal.CopyCheckpointFile(filename, from, to)
copiedFiles, err := wal.SoftlinkCheckpointFile(filename, from, to)
if err != nil {
return fmt.Errorf("can not copy checkpoint file %s, from %s to %s",
filename, from, to)
return fmt.Errorf("can not link checkpoint file %s, from %s to %s, %w",
filename, from, to, err)
}

for _, newPath := range copiedFiles {
fmt.Printf("copied root checkpoint file from directory: %v, to: %v\n", from, newPath)
fmt.Printf("linked root checkpoint file from directory: %v, to: %v\n", from, newPath)
}

return nil
Expand Down
9 changes: 0 additions & 9 deletions integration/localnet/builder/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ import (
"time"

"github.com/go-yaml/yaml"
"github.com/plus3it/gorecurcopy"

"github.com/onflow/flow-go/cmd/build"
"github.com/onflow/flow-go/integration/testnet"
"github.com/onflow/flow-go/model/bootstrap"
"github.com/onflow/flow-go/model/flow"
)

Expand Down Expand Up @@ -387,13 +385,6 @@ func prepareExecutionService(container testnet.ContainerConfig, i int, n int) Se
panic(err)
}

// we need to actually copy the execution state into the directory for bootstrapping
sourceDir := "./" + filepath.Join(BootstrapDir, bootstrap.DirnameExecutionState)
err = gorecurcopy.CopyDirectory(sourceDir, trieDir)
if err != nil {
panic(err)
}

enableNewIngestionEngine := true

service.Command = append(service.Command,
Expand Down
32 changes: 32 additions & 0 deletions ledger/complete/wal/checkpointer.go
Original file line number Diff line number Diff line change
Expand Up @@ -1083,3 +1083,35 @@ func CopyCheckpointFile(filename string, from string, to string) (

return newPaths, nil
}

// SoftlinkCheckpointFile creates soft links of the checkpoint file including the part files from the given `from` to
// the `to` directory
func SoftlinkCheckpointFile(filename string, from string, to string) ([]string, error) {

// It's possible that the trie dir does not yet exist. If not this will create the the required path
err := os.MkdirAll(to, 0700)
if err != nil {
return nil, err
}

// checkpoint V6 produces multiple checkpoint part files that need to be copied over
pattern := filePathPattern(from, filename)
matched, err := filepath.Glob(pattern)
if err != nil {
return nil, fmt.Errorf("could not glob checkpoint file with pattern %v: %w", pattern, err)
}

newPaths := make([]string, len(matched))
for i, match := range matched {
_, partfile := filepath.Split(match)
newPath := filepath.Join(to, partfile)
newPaths[i] = newPath

err := os.Symlink(match, newPath)
if err != nil {
return nil, fmt.Errorf("cannot link file from %v to %v: %w", match, newPath, err)
}
}

return newPaths, nil
}

0 comments on commit 54a7a7a

Please sign in to comment.