Skip to content

Commit f78ae22

Browse files
committed
fix import tool
1 parent 257c436 commit f78ae22

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

rollup/tests/integration_tool/imports.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"math/rand"
66
"sort"
7+
"strings"
78

89
"gorm.io/gorm"
910

@@ -54,7 +55,7 @@ func importData(ctx context.Context, beginBlk, endBlk uint64, chkNum, batchNum,
5455
for i, ind := range chkSepIdx {
5556
chkSep[i] = beginBlk + uint64(ind)
5657
}
57-
chkSep = append(chkSep, endBlk)
58+
chkSep = append(chkSep, endBlk+1)
5859

5960
log.Info("separated chunk", "border", chkSep)
6061
head := beginBlk
@@ -152,6 +153,15 @@ func importChunk(ctx context.Context, db *gorm.DB, beginBlk, endBlk uint64, prev
152153
func importBatch(ctx context.Context, db *gorm.DB, chks []*orm.Chunk, encChks []*encoding.Chunk, last *orm.Batch) (*orm.Batch, error) {
153154

154155
batchOrm := orm.NewBatch(db)
156+
if last == nil {
157+
var err error
158+
last, err = batchOrm.GetLatestBatch(ctx)
159+
if err != nil && !strings.Contains(err.Error(), "record not found") {
160+
return nil, err
161+
} else if last != nil {
162+
log.Info("start from last batch", "index", last.Index)
163+
}
164+
}
155165

156166
var index uint64
157167
var parentHash common.Hash

0 commit comments

Comments
 (0)