Correct handling of db modes
This commit is contained in:
parent
8530c45074
commit
6749c632b0
@ -65,21 +65,16 @@ func setConn() error {
|
||||
func ApplyConn(override *Override) {
|
||||
if override.DbConn != nil {
|
||||
dbConn = *override.DbConn
|
||||
dbConnMode = override.DbConnMode
|
||||
}
|
||||
dbConnMode = override.DbConnMode
|
||||
if override.StateConn != nil {
|
||||
stateDbConn = *override.StateConn
|
||||
stateDbConnMode = override.StateConnMode
|
||||
}
|
||||
if override.ResourceConn != nil {
|
||||
resourceDbConn = *override.ResourceConn
|
||||
resourceDbConnMode = override.ResourceConnMode
|
||||
}
|
||||
if override.UserConn != nil {
|
||||
userDbConn = *override.UserConn
|
||||
if override.UserConnMode != storage.DBMODE_BINARY {
|
||||
logg.Warnf("user db non-binary mode ignored")
|
||||
}
|
||||
}
|
||||
|
||||
if dbConn == "?" {
|
||||
@ -96,7 +91,17 @@ func ApplyConn(override *Override) {
|
||||
}
|
||||
if userDbConn == "?" {
|
||||
userDbConn = dbConn
|
||||
//userDbConnMode = dbConnMode
|
||||
userDbConnMode = dbConnMode
|
||||
}
|
||||
|
||||
if override.StateConnMode != storage.DBMODE_ANY {
|
||||
stateDbConnMode = override.StateConnMode
|
||||
}
|
||||
if override.ResourceConnMode != storage.DBMODE_ANY {
|
||||
resourceDbConnMode = override.ResourceConnMode
|
||||
}
|
||||
if override.UserConnMode != storage.DBMODE_ANY {
|
||||
userDbConnMode = override.UserConnMode
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,8 @@ const (
|
||||
)
|
||||
|
||||
const (
|
||||
DBMODE_BINARY DbMode = iota
|
||||
DBMODE_ANY DbMode = iota
|
||||
DBMODE_BINARY
|
||||
DBMODE_TEXT
|
||||
)
|
||||
|
||||
@ -27,6 +28,12 @@ const (
|
||||
_STORETYPE_MAX
|
||||
)
|
||||
|
||||
var (
|
||||
DbModeDebug = []string{"ANY", "BIN", "TXT"}
|
||||
DbTypeDebug = []string{"NONE", "MEM", "FS", "GDBM", "POSTGRES"}
|
||||
DbStoreDebug = []string{"STATE", "RESOURCE", "USER"}
|
||||
)
|
||||
|
||||
type Conns map[int8]ConnData
|
||||
|
||||
func NewConns() Conns {
|
||||
@ -48,8 +55,10 @@ func (c Conns) Have(conn *ConnData) int8 {
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
if v.String() == conn.String() {
|
||||
return ii
|
||||
if v.Raw() == conn.Raw() {
|
||||
if v.Mode() == DBMODE_ANY || v.Mode() == conn.Mode() {
|
||||
return ii
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1
|
||||
@ -66,8 +75,8 @@ func (cd *ConnData) DbType() int {
|
||||
return cd.typ
|
||||
}
|
||||
|
||||
func (cd *ConnData) String() string {
|
||||
return cd.str
|
||||
func (cd ConnData) String() string {
|
||||
return fmt.Sprintf("conn: %s, mod %s, typ %s", cd.str, DbModeDebug[uint8(cd.mode)], DbTypeDebug[uint8(cd.typ)])
|
||||
}
|
||||
|
||||
func (cd *ConnData) Domain() string {
|
||||
@ -83,3 +92,7 @@ func (cd *ConnData) Path() string {
|
||||
v.RawQuery = ""
|
||||
return v.String()
|
||||
}
|
||||
|
||||
func (cd *ConnData) Raw() string {
|
||||
return cd.str
|
||||
}
|
||||
|
@ -61,6 +61,7 @@ func (ms *MenuStorageService) checkDb(ctx context.Context, typ int8) db.Db {
|
||||
return store
|
||||
}
|
||||
connData := ms.conns[typ]
|
||||
logg.DebugCtxf(ctx, "db check", "conn", connData, "store", DbStoreDebug[typ])
|
||||
v := ms.conns.Have(&connData)
|
||||
if v == -1 {
|
||||
return nil
|
||||
@ -84,7 +85,7 @@ func (ms *MenuStorageService) getOrCreateDb(ctx context.Context, section string,
|
||||
}
|
||||
|
||||
connData := ms.conns[typ]
|
||||
connStr := connData.String()
|
||||
connStr := connData.Raw()
|
||||
dbTyp := connData.DbType()
|
||||
if dbTyp == DBTYPE_POSTGRES {
|
||||
// TODO: move to vise
|
||||
@ -114,7 +115,7 @@ func (ms *MenuStorageService) getOrCreateDb(ctx context.Context, section string,
|
||||
logg.WarnCtxf(ctx, "using volatile storage (memdb)")
|
||||
newDb = memdb.NewMemDb()
|
||||
} else {
|
||||
return nil, fmt.Errorf("unsupported connection string: '%s'\n", connData.String())
|
||||
return nil, fmt.Errorf("unsupported connection string: '%s'\n", connData.Raw())
|
||||
}
|
||||
logg.InfoCtxf(ctx, "connecting to db", "conn", connData, "typ", typ)
|
||||
err = newDb.Connect(ctx, connStr)
|
||||
|
Loading…
Reference in New Issue
Block a user