Skip to content

Commit

Permalink
perf: add config item commit number
Browse files Browse the repository at this point in the history
  • Loading branch information
constwz committed Jan 17, 2024
1 parent 4703b71 commit 41de69c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions base/gfspconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ type LogConfig struct {
type BlockSyncerConfig struct {
Modules []string `comment:"required"`
Workers uint `comment:"required"`
CommitNumber uint64 `comment:"optional"`
BsDBWriteAddress string `comment:"optional"`
}

Expand Down
8 changes: 4 additions & 4 deletions modular/blocksyncer/blocksyncer_indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ import (
"github.com/bnb-chain/greenfield-storage-provider/pkg/metrics"
)

func NewIndexer(codec codec.Codec, proxy node.Node, db database.Database, modules []modules.Module, serviceName string) parser.Indexer {
func NewIndexer(codec codec.Codec, proxy node.Node, db database.Database, modules []modules.Module, serviceName string, commitNumber uint64) parser.Indexer {
return &Impl{
codec: codec,
Node: proxy,
DB: db,
Modules: modules,
ServiceName: serviceName,
ProcessedHeight: 0,
eventTypeCount: 8,
CommitNumber: commitNumber,
}
}

Expand All @@ -48,7 +48,7 @@ type Impl struct {
LatestBlockHeight atomic.Value
ProcessedHeight uint64

eventTypeCount int
CommitNumber uint64

ServiceName string
}
Expand Down Expand Up @@ -193,7 +193,7 @@ func (i *Impl) Process(height uint64) error {
finalSQL := ""
finalVal := make([]interface{}, 0)
left := step
right := step + CommitNumber
right := step + int(i.CommitNumber)
if right > sqlCount {
right = sqlCount
}
Expand Down
6 changes: 5 additions & 1 deletion modular/blocksyncer/blocksyncer_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,15 @@ func (b *BlockSyncerModular) initClient(cfg *gfspconfig.GfSpConfig) error {
}
b.parserCtx = ctx
log.Infof("blocksyncer dsn : %s", config.Cfg.Database.DSN)
commitNumber := uint64(CommitNumber)
if cfg.BlockSyncer.CommitNumber != 0 {
commitNumber = cfg.BlockSyncer.CommitNumber
}
b.parserCtx.Indexer = NewIndexer(ctx.EncodingConfig.Marshaler,
ctx.Node,
ctx.Database,
ctx.Modules,
b.Name())
b.Name(), commitNumber)
return nil
}

Expand Down

0 comments on commit 41de69c

Please sign in to comment.