good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
E
Erigon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
a
Erigon
Commits
f5a82300
Unverified
Commit
f5a82300
authored
3 years ago
by
Alex Sharov
Committed by
GitHub
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Snapshots: write hashes to file only if amount of them growth (#3784)
parent
3313eedb
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
cmd/downloader/main.go
+30
-15
30 additions, 15 deletions
cmd/downloader/main.go
cmd/downloader/torrent_hashes_update.sh
+1
-1
1 addition, 1 deletion
cmd/downloader/torrent_hashes_update.sh
with
31 additions
and
16 deletions
cmd/downloader/main.go
+
30
−
15
View file @
f5a82300
...
@@ -2,8 +2,8 @@ package main
...
@@ -2,8 +2,8 @@ package main
import
(
import
(
"context"
"context"
"encoding/json"
"fmt"
"fmt"
"io/ioutil"
"net"
"net"
"os"
"os"
"path/filepath"
"path/filepath"
...
@@ -35,13 +35,13 @@ import (
...
@@ -35,13 +35,13 @@ import (
var
(
var
(
datadir
string
datadir
string
asJson
bool
forceRebuild
bool
forceRebuild
bool
forceVerify
bool
forceVerify
bool
downloaderApiAddr
string
downloaderApiAddr
string
torrentVerbosity
string
torrentVerbosity
string
downloadRateStr
,
uploadRateStr
string
downloadRateStr
,
uploadRateStr
string
torrentPort
int
torrentPort
int
targetFile
string
)
)
func
init
()
{
func
init
()
{
...
@@ -57,9 +57,12 @@ func init() {
...
@@ -57,9 +57,12 @@ func init() {
rootCmd
.
Flags
()
.
IntVar
(
&
torrentPort
,
"torrent.port"
,
42069
,
"port to listen and serve BitTorrent protocol"
)
rootCmd
.
Flags
()
.
IntVar
(
&
torrentPort
,
"torrent.port"
,
42069
,
"port to listen and serve BitTorrent protocol"
)
withDataDir
(
printTorrentHashes
)
withDataDir
(
printTorrentHashes
)
printTorrentHashes
.
PersistentFlags
()
.
BoolVar
(
&
asJson
,
"json"
,
false
,
"Print in json format (default: toml)"
)
printTorrentHashes
.
PersistentFlags
()
.
BoolVar
(
&
forceRebuild
,
"rebuild"
,
false
,
"Force re-create .torrent files"
)
printTorrentHashes
.
PersistentFlags
()
.
BoolVar
(
&
forceRebuild
,
"rebuild"
,
false
,
"Force re-create .torrent files"
)
printTorrentHashes
.
PersistentFlags
()
.
BoolVar
(
&
forceVerify
,
"verify"
,
false
,
"Force verify data files if have .torrent files"
)
printTorrentHashes
.
PersistentFlags
()
.
BoolVar
(
&
forceVerify
,
"verify"
,
false
,
"Force verify data files if have .torrent files"
)
printTorrentHashes
.
Flags
()
.
StringVar
(
&
targetFile
,
"targetfile"
,
""
,
"write output to file"
)
if
err
:=
printTorrentHashes
.
MarkFlagFilename
(
"targetfile"
);
err
!=
nil
{
panic
(
err
)
}
rootCmd
.
AddCommand
(
printTorrentHashes
)
rootCmd
.
AddCommand
(
printTorrentHashes
)
}
}
...
@@ -205,19 +208,31 @@ var printTorrentHashes = &cobra.Command{
...
@@ -205,19 +208,31 @@ var printTorrentHashes = &cobra.Command{
}
}
res
[
info
.
Name
]
=
mi
.
HashInfoBytes
()
.
String
()
res
[
info
.
Name
]
=
mi
.
HashInfoBytes
()
.
String
()
}
}
var
serialized
[]
byte
serialized
,
err
:=
toml
.
Marshal
(
res
)
if
asJson
{
if
err
!=
nil
{
serialized
,
err
=
json
.
Marshal
(
res
)
return
err
if
err
!=
nil
{
}
return
err
}
if
targetFile
==
""
{
}
else
{
fmt
.
Printf
(
"%s
\n
"
,
serialized
)
serialized
,
err
=
toml
.
Marshal
(
res
)
return
nil
if
err
!=
nil
{
}
return
err
}
oldContent
,
err
:=
ioutil
.
ReadFile
(
targetFile
)
if
err
!=
nil
{
return
err
}
oldLines
:=
map
[
string
]
string
{}
if
err
:=
toml
.
Unmarshal
(
oldContent
,
&
oldLines
);
err
!=
nil
{
return
fmt
.
Errorf
(
"unmarshal: %w"
,
err
)
}
if
len
(
oldLines
)
>=
len
(
res
)
{
log
.
Info
(
"amount of lines in target file is equal or greater than amount of lines in snapshot dir"
,
"old"
,
len
(
oldLines
),
"new"
,
len
(
res
))
return
nil
}
if
err
:=
ioutil
.
WriteFile
(
targetFile
,
serialized
,
0644
);
err
!=
nil
{
return
err
}
}
fmt
.
Printf
(
"%s
\n
"
,
serialized
)
return
nil
return
nil
},
},
}
}
...
...
This diff is collapsed.
Click to expand it.
cmd/downloader/torrent_hashes_update.sh
+
1
−
1
View file @
f5a82300
...
@@ -14,7 +14,7 @@ git pull
...
@@ -14,7 +14,7 @@ git pull
cd
../erigon
cd
../erigon
# it will return only .seg of 500K (because Erigon send to Downloader only such files)
# it will return only .seg of 500K (because Erigon send to Downloader only such files)
go run
-trimpath
./cmd/downloader torrent_hashes
--datadir
=
"
$datadir
"
>
./../erigon-snapshot/
"
$network
"
.toml
go run
-trimpath
./cmd/downloader torrent_hashes
--datadir
=
"
$datadir
"
--targetfile
=
./../erigon-snapshot/
"
$network
"
.toml
cd
./../erigon-snapshot
cd
./../erigon-snapshot
git add
"
$network
"
.toml
git add
"
$network
"
.toml
git commit
-m
"ci:
$network
"
git commit
-m
"ci:
$network
"
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment