You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by wu...@apache.org on 2022/04/03 02:32:37 UTC
[skywalking-banyandb] branch main updated: Fix NPE of stating badger kv (#97)
This is an automated email from the ASF dual-hosted git repository.
wusheng pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/skywalking-banyandb.git
The following commit(s) were added to refs/heads/main by this push:
new 3c8d162 Fix NPE of stating badger kv (#97)
3c8d162 is described below
commit 3c8d1623e2b4267e491b0c70afd7d13ab451e1df
Author: Gao Hongtao <ha...@gmail.com>
AuthorDate: Sun Apr 3 10:32:31 2022 +0800
Fix NPE of stating badger kv (#97)
---
banyand/tsdb/block.go | 26 +++++++++++++++++---------
banyand/tsdb/metric.go | 31 ++++++++++++++++++-------------
go.mod | 2 +-
go.sum | 4 ++--
4 files changed, 38 insertions(+), 25 deletions(-)
diff --git a/banyand/tsdb/block.go b/banyand/tsdb/block.go
index cafe15c..3296b26 100644
--- a/banyand/tsdb/block.go
+++ b/banyand/tsdb/block.go
@@ -20,6 +20,7 @@ package tsdb
import (
"context"
"io"
+ "path"
"strconv"
"sync"
"time"
@@ -39,6 +40,13 @@ import (
"github.com/apache/skywalking-banyandb/pkg/timestamp"
)
+const (
+ componentMain = "main"
+ componentPrimaryIdx = "primary"
+ componentSecondInvertedIdx = "inverted"
+ componentSecondLSMIdx = "lsm"
+)
+
type block struct {
path string
l *logger.Logger
@@ -108,28 +116,28 @@ func (b *block) open() (err error) {
b.ref = z.NewCloser(1)
if b.store, err = kv.OpenTimeSeriesStore(
0,
- b.path+"/store",
+ path.Join(b.path, componentMain),
kv.TSSWithEncoding(b.encodingMethod.EncoderPool, b.encodingMethod.DecoderPool),
- kv.TSSWithLogger(b.l.Named("main-store")),
+ kv.TSSWithLogger(b.l.Named(componentMain)),
); err != nil {
return err
}
if b.primaryIndex, err = lsm.NewStore(lsm.StoreOpts{
- Path: b.path + "/primary",
- Logger: b.l.Named("primary-lsm"),
+ Path: path.Join(b.path, componentPrimaryIdx),
+ Logger: b.l.Named(componentPrimaryIdx),
}); err != nil {
return err
}
b.closableLst = append(b.closableLst, b.store, b.primaryIndex)
if b.invertedIndex, err = inverted.NewStore(inverted.StoreOpts{
- Path: b.path + "/inverted",
- Logger: b.l.Named("secondary-inverted"),
+ Path: path.Join(b.path, componentSecondInvertedIdx),
+ Logger: b.l.Named(componentSecondInvertedIdx),
}); err != nil {
return err
}
if b.lsmIndex, err = lsm.NewStore(lsm.StoreOpts{
- Path: b.path + "/lsm",
- Logger: b.l.Named("secondary-lsm"),
+ Path: path.Join(b.path, componentSecondLSMIdx),
+ Logger: b.l.Named(componentSecondLSMIdx),
}); err != nil {
return err
}
@@ -179,7 +187,7 @@ func (b *block) String() string {
}
func (b *block) stats() (names []string, stats []observability.Statistics) {
- names = append(names, "main", "p-idx", "si-idx", "sl-idx")
+ names = append(names, componentMain, componentPrimaryIdx, componentSecondInvertedIdx, componentSecondLSMIdx)
stats = append(stats, b.store.Stats(), b.primaryIndex.Stats(), b.invertedIndex.Stats(), b.lsmIndex.Stats())
return names, stats
}
diff --git a/banyand/tsdb/metric.go b/banyand/tsdb/metric.go
index 9c4005b..3638bb4 100644
--- a/banyand/tsdb/metric.go
+++ b/banyand/tsdb/metric.go
@@ -71,8 +71,7 @@ func (s *shard) stat() {
s.curry(mtBytes).WithLabelValues("series").Set(float64(seriesStat.MemBytes))
s.curry(maxMtBytes).WithLabelValues("series").Set(float64(seriesStat.MaxMemBytes))
segStats := observability.Statistics{}
- blockStats := observability.Statistics{}
- localIndexStats := observability.Statistics{}
+ blockStats := newBlockStat()
for _, seg := range s.segmentController.segments() {
segStat := seg.Stats()
segStats.MaxMemBytes += segStat.MaxMemBytes
@@ -83,23 +82,20 @@ func (s *shard) stat() {
}
names, bss := b.stats()
for i, bs := range bss {
- if names[i] == "main" {
- blockStats.MaxMemBytes += bs.MaxMemBytes
- blockStats.MemBytes += bs.MemBytes
- continue
+ bsc, ok := blockStats[names[i]]
+ if ok {
+ bsc.MaxMemBytes += bs.MaxMemBytes
+ bsc.MemBytes += bs.MemBytes
}
- localIndexStats.MaxMemBytes += bs.MaxMemBytes
- localIndexStats.MemBytes += bs.MemBytes
}
-
}
}
s.curry(mtBytes).WithLabelValues("global-index").Set(float64(segStats.MemBytes))
s.curry(maxMtBytes).WithLabelValues("global-index").Set(float64(segStats.MaxMemBytes))
- s.curry(mtBytes).WithLabelValues("block").Set(float64(blockStats.MemBytes))
- s.curry(maxMtBytes).WithLabelValues("block").Set(float64(blockStats.MaxMemBytes))
- s.curry(mtBytes).WithLabelValues("local-index").Set(float64(localIndexStats.MemBytes))
- s.curry(maxMtBytes).WithLabelValues("local-index").Set(float64(localIndexStats.MaxMemBytes))
+ for name, bs := range blockStats {
+ s.curry(mtBytes).WithLabelValues(name).Set(float64(bs.MemBytes))
+ s.curry(maxMtBytes).WithLabelValues(name).Set(float64(bs.MaxMemBytes))
+ }
}
func (s *shard) curry(gv *prometheus.GaugeVec) *prometheus.GaugeVec {
@@ -109,3 +105,12 @@ func (s *shard) curry(gv *prometheus.GaugeVec) *prometheus.GaugeVec {
"shard": s.position.Shard,
})
}
+
+func newBlockStat() map[string]observability.Statistics {
+ return map[string]observability.Statistics{
+ componentMain: {},
+ componentPrimaryIdx: {},
+ componentSecondInvertedIdx: {},
+ componentSecondLSMIdx: {},
+ }
+}
diff --git a/go.mod b/go.mod
index e8db453..4f5498c 100644
--- a/go.mod
+++ b/go.mod
@@ -107,4 +107,4 @@ require (
sigs.k8s.io/yaml v1.2.0 // indirect
)
-replace github.com/dgraph-io/badger/v3 v3.2011.1 => github.com/SkyAPM/badger/v3 v3.0.0-20220331082938-b907904d6089
+replace github.com/dgraph-io/badger/v3 v3.2011.1 => github.com/SkyAPM/badger/v3 v3.0.0-20220403004319-fea65bd5e9e4
diff --git a/go.sum b/go.sum
index 4189cd5..5057b2a 100644
--- a/go.sum
+++ b/go.sum
@@ -47,8 +47,8 @@ github.com/RoaringBitmap/gocroaring v0.4.0/go.mod h1:NieMwz7ZqwU2DD73/vvYwv7r4eW
github.com/RoaringBitmap/real-roaring-datasets v0.0.0-20190726190000-eb7c87156f76/go.mod h1:oM0MHmQ3nDsq609SS36p+oYbRi16+oVvU2Bw4Ipv0SE=
github.com/RoaringBitmap/roaring v0.9.1 h1:5PRizBmoN/PfV17nPNQou4dHQ7NcJi8FO/bihdYyCEM=
github.com/RoaringBitmap/roaring v0.9.1/go.mod h1:h1B7iIUOmnAeb5ytYMvnHJwxMc6LUrwBnzXWRuqTQUc=
-github.com/SkyAPM/badger/v3 v3.0.0-20220331082938-b907904d6089 h1:MEqSQssrKviX+uU4xfAcIvvpFeTamsT3cPc9k4Ol4Ks=
-github.com/SkyAPM/badger/v3 v3.0.0-20220331082938-b907904d6089/go.mod h1:Q0luV7nB94o3Bl4hYqAPy03+QTtLxs9pWdUEQb0i0K0=
+github.com/SkyAPM/badger/v3 v3.0.0-20220403004319-fea65bd5e9e4 h1:iLwRXI6WHBMb2VkWrlYKIFngPKwgs2OnjliXdMB5DY0=
+github.com/SkyAPM/badger/v3 v3.0.0-20220403004319-fea65bd5e9e4/go.mod h1:Q0luV7nB94o3Bl4hYqAPy03+QTtLxs9pWdUEQb0i0K0=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=