mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2025-01-06 19:12:19 +00:00
79ed8cad35
This change introduces additional processes to manage snapshot uploading for E2 snapshots: ## erigon snapshots upload The `snapshots uploader` command starts a version of erigon customized for uploading snapshot files to a remote location. It breaks the stage execution process after the senders stage and then uses the snapshot stage to send uploaded headers, bodies and (in the case of polygon) bor spans and events to snapshot files. Because this process avoids execution in run signifigantly faster than a standard erigon configuration. The uploader uses rclone to send seedable (100K or 500K blocks) to a remote storage location specified in the rclone config file. The **uploader** is configured to minimize disk usage by doing the following: * It removes snapshots once they are loaded * It aggressively prunes the database once entities are transferred to snapshots in addition to this it has the following performance related features: * maximizes the workers allocated to snapshot processing to improve throughput * Can be started from scratch by downloading the latest snapshots from the remote location to seed processing ## snapshots command Is a stand alone command for managing remote snapshots it has the following sub commands * **cmp** - compare snapshots * **copy** - copy snapshots * **verify** - verify snapshots * **manifest** - manage the manifest file in the root of remote snapshot locations * **torrent** - manage snapshot torrent files
146 lines
2.8 KiB
Go
146 lines
2.8 KiB
Go
/*
|
|
Copyright 2021 Erigon contributors
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
package dir
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
)
|
|
|
|
func MustExist(path ...string) {
|
|
const perm = 0764 // user rwx, group rw, other r
|
|
for _, p := range path {
|
|
if err := os.MkdirAll(p, perm); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
}
|
|
|
|
func Exist(path string) bool {
|
|
_, err := os.Stat(path)
|
|
if err != nil && os.IsNotExist(err) {
|
|
return false
|
|
}
|
|
return true
|
|
}
|
|
|
|
func FileExist(path string) bool {
|
|
fi, err := os.Stat(path)
|
|
if err != nil && os.IsNotExist(err) {
|
|
return false
|
|
}
|
|
if !fi.Mode().IsRegular() {
|
|
return false
|
|
}
|
|
return true
|
|
}
|
|
|
|
func FileNonZero(path string) bool {
|
|
fi, err := os.Stat(path)
|
|
if err != nil && os.IsNotExist(err) {
|
|
return false
|
|
}
|
|
if !fi.Mode().IsRegular() {
|
|
return false
|
|
}
|
|
return fi.Size() > 0
|
|
}
|
|
|
|
// nolint
|
|
func WriteFileWithFsync(name string, data []byte, perm os.FileMode) error {
|
|
f, err := os.OpenFile(name, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, perm)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer f.Close()
|
|
_, err = f.Write(data)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
err = f.Sync()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return err
|
|
}
|
|
|
|
func Recreate(dir string) {
|
|
if Exist(dir) {
|
|
_ = os.RemoveAll(dir)
|
|
}
|
|
MustExist(dir)
|
|
}
|
|
|
|
func HasFileOfType(dir, ext string) bool {
|
|
files, err := os.ReadDir(dir)
|
|
if err != nil {
|
|
return false
|
|
}
|
|
for _, f := range files {
|
|
if f.IsDir() {
|
|
continue
|
|
}
|
|
if filepath.Ext(f.Name()) == ext {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
// nolint
|
|
func DeleteFiles(dirs ...string) error {
|
|
for _, dir := range dirs {
|
|
files, err := ListFiles(dir)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
for _, fPath := range files {
|
|
if err := os.Remove(fPath); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func ListFiles(dir string, extensions ...string) ([]string, error) {
|
|
files, err := os.ReadDir(dir)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
res := make([]string, 0, len(files))
|
|
for _, f := range files {
|
|
if f.IsDir() && !f.Type().IsRegular() {
|
|
continue
|
|
}
|
|
match := false
|
|
if len(extensions) == 0 {
|
|
match = true
|
|
}
|
|
for _, ext := range extensions {
|
|
if filepath.Ext(f.Name()) == ext { // filter out only compressed files
|
|
match = true
|
|
}
|
|
}
|
|
if !match {
|
|
continue
|
|
}
|
|
res = append(res, filepath.Join(dir, f.Name()))
|
|
}
|
|
return res, nil
|
|
}
|