Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: index stats walsize #821

Merged
merged 2 commits into from
Mar 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ type cluster struct {
}

type shard struct {
// control gorutine number for read
GorutineNum int `env:"ZINC_SHARD_GORUTINE_NUM,default=3"`
// DefaultNum is the default number of shards.
Num int64 `env:"ZINC_SHARD_NUM,default=3"`
// MaxSize is the maximum size limit for one shard, or will create a new shard.
MaxSize uint64 `env:"ZINC_SHARD_MAX_SIZE,default=1073741824"`
// control gorutine number for read
GorutineNum int `env:"ZINC_SHARD_GORUTINE_NUM,default=10"`
}

type etcd struct {
Expand Down
6 changes: 6 additions & 0 deletions pkg/core/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ func (index *Index) GetStats() meta.IndexStat {
return s
}

func (index *Index) UpdateWALSize(size uint64) {
index.lock.Lock()
index.ref.Stats.WALSize = size
index.lock.Unlock()
}

func (index *Index) GetAnalyzers() map[string]*analysis.Analyzer {
index.lock.RLock()
a := index.analyzers
Expand Down
4 changes: 2 additions & 2 deletions pkg/core/index_shards_wal.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func (s *IndexShard) ConsumeWAL() bool {
if minID == maxID {
return false // no new entries
}
// log.Debug().Str("index", s.GetIndexName()).Int64("shard", s.GetID()).Uint64("minID", minID).Uint64("maxID", maxID).Msg("consume wal begin")
log.Debug().Str("index", s.GetIndexName()).Str("shard", s.GetID()).Uint64("minID", minID).Uint64("maxID", maxID).Msg("consume wal begin")

// limit max batch size
if maxID-minID > MaxBatchSize {
Expand Down Expand Up @@ -218,7 +218,7 @@ func (s *IndexShard) ConsumeWAL() bool {
return false
}
}
// log.Debug().Str("index", s.GetIndexName()).Int64("shard", s.GetID()).Uint64("minID", minID).Uint64("maxID", maxID).Msg("consume wal end")
log.Debug().Str("index", s.GetIndexName()).Str("shard", s.GetID()).Uint64("minID", minID).Uint64("maxID", maxID).Msg("consume wal end")

// Truncate log
if err = s.wal.TruncateFront(minID); err != nil {
Expand Down
3 changes: 2 additions & 1 deletion pkg/core/index_shards_wallist.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,9 @@ func (t *IndexShardWALList) ConsumeWAL() {
if size == uint64(index.GetShardNum()) {
size = 0
}
index.UpdateWALSize(size)

stats := index.GetStats()
atomic.StoreUint64(&stats.WALSize, size)
SetMetricStatsByIndex(name, "doc_num", float64(atomic.LoadUint64(&stats.DocNum)))
SetMetricStatsByIndex(name, "storage_size", float64(atomic.LoadUint64(&stats.StorageSize)/1024/1024)) // convert to MB

Expand Down