go-vise

Constrained Size Output Virtual Machine
Info | Log | Files | Refs | README | LICENSE

commit 10739fb4a8c9c1e73c8f4c90eb62ae97c0dc8938
parent 4f69d6fe59397da480afe871dcb9ffd5be296fcd
Author: lash <dev@holbrook.no>
Date:   Mon, 20 Jan 2025 12:13:01 +0000

Expose connection info in db

Diffstat:
Mcache/cache.go | 4++--
Mdb/db.go | 11+++++++++++
Mdb/fs/fs.go | 3++-
Mdb/gdbm/gdbm.go | 1+
Mdb/postgres/pg.go | 1+
Mpersist/persist.go | 4++--
6 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/cache/cache.go b/cache/cache.go @@ -69,8 +69,8 @@ func(ca *Cache) Add(key string, value string, sizeLimit uint16) error { return fmt.Errorf("Cache capacity exceeded %v of %v", ca.CacheUseSize + sz, ca.CacheSize) } } - logg.Infof("Cache add", "key", key, "size", sz, "limit", sizeLimit) - logg.Tracef("", "Cache add data", value) + logg.Debugf("Cache add", "key", key, "size", sz, "limit", sizeLimit) + logg.Tracef("Cache add data", "value", value) ca.Cache[len(ca.Cache)-1][key] = value ca.CacheUseSize += sz ca.Sizes[key] = sizeLimit diff --git a/db/db.go b/db/db.go @@ -80,6 +80,7 @@ type Db interface { Start(context.Context) error Stop(context.Context) error Abort(context.Context) + Connection() string } type LookupKey struct { @@ -124,6 +125,7 @@ type baseDb struct { lock uint8 lang *lang.Language seal bool + connStr string } // DbBase is a base class that must be extended by all db.Db implementers. @@ -273,3 +275,12 @@ func (bd *DbBase) Stop(ctx context.Context) error { func (bd *DbBase) Abort(ctx context.Context) { } + +func (bd *DbBase) Connect(ctx context.Context, connStr string) error { + bd.connStr = connStr + return nil +} + +func (bd *DbBase) Connection() string { + return bd.connStr +} diff --git a/db/fs/fs.go b/db/fs/fs.go @@ -57,7 +57,8 @@ func(fdb *fsDb) Connect(ctx context.Context, connStr string) error { if err != nil { return err } - fdb.dir = connStr + fdb.DbBase.Connect(ctx, connStr) + fdb.dir = fdb.Connection() return nil } diff --git a/db/gdbm/gdbm.go b/db/gdbm/gdbm.go @@ -84,6 +84,7 @@ func(gdb *gdbmDb) Connect(ctx context.Context, connStr string) error { } logg.DebugCtxf(ctx, "gdbm connected", "connstr", connStr) gdb.conn = db + gdb.DbBase.Connect(ctx, connStr) return nil } diff --git a/db/postgres/pg.go b/db/postgres/pg.go @@ -69,6 +69,7 @@ func(pdb *pgDb) Connect(ctx context.Context, connStr string) error { } pdb.conn = conn + pdb.DbBase.Connect(ctx, connStr) return pdb.ensureTable(ctx) } diff --git a/persist/persist.go b/persist/persist.go @@ -98,7 +98,7 @@ func(p *Persister) Save(key string) error { return err } p.db.SetPrefix(db.DATATYPE_STATE) - logg.Debugf("saving state and cache", "self", p, "key", key, "state", p.State) + logg.Infof("saving state and cache", "self", p, "key", key, "state", p.State) logg.Tracef("saving bytecode", "code", p.State.Code) err = p.db.Put(p.ctx, []byte(key), b) if err != nil { @@ -124,7 +124,7 @@ func(p *Persister) Load(key string) error { if err != nil { return err } - logg.Debugf("loaded state and cache", "self", p, "key", key, "state", p.State) + logg.Infof("loaded state and cache", "self", p, "key", key, "state", p.State) logg.Tracef("loaded bytecode", "code", p.State.Code) return nil }