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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
a
Erigon
Commits
1bfc2ffd
Unverified
Commit
1bfc2ffd
authored
Jan 3, 2022
by
Alex Sharov
Committed by
GitHub
Jan 3, 2022
Browse files
Options
Downloads
Patches
Plain Diff
Snapshots: add --to parameter to "erigon snapshots create" (#3194)
* save * save
parent
d4442af1
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
turbo/cli/snapshot.go
+38
-26
38 additions, 26 deletions
turbo/cli/snapshot.go
with
38 additions
and
26 deletions
turbo/cli/snapshot.go
+
38
−
26
View file @
1bfc2ffd
...
@@ -14,6 +14,7 @@ import (
...
@@ -14,6 +14,7 @@ import (
"github.com/ledgerwatch/erigon/cmd/hack/tool"
"github.com/ledgerwatch/erigon/cmd/hack/tool"
"github.com/ledgerwatch/erigon/cmd/utils"
"github.com/ledgerwatch/erigon/cmd/utils"
"github.com/ledgerwatch/erigon/core/rawdb"
"github.com/ledgerwatch/erigon/core/rawdb"
"github.com/ledgerwatch/erigon/params"
"github.com/ledgerwatch/erigon/turbo/snapshotsync"
"github.com/ledgerwatch/erigon/turbo/snapshotsync"
"github.com/ledgerwatch/erigon/turbo/snapshotsync/parallelcompress"
"github.com/ledgerwatch/erigon/turbo/snapshotsync/parallelcompress"
"github.com/ledgerwatch/erigon/turbo/snapshotsync/snapshothashes"
"github.com/ledgerwatch/erigon/turbo/snapshotsync/snapshothashes"
...
@@ -33,6 +34,7 @@ var snapshotCommand = cli.Command{
...
@@ -33,6 +34,7 @@ var snapshotCommand = cli.Command{
Flags
:
[]
cli
.
Flag
{
Flags
:
[]
cli
.
Flag
{
utils
.
DataDirFlag
,
utils
.
DataDirFlag
,
SnapshotFromFlag
,
SnapshotFromFlag
,
SnapshotToFlag
,
SnapshotSegmentSizeFlag
,
SnapshotSegmentSizeFlag
,
},
},
Description
:
`Create snapshots`
,
Description
:
`Create snapshots`
,
...
@@ -46,6 +48,11 @@ var (
...
@@ -46,6 +48,11 @@ var (
Usage
:
"From block number"
,
Usage
:
"From block number"
,
Required
:
true
,
Required
:
true
,
}
}
SnapshotToFlag
=
cli
.
Uint64Flag
{
Name
:
"to"
,
Usage
:
"To block number. Zero - means unlimited."
,
Required
:
true
,
}
SnapshotSegmentSizeFlag
=
cli
.
Uint64Flag
{
SnapshotSegmentSizeFlag
=
cli
.
Uint64Flag
{
Name
:
"segment.size"
,
Name
:
"segment.size"
,
Usage
:
"Amount of blocks in each segment"
,
Usage
:
"Amount of blocks in each segment"
,
...
@@ -56,6 +63,7 @@ var (
...
@@ -56,6 +63,7 @@ var (
func
doSnapshotCommand
(
ctx
*
cli
.
Context
)
error
{
func
doSnapshotCommand
(
ctx
*
cli
.
Context
)
error
{
fromBlock
:=
ctx
.
Uint64
(
SnapshotFromFlag
.
Name
)
fromBlock
:=
ctx
.
Uint64
(
SnapshotFromFlag
.
Name
)
toBlock
:=
ctx
.
Uint64
(
SnapshotToFlag
.
Name
)
segmentSize
:=
ctx
.
Uint64
(
SnapshotSegmentSizeFlag
.
Name
)
segmentSize
:=
ctx
.
Uint64
(
SnapshotSegmentSizeFlag
.
Name
)
if
segmentSize
<
1000
{
if
segmentSize
<
1000
{
return
fmt
.
Errorf
(
"too small --segment.size %d"
,
segmentSize
)
return
fmt
.
Errorf
(
"too small --segment.size %d"
,
segmentSize
)
...
@@ -66,13 +74,18 @@ func doSnapshotCommand(ctx *cli.Context) error {
...
@@ -66,13 +74,18 @@ func doSnapshotCommand(ctx *cli.Context) error {
chainDB
:=
mdbx
.
MustOpen
(
path
.
Join
(
dataDir
,
"chaindata"
))
chainDB
:=
mdbx
.
MustOpen
(
path
.
Join
(
dataDir
,
"chaindata"
))
defer
chainDB
.
Close
()
defer
chainDB
.
Close
()
if
err
:=
snapshotBlocks
(
chainDB
,
fromBlock
,
segmentSize
,
snapshotDir
);
err
!=
nil
{
if
err
:=
snapshotBlocks
(
chainDB
,
fromBlock
,
toBlock
,
segmentSize
,
snapshotDir
);
err
!=
nil
{
log
.
Error
(
"Error"
,
"err"
,
err
)
log
.
Error
(
"Error"
,
"err"
,
err
)
}
}
return
nil
return
nil
}
}
func
snapshotBlocks
(
chainDB
kv
.
RoDB
,
fromBlock
,
blocksPerFile
uint64
,
snapshotDir
string
)
error
{
func
snapshotBlocks
(
chainDB
kv
.
RoDB
,
fromBlock
,
toBlock
,
blocksPerFile
uint64
,
snapshotDir
string
)
error
{
var
last
uint64
if
toBlock
>
0
{
last
=
toBlock
}
else
{
lastChunk
:=
func
(
tx
kv
.
Tx
,
blocksPerFile
uint64
)
(
uint64
,
error
)
{
lastChunk
:=
func
(
tx
kv
.
Tx
,
blocksPerFile
uint64
)
(
uint64
,
error
)
{
c
,
err
:=
tx
.
Cursor
(
kv
.
BlockBody
)
c
,
err
:=
tx
.
Cursor
(
kv
.
BlockBody
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -83,27 +96,26 @@ func snapshotBlocks(chainDB kv.RoDB, fromBlock, blocksPerFile uint64, snapshotDi
...
@@ -83,27 +96,26 @@ func snapshotBlocks(chainDB kv.RoDB, fromBlock, blocksPerFile uint64, snapshotDi
return
0
,
err
return
0
,
err
}
}
last
:=
binary
.
BigEndian
.
Uint64
(
k
)
last
:=
binary
.
BigEndian
.
Uint64
(
k
)
// TODO: enable next condition (disabled for tests)
if
last
>
params
.
FullImmutabilityThreshold
{
//if last > params.FullImmutabilityThreshold {
last
-=
params
.
FullImmutabilityThreshold
// last -= params.FullImmutabilityThreshold
}
else
{
//} else {
last
=
0
// last = 0
}
//}
last
=
last
-
last
%
blocksPerFile
last
=
last
-
last
%
blocksPerFile
return
last
,
nil
return
last
,
nil
}
}
var
last
uint64
chainConfig
:=
tool
.
ChainConfigFromDB
(
chainDB
)
chainID
,
_
:=
uint256
.
FromBig
(
chainConfig
.
ChainID
)
_
=
chainID
if
err
:=
chainDB
.
View
(
context
.
Background
(),
func
(
tx
kv
.
Tx
)
(
err
error
)
{
if
err
:=
chainDB
.
View
(
context
.
Background
(),
func
(
tx
kv
.
Tx
)
(
err
error
)
{
last
,
err
=
lastChunk
(
tx
,
blocksPerFile
)
last
,
err
=
lastChunk
(
tx
,
blocksPerFile
)
return
err
return
err
});
err
!=
nil
{
});
err
!=
nil
{
return
err
return
err
}
}
}
chainConfig
:=
tool
.
ChainConfigFromDB
(
chainDB
)
chainID
,
_
:=
uint256
.
FromBig
(
chainConfig
.
ChainID
)
_
=
chainID
_
=
os
.
MkdirAll
(
snapshotDir
,
fs
.
ModePerm
)
_
=
os
.
MkdirAll
(
snapshotDir
,
fs
.
ModePerm
)
log
.
Info
(
"Last body number"
,
"last"
,
last
)
log
.
Info
(
"Last body number"
,
"last"
,
last
)
...
...
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