Skip to content

Commit

Permalink
storage: fix compile errors
Browse files Browse the repository at this point in the history
  • Loading branch information
fanyang89 authored and 1023280072 committed Sep 6, 2023
1 parent 9cbf70c commit 23572d0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
1 change: 0 additions & 1 deletion tcpmon/cmd_ss.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,6 @@ func (m *SocketMonitor) RunSS(now time.Time) (*TcpMetric, string, error) {
var t TcpMetric
t.Timestamp = now.Unix()
t.Type = MetricType_TCP
out := ss_outp
ParseSSOutput(&t, st.Stdout)
return &t, strings.Join(st.Stdout, "\n"), nil
}
Expand Down
15 changes: 9 additions & 6 deletions tcpmon/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import (
)

type DataStore struct {
db *badger.DB
tx chan *KVPair
config DataStoreConfig
db *badger.DB
tx chan *KVPair
config DataStoreConfig
lastOpen time.Time

done chan struct{}
Expand Down Expand Up @@ -112,7 +112,7 @@ func (d *DataStore) writer(initialEpoch uint64, writeInterval time.Duration) {
d.openDatabase()
d.waitDbInit.Done()

err := d.db.Update(func(txn *badger.Txn) error {
err = d.db.Update(func(txn *badger.Txn) error {
err := txnEnsureExistsUint32(txn, KeyTotalCount)
if err != nil {
return err
Expand Down Expand Up @@ -317,16 +317,19 @@ func (d *DataStore) openDatabase() {
}

func (d *DataStore) reopenDatabase() {
d.closeDatabase()
d.openDatabase()
}

func (d *DataStore) closeDatabase() {
if d.db != nil {
err := d.db.Close()
if err != nil {
log.Warn().Err(err).Msg("Close db failed")
}
d.db = nil
}

debug.FreeOSMemory()
d.openDatabase()
}

func txnSetUint32(txn *badger.Txn, key string, value uint32) error {
Expand Down

0 comments on commit 23572d0

Please sign in to comment.