-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 3 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
103 changes: 103 additions & 0 deletions
103
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,103 @@ | ||
package downloaderrawdb | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"os" | ||
"path/filepath" | ||
"time" | ||
|
||
"github.com/erigontech/erigon-lib/chain/snapcfg" | ||
"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 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 allFilesComplete(tx kv.Tx, preverifiedCfg *snapcfg.Cfg, dirs datadir.Dirs) (allFilesDownloadComplete bool) { | ||
for _, p := range preverifiedCfg.Preverified { | ||
complete, _, _ := CheckFileComplete(tx, p.Name, dirs.Snap) | ||
if !complete { | ||
return false | ||
} | ||
} | ||
return true | ||
} | ||
|
||
func AllFilesComplete(preverifiedCfg *snapcfg.Cfg, dirs datadir.Dirs) (allFilesDownloadComplete bool, err error) { | ||
limiter := semaphore.NewWeighted(9_000) | ||
downloaderDB, err := kv2.NewMDBX(log.Root()).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 = allFilesComplete(tx, preverifiedCfg, dirs) | ||
return nil | ||
}); err != nil { | ||
return false, err | ||
} | ||
return allFilesDownloadComplete, 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.
the naming is OptimisticallReopenFolder, but the
ReopenFolder
function it called doesn't open file in optimistic way.