使用KV存储实现指标统计

This commit is contained in:
GoEdgeLab
2024-04-02 19:54:04 +08:00
parent d7de2bd167
commit 4c30c28b4c
21 changed files with 1561 additions and 612 deletions

View File

@@ -162,14 +162,22 @@ func (this *Store) Delete(keyBytes []byte) error {
}
func (this *Store) NewDB(dbName string) (*DB, error) {
this.mu.Lock()
defer this.mu.Unlock()
// check existence
for _, db := range this.dbs {
if db.name == dbName {
return db, nil
}
}
// create new
db, err := NewDB(this, dbName)
if err != nil {
return nil, err
}
this.mu.Lock()
defer this.mu.Unlock()
this.dbs = append(this.dbs, db)
return db, nil
}