Skip to content

Commit

Permalink
snap: no tmp subfolder (#4940)
Browse files Browse the repository at this point in the history
* save

* save

* save

* save

* save
  • Loading branch information
AskAlexSharov authored Aug 8, 2022
1 parent bc7921a commit 1b20322
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 51 deletions.
49 changes: 4 additions & 45 deletions cmd/downloader/downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,10 @@ func New(cfg *downloadercfg.Cfg) (*Downloader, error) {
if common.FileExist(cfg.DataDir + "_tmp") { // migration from prev versions
_ = os.Rename(cfg.DataDir+"_tmp", filepath.Join(cfg.DataDir, "tmp")) // ignore error, because maybe they are on different drive, or target folder already created manually, all is fine
}
if !common.FileExist(filepath.Join(cfg.DataDir, "db")) && !HasSegFile(cfg.DataDir) { // it's ok to remove "datadir/snapshots/db" dir or add .seg files manually
cfg.DataDir = filepath.Join(cfg.DataDir, "tmp")
} else {
if err := copyFromTmp(cfg.DataDir); err != nil {
return nil, err
}
if err := moveFromTmp(cfg.DataDir); err != nil {
return nil, err
}

db, c, m, torrentClient, err := openClient(cfg.ClientConfig)
if err != nil {
return nil, fmt.Errorf("openClient: %w", err)
Expand Down Expand Up @@ -154,14 +151,10 @@ func (d *Downloader) ReCalcStats(interval time.Duration) {
stats.PeersUnique = int32(len(peers))
stats.FilesTotal = int32(len(torrents))

if !prevStats.Completed && stats.Completed {
d.onComplete()
}

d.stats = stats
}

func copyFromTmp(snapDir string) error {
func moveFromTmp(snapDir string) error {
tmpDir := filepath.Join(snapDir, "tmp")
if !common.FileExist(tmpDir) {
return nil
Expand Down Expand Up @@ -189,40 +182,6 @@ func copyFromTmp(snapDir string) error {
return nil
}

// onComplete - only once - after download of all files fully done:
// - closing torrent client, closing downloader db
// - removing _tmp suffix from snapDir
// - open new torrentClient and db
func (d *Downloader) onComplete() {
snapDir, lastPart := filepath.Split(d.cfg.DataDir)
if lastPart != "tmp" {
return
}

d.clientLock.Lock()
defer d.clientLock.Unlock()

d.torrentClient.Close()
d.folder.Close()
d.pieceCompletionDB.Close()
d.db.Close()

if err := copyFromTmp(snapDir); err != nil {
panic(err)
}
d.cfg.DataDir = snapDir

db, c, m, torrentClient, err := openClient(d.cfg.ClientConfig)
if err != nil {
panic(err)
}
d.db = db
d.pieceCompletionDB = c
d.folder = m
d.torrentClient = torrentClient
_ = d.addSegments()
}

func (d *Downloader) verify() error {
total := 0
for _, t := range d.torrentClient.Torrents() {
Expand Down
5 changes: 0 additions & 5 deletions cmd/downloader/downloader/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/ledgerwatch/erigon-lib/kv"
"github.com/ledgerwatch/erigon/cmd/downloader/downloader/downloadercfg"
"github.com/ledgerwatch/erigon/cmd/downloader/trackers"
"github.com/ledgerwatch/erigon/common"
"github.com/ledgerwatch/erigon/turbo/snapshotsync/snap"
"github.com/ledgerwatch/log/v3"
"golang.org/x/sync/semaphore"
Expand Down Expand Up @@ -326,10 +325,6 @@ func VerifyDtaFiles(ctx context.Context, snapDir string) error {
logEvery := time.NewTicker(5 * time.Second)
defer logEvery.Stop()

tmpSnapDir := filepath.Join(snapDir, "tmp") // snapshots are in sub-dir "tmp", if not fully downloaded
if common.FileExist(tmpSnapDir) {
snapDir = tmpSnapDir
}
files, err := AllTorrentPaths(snapDir)
if err != nil {
return err
Expand Down
1 change: 0 additions & 1 deletion eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ func New(stack *node.Node, config *ethconfig.Config, logger log.Logger) (*Ethere
}

ctx, ctxCancel := context.WithCancel(context.Background())
log.Info("Using snapshots", "on", config.Snapshot.Enabled)

// kv_remote architecture does blocks on stream.Send - means current architecture require unlimited amount of txs to provide good throughput
//limiter := make(chan struct{}, kv.ReadersLimit)
Expand Down

0 comments on commit 1b20322

Please sign in to comment.