good morning!!!!

Skip to content
Snippets Groups Projects
Unverified Commit 10bcbf4a authored by Alex Sharov's avatar Alex Sharov Committed by GitHub
Browse files

Snap: faster Erigon re-start (#4201)

parent 2396765c
Branches
Tags
No related merge requests found
...@@ -285,15 +285,15 @@ func MainLoop(ctx context.Context, d *Downloader, silent bool) { ...@@ -285,15 +285,15 @@ func MainLoop(ctx context.Context, d *Downloader, silent bool) {
logEvery := time.NewTicker(20 * time.Second) logEvery := time.NewTicker(20 * time.Second)
defer logEvery.Stop() defer logEvery.Stop()
interval := 10 * time.Second statInterval := 20 * time.Second
statEvery := time.NewTicker(interval) statEvery := time.NewTicker(statInterval)
defer statEvery.Stop() defer statEvery.Stop()
for { for {
select { select {
case <-ctx.Done(): case <-ctx.Done():
return return
case <-statEvery.C: case <-statEvery.C:
d.ReCalcStats(interval) d.ReCalcStats(statInterval)
case <-logEvery.C: case <-logEvery.C:
if silent { if silent {
......
...@@ -2,6 +2,7 @@ package downloader ...@@ -2,6 +2,7 @@ package downloader
import ( import (
"context" "context"
"time"
"github.com/anacrolix/torrent/metainfo" "github.com/anacrolix/torrent/metainfo"
"github.com/ledgerwatch/erigon-lib/gointerfaces" "github.com/ledgerwatch/erigon-lib/gointerfaces"
...@@ -57,8 +58,8 @@ func (s *GrpcServer) Download(ctx context.Context, request *proto_downloader.Dow ...@@ -57,8 +58,8 @@ func (s *GrpcServer) Download(ctx context.Context, request *proto_downloader.Dow
return return
} }
}(magnet.String()) }(magnet.String())
} }
s.d.ReCalcStats(10 * time.Second) // immediately call ReCalc to set stat.Complete flag
return &emptypb.Empty{}, nil return &emptypb.Empty{}, nil
} }
......
...@@ -2,6 +2,7 @@ package commands ...@@ -2,6 +2,7 @@ package commands
import ( import (
"context" "context"
"encoding/binary"
"fmt" "fmt"
"os" "os"
"text/tabwriter" "text/tabwriter"
...@@ -9,6 +10,7 @@ import ( ...@@ -9,6 +10,7 @@ import (
"github.com/ledgerwatch/erigon-lib/common" "github.com/ledgerwatch/erigon-lib/common"
"github.com/ledgerwatch/erigon-lib/kv" "github.com/ledgerwatch/erigon-lib/kv"
"github.com/ledgerwatch/erigon/core" "github.com/ledgerwatch/erigon/core"
"github.com/ledgerwatch/erigon/core/rawdb"
"github.com/ledgerwatch/erigon/eth/stagedsync" "github.com/ledgerwatch/erigon/eth/stagedsync"
"github.com/ledgerwatch/erigon/eth/stagedsync/stages" "github.com/ledgerwatch/erigon/eth/stagedsync/stages"
"github.com/ledgerwatch/erigon/ethdb/prune" "github.com/ledgerwatch/erigon/ethdb/prune"
...@@ -267,5 +269,13 @@ func printStages(db kv.Tx) error { ...@@ -267,5 +269,13 @@ func printStages(db kv.Tx) error {
} }
fmt.Fprintf(w, "sequence: EthTx=%d, NonCanonicalTx=%d\n\n", s1, s2) fmt.Fprintf(w, "sequence: EthTx=%d, NonCanonicalTx=%d\n\n", s1, s2)
{
firstNonGenesis, err := rawdb.SecondKey(db, kv.Headers)
if err != nil {
return err
}
fmt.Fprintf(w, "first header in db: %d\n\n", binary.BigEndian.Uint64(firstNonGenesis))
}
return nil return nil
} }
...@@ -47,7 +47,24 @@ Content-Type: application/json ...@@ -47,7 +47,24 @@ Content-Type: application/json
### ###
# curl -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_getTransactionByHash", "params": ["0x8582cf1230e0b1c191a306e907ee4abe3459607dfa84143ebd496de7e77fa45e", true], "id":1}' localhost:8545 # curl -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_getTransactionByHash", "params": ["0x1302cc71b89c1482b18a97a6fa2c9c375f4bf7548122363b6e91528440272fde"], "id":1}' localhost:8545
POST localhost:8545
Content-Type: application/json
{
"jsonrpc": "2.0",
"method": "eth_getTransactionByHash",
"params": [
"0x1302cc71b89c1482b18a97a6fa2c9c375f4bf7548122363b6e91528440272fde"
],
"id": 1
}
###
# curl -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_getTransactionByHash", "params": ["0x1302cc71b89c1482b18a97a6fa2c9c375f4bf7548122363b6e91528440272fde"], "id":1}' localhost:8545
POST localhost:8545 POST localhost:8545
Content-Type: application/json Content-Type: application/json
......
...@@ -1256,6 +1256,11 @@ func WaitForDownloader(ctx context.Context, cfg HeadersCfg) error { ...@@ -1256,6 +1256,11 @@ func WaitForDownloader(ctx context.Context, cfg HeadersCfg) error {
logEvery := time.NewTicker(logInterval) logEvery := time.NewTicker(logInterval)
defer logEvery.Stop() defer logEvery.Stop()
// Check once without delay, for faster erigon re-start
if stats, err := cfg.snapshotDownloader.Stats(ctx, &proto_downloader.StatsRequest{}); err == nil && stats.Completed {
return nil
}
var m runtime.MemStats var m runtime.MemStats
// Print download progress until all segments are available // Print download progress until all segments are available
Loop: Loop:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment