Compare commits

...

3 commits

Author SHA1 Message Date
de7a678640
f-8: fix: implemente readonly usage #8
All checks were successful
Pre Release Workflow / set-release-target (push) Successful in 1s
Pre Release Workflow / build (agent, amd64, linux) (push) Successful in 1m24s
Pre Release Workflow / build (db, amd64, linux) (push) Successful in 1m31s
Pre Release Workflow / build (meta_cli, amd64, linux) (push) Successful in 1m31s
Pre Release Workflow / build (metadata, amd64, linux) (push) Successful in 1m28s
Pre Release Workflow / prerelease (push) Successful in 12s
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
2026-01-02 22:51:53 +01:00
8787904833
f-8: code: add readonly feature in kv db #8
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
2026-01-02 22:51:15 +01:00
7dbb508058
f-8: fix: close db for metadata
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
2026-01-01 23:24:11 +01:00
4 changed files with 7 additions and 5 deletions

View file

@ -136,7 +136,7 @@ func main() {
DB = kv.InitDB(kv.Config{
Path: conf.Database.Path,
})
}, false)
defer DB.Close()
if len(args) < 1 {

View file

@ -31,7 +31,7 @@ func main() {
db := kv.InitDB(kv.Config{
Path: conf.Database.Path,
})
}, false)
defer db.Close()
if *start {

View file

@ -30,7 +30,8 @@ func getFromDB(config Config) NoCloudData {
conf_db, _ := configuration.LoadConfig(config.ConfFile)
db := kv.InitDB(kv.Config{Path: conf_db.Database.Path})
db := kv.InitDB(kv.Config{Path: conf_db.Database.Path}, true)
defer db.Close()
metadata, _ := kv.GetFromDB(db, "metadata/"+config.VmName+"/meta-data")
userdata, _ := kv.GetFromDB(db, "metadata/"+config.VmName+"/user-data")

View file

@ -4,8 +4,9 @@ import (
"github.com/dgraph-io/badger/v4"
)
func InitDB(conf Config) *badger.DB {
opts := badger.DefaultOptions(conf.Path)
func InitDB(conf Config, readonly bool) *badger.DB {
opts := badger.DefaultOptions(conf.Path).
WithReadOnly(readonly)
opts.Logger = nil
opts.ValueLogFileSize = 10 << 20 // 10 Mo par fichier vlog
opts.NumMemtables = 1