Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
acd7b369
Unverified
Commit
acd7b369
authored
Jan 11, 2022
by
Péter Szilágyi
Committed by
GitHub
Jan 11, 2022
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #24197 from rjl493456442/periodically-flush-batch
core: periodically flush the transaction indexes
parents
b1e72f7e
4bd2d0ec
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
12 deletions
+11
-12
blockchain.go
core/blockchain.go
+11
-12
No files found.
core/blockchain.go
View file @
acd7b369
...
@@ -979,32 +979,31 @@ func (bc *BlockChain) InsertReceiptChain(blockChain types.Blocks, receiptChain [
...
@@ -979,32 +979,31 @@ func (bc *BlockChain) InsertReceiptChain(blockChain types.Blocks, receiptChain [
// range. In this case, all tx indices of newly imported blocks should be
// range. In this case, all tx indices of newly imported blocks should be
// generated.
// generated.
var
batch
=
bc
.
db
.
NewBatch
()
var
batch
=
bc
.
db
.
NewBatch
()
for
_
,
block
:=
range
blockChain
{
for
i
,
block
:=
range
blockChain
{
if
bc
.
txLookupLimit
==
0
||
ancientLimit
<=
bc
.
txLookupLimit
||
block
.
NumberU64
()
>=
ancientLimit
-
bc
.
txLookupLimit
{
if
bc
.
txLookupLimit
==
0
||
ancientLimit
<=
bc
.
txLookupLimit
||
block
.
NumberU64
()
>=
ancientLimit
-
bc
.
txLookupLimit
{
rawdb
.
WriteTxLookupEntriesByBlock
(
batch
,
block
)
rawdb
.
WriteTxLookupEntriesByBlock
(
batch
,
block
)
}
else
if
rawdb
.
ReadTxIndexTail
(
bc
.
db
)
!=
nil
{
}
else
if
rawdb
.
ReadTxIndexTail
(
bc
.
db
)
!=
nil
{
rawdb
.
WriteTxLookupEntriesByBlock
(
batch
,
block
)
rawdb
.
WriteTxLookupEntriesByBlock
(
batch
,
block
)
}
}
stats
.
processed
++
stats
.
processed
++
}
// Flush all tx-lookup index data.
if
batch
.
ValueSize
()
>
ethdb
.
IdealBatchSize
||
i
==
len
(
blockChain
)
-
1
{
size
+=
int64
(
batch
.
ValueSize
())
size
+=
int64
(
batch
.
ValueSize
())
if
err
:=
batch
.
Write
();
err
!=
nil
{
if
err
=
batch
.
Write
();
err
!=
nil
{
// The tx index data could not be written.
// Roll back the ancient store update.
fastBlock
:=
bc
.
CurrentFastBlock
()
.
NumberU64
()
fastBlock
:=
bc
.
CurrentFastBlock
()
.
NumberU64
()
if
err
:=
bc
.
db
.
TruncateAncients
(
fastBlock
+
1
);
err
!=
nil
{
if
err
:=
bc
.
db
.
TruncateAncients
(
fastBlock
+
1
);
err
!=
nil
{
log
.
Error
(
"Can't truncate ancient store after failed insert"
,
"err"
,
err
)
log
.
Error
(
"Can't truncate ancient store after failed insert"
,
"err"
,
err
)
}
}
return
0
,
err
return
0
,
err
}
}
batch
.
Reset
()
}
}
// Sync the ancient store explicitly to ensure all data has been flushed to disk.
// Sync the ancient store explicitly to ensure all data has been flushed to disk.
if
err
:=
bc
.
db
.
Sync
();
err
!=
nil
{
if
err
:=
bc
.
db
.
Sync
();
err
!=
nil
{
return
0
,
err
return
0
,
err
}
}
// Update the current fast block because all block data is now present in DB.
// Update the current fast block because all block data is now present in DB.
previousFastBlock
:=
bc
.
CurrentFastBlock
()
.
NumberU64
()
previousFastBlock
:=
bc
.
CurrentFastBlock
()
.
NumberU64
()
if
!
updateHead
(
blockChain
[
len
(
blockChain
)
-
1
])
{
if
!
updateHead
(
blockChain
[
len
(
blockChain
)
-
1
])
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment