Skip to content

Commit

Permalink
hide url
Browse files Browse the repository at this point in the history
Signed-off-by: yisaer <[email protected]>
  • Loading branch information
Yisaer committed Jan 9, 2024
1 parent 0d596d7 commit db5683a
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions extensions/util/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/xo/dburl"

"github.com/lf-edge/ekuiper/internal/conf"
"github.com/lf-edge/ekuiper/pkg/hidden"
)

var GlobalPool *dbPool
Expand Down Expand Up @@ -61,14 +62,15 @@ func (dp *dbPool) getDBConnCount(url string) int {
}

func (dp *dbPool) createAndReplace(url string) (*sql.DB, error) {
hiddenURL, _ := hidden.HiddenURLPasswd(url)
dp.Lock()
defer dp.Unlock()
newDb, err := openDB(url, dp.isTesting)
if err != nil {
conf.Log.Errorf("create new database instance %v failed, err:%v", url, err)
conf.Log.Errorf("create new database instance %v failed, err:%v", hiddenURL, err)
return nil, err
}
conf.Log.Infof("create new database instance: %v", url)
conf.Log.Infof("create new database instance: %v", hiddenURL)
oldDB, ok := dp.pool[url]
if !ok {
dp.connections[url] = 1
Expand All @@ -81,6 +83,7 @@ func (dp *dbPool) createAndReplace(url string) (*sql.DB, error) {
}

func (dp *dbPool) getOrCreate(url string) (*sql.DB, error) {
hiddenURL, _ := hidden.HiddenURLPasswd(url)
dp.Lock()
defer dp.Unlock()
db, ok := dp.pool[url]
Expand All @@ -90,10 +93,10 @@ func (dp *dbPool) getOrCreate(url string) (*sql.DB, error) {
}
newDb, err := openDB(url, dp.isTesting)
if err != nil {
conf.Log.Errorf("create new database instance %v failed, err:%v", url, err)
conf.Log.Errorf("create new database instance %v failed, err:%v", hiddenURL, err)
return nil, err
}
conf.Log.Infof("create new database instance: %v", url)
conf.Log.Infof("create new database instance: %v", hiddenURL)
dp.pool[url] = newDb
dp.connections[url] = 1
return newDb, nil
Expand Down Expand Up @@ -134,6 +137,7 @@ func openDMDB(url string) (*sql.DB, error) {
}

func (dp *dbPool) closeOneConn(url string) error {
hiddenURL, _ := hidden.HiddenURLPasswd(url)
dp.Lock()
defer dp.Unlock()
connCount, ok := dp.connections[url]
Expand All @@ -145,7 +149,7 @@ func (dp *dbPool) closeOneConn(url string) error {
dp.connections[url] = connCount
return nil
}
conf.Log.Infof("drop database instance: %v", url)
conf.Log.Infof("drop database instance: %v", hiddenURL)
db := dp.pool[url]
// remove db instance from map in order to avoid memory leak
delete(dp.pool, url)
Expand Down

0 comments on commit db5683a

Please sign in to comment.