Skip to content

Commit

Permalink
Merge pull request #6174 from onflow/leo/v0.33-link-checkpoint
Browse files Browse the repository at this point in the history
Backport v0.33 link checkpoint
  • Loading branch information
zhangchiqing authored Jul 10, 2024
2 parents bfec5a5 + 4b12c7b commit 01c1ca0
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 17 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
1 change: 0 additions & 1 deletion integration/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ require (
github.com/onflow/flow-go/crypto v0.25.0
github.com/onflow/flow-go/insecure v0.0.0-00010101000000-000000000000
github.com/onflow/flow/protobuf/go/flow v0.4.4
github.com/plus3it/gorecurcopy v0.0.1
github.com/prometheus/client_golang v1.18.0
github.com/prometheus/client_model v0.5.0
github.com/prometheus/common v0.45.0
Expand Down
2 changes: 0 additions & 2 deletions integration/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1042,8 +1042,6 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg=
github.com/pkg/term v1.1.0/go.mod h1:E25nymQcrSllhX42Ok8MRm1+hyBdHY0dCeiKZ9jpNGw=
github.com/plus3it/gorecurcopy v0.0.1 h1:H7AgvM0N/uIo7o1PQRlewEGQ92BNr7DqbPy5lnR3uJI=
github.com/plus3it/gorecurcopy v0.0.1/go.mod h1:NvVTm4RX68A1vQbHmHunDO4OtBLVroT6CrsiqAzNyJA=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/polydawn/refmt v0.89.0 h1:ADJTApkvkeBZsN0tBTx8QjpD9JkmxbKp0cxfr9qszm4=
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 01c1ca0

Please sign in to comment.