-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RPCDaemon and Erigon: don't open files at startup if download is not finished (StageSnapshots == 0) #12332
Merged
Merged
RPCDaemon and Erigon: don't open files at startup if download is not finished (StageSnapshots == 0) #12332
Changes from 12 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
e729c1f
save
AskAlexSharov 9c0fe92
save
AskAlexSharov 8c3eeb4
save
AskAlexSharov 30be59c
save
AskAlexSharov 152632f
save
AskAlexSharov d903430
save
AskAlexSharov 333a4fe
save
AskAlexSharov 74161df
save
AskAlexSharov 9e2c1c1
save
AskAlexSharov f582712
save
AskAlexSharov c50a0c9
save
AskAlexSharov ab8f414
save
AskAlexSharov 6db4f42
save
AskAlexSharov 1726218
save
AskAlexSharov 8beff9a
Merge branch 'main' into rpcdaemon_dont_open_uncomplete
AskAlexSharov 690ae7b
save
AskAlexSharov c1071e2
save
AskAlexSharov 1f962b1
save
AskAlexSharov e47c663
save
AskAlexSharov 0678cee
save
AskAlexSharov 9a69904
save
AskAlexSharov 80586ac
save
AskAlexSharov 678ee95
save
AskAlexSharov 29ba71d
save
AskAlexSharov 7c00ba5
save
AskAlexSharov fff9555
Merge branch 'main' into rpcdaemon_dont_open_uncomplete
AskAlexSharov e7c0634
save
AskAlexSharov a0ffe2a
save
AskAlexSharov 79f57b8
save
AskAlexSharov d5f6c3f
save
AskAlexSharov ad65988
save
AskAlexSharov 66fed7b
save
AskAlexSharov 7f092e9
save
AskAlexSharov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
erigon-lib/downloader/downloaderrawdb/accessors_downloader.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
package downloaderrawdb | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"os" | ||
"path/filepath" | ||
"time" | ||
|
||
"github.com/erigontech/erigon-lib/common/datadir" | ||
"github.com/erigontech/erigon-lib/kv" | ||
kv2 "github.com/erigontech/erigon-lib/kv/mdbx" | ||
"github.com/erigontech/erigon-lib/log/v3" | ||
"golang.org/x/sync/semaphore" | ||
) | ||
|
||
type TorrentInfo struct { | ||
Name string `json:"name"` | ||
Hash []byte `json:"hash"` | ||
Length *int64 `json:"length,omitempty"` | ||
Created *time.Time `json:"created,omitempty"` | ||
Completed *time.Time `json:"completed,omitempty"` | ||
} | ||
|
||
func ReadTorrentInfo(downloaderDBTx kv.Tx, name string) (*TorrentInfo, error) { | ||
var info TorrentInfo | ||
infoBytes, err := downloaderDBTx.GetOne(kv.BittorrentInfo, []byte(name)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if len(infoBytes) == 0 { | ||
return &info, nil | ||
} | ||
if err = json.Unmarshal(infoBytes, &info); err != nil { | ||
return nil, err | ||
} | ||
return &info, nil | ||
} | ||
|
||
func ReadTorrentInfoHash(downloaderDBTx kv.Tx, name string) (hashBytes []byte, err error) { | ||
infoBytes, err := downloaderDBTx.GetOne(kv.BittorrentInfo, []byte(name)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if len(infoBytes) == 20 { | ||
return infoBytes, nil | ||
} | ||
|
||
var info TorrentInfo | ||
if err = json.Unmarshal(infoBytes, &info); err == nil { | ||
return info.Hash, nil | ||
} | ||
return nil, nil | ||
} | ||
|
||
func WriteTorrentInfo(tx kv.RwTx, info *TorrentInfo) error { | ||
infoBytes, err := json.Marshal(info) | ||
if err != nil { | ||
return err | ||
} | ||
return tx.Put(kv.BittorrentInfo, []byte(info.Name), infoBytes) | ||
} | ||
|
||
func CheckFileComplete(tx kv.Tx, name string, snapDir string) (bool, int64, *time.Time) { | ||
info, err := ReadTorrentInfo(tx, name) | ||
if err != nil { | ||
return false, 0, nil | ||
} | ||
if info.Completed != nil && info.Completed.Before(time.Now()) { | ||
if info.Length != nil { | ||
if fi, err := os.Stat(filepath.Join(snapDir, name)); err == nil { | ||
return fi.Size() == *info.Length && fi.ModTime().Equal(*info.Completed), *info.Length, info.Completed | ||
} | ||
} | ||
} | ||
return false, 0, nil | ||
} | ||
|
||
func AllSegmentsDownloadCompleteFlag(dirs datadir.Dirs) (allFilesDownloadComplete bool, err error) { | ||
limiter := semaphore.NewWeighted(9_000) | ||
downloaderDB, err := kv2.NewMDBX(log.Root()).Label(kv.DownloaderDB).WithTableCfg(func(defaultBuckets kv.TableCfg) kv.TableCfg { | ||
return kv.TablesCfgByLabel(kv.DownloaderDB) | ||
}).RoTxsLimiter(limiter).Path(dirs.Downloader).Accede().Open(context.Background()) | ||
if err != nil { | ||
return false, err | ||
} | ||
defer downloaderDB.Close() | ||
|
||
if err := downloaderDB.View(context.Background(), func(tx kv.Tx) error { | ||
allFilesDownloadComplete, err = ReadAllCompleteFlag(tx) | ||
return err | ||
}); err != nil { | ||
return false, err | ||
} | ||
return allFilesDownloadComplete, nil | ||
} | ||
|
||
var AllCompleteFlagKey = []byte("all_complete") | ||
|
||
func WriteAllCompleteFlag(tx kv.RwTx) error { | ||
return tx.Put(kv.BittorrentInfo, AllCompleteFlagKey, []byte{1}) | ||
} | ||
func ReadAllCompleteFlag(tx kv.Tx) (bool, error) { | ||
v, err := tx.GetOne(kv.BittorrentInfo, AllCompleteFlagKey) | ||
if err != nil { | ||
return false, err | ||
} | ||
if len(v) == 0 { | ||
return false, nil | ||
} | ||
return v[0] == 1, nil | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There're two steps of downloading: 1. header chain segments(headers and bodies) 2. other segments(transactions...)
stats.Completed is true after the first step completed, but will be re-written to false once step2 starts.
should we wait all types of segments complete and then set the flag?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add some logs locally and here's logs test on sepolia:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And i'm a little confused that the flag seems to work the same way as prohibit_new_downloads.lock file, cause the file is written in right after specific types of segments complete downloading and
stats.Completed
turns true. However you saidIn the past i used prohibit_new_downloads.lock file for this - but now it created before download completion (and it’s fine)
.If the prohibit_new_downloads file cannot mark the completion of download, then the flag cannot too.
If above is right, we can still use the way used by previous version of the PR , this function should work:
e729c1f#diff-f98a3c65d957c3d92bee0d12aeed5ec1ee902de014f1cda287f430808ea1aa2eR63
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You right. Maybe i must use “StageSnapshots progress > 0”