Fix extensionData database errors - make optional
Some checks failed
CI / run (push) Has been cancelled

This commit is contained in:
Umbrix Developer
2026-01-17 12:50:49 +03:00
parent f993a57755
commit 8b6f4d6f20
3 changed files with 8 additions and 15 deletions

View File

View File

@@ -67,7 +67,8 @@ func (s *extensionService) Start() error {
table := db.GetTable[extensionData]() table := db.GetTable[extensionData]()
extdata, err := table.All() extdata, err := table.All()
if err != nil { if err != nil {
return fmt.Errorf("failed to select enabled extensions: %w", err) // Extensions are optional, skip if database not available
return nil
} }
for _, data := range extdata { for _, data := range extdata {
if !data.Enable { if !data.Enable {

View File

@@ -4,28 +4,20 @@ import (
"bytes" "bytes"
"encoding/gob" "encoding/gob"
"fmt" "fmt"
"log"
"reflect" "reflect"
"time"
"github.com/syndtr/goleveldb/leveldb/opt" "github.com/syndtr/goleveldb/leveldb/opt"
tmdb "github.com/tendermint/tm-db" tmdb "github.com/tendermint/tm-db"
) )
// getDB initializes the database with retry logic. If it fails after 100 attempts, it returns nil. // getDB initializes the database. If it fails, it returns nil silently.
func getDB(name string, readOnly bool) tmdb.DB { func getDB(name string, readOnly bool) tmdb.DB {
const retryAttempts = 100 db, err := tmdb.NewGoLevelDBWithOpts(name, "./data", &opt.Options{ReadOnly: readOnly})
const retryDelay = 100 * time.Microsecond if err != nil {
// Extension database is optional, skip silently
for i := 0; i < retryAttempts; i++ { return nil
db, err := tmdb.NewGoLevelDBWithOpts(name, "./data", &opt.Options{ReadOnly: readOnly})
if err == nil {
return db
}
log.Printf("Failed attempt %d to initialize the database: %v", i, err)
time.Sleep(retryDelay)
} }
return nil return db
} }
// GetTable returns a new Table instance for the generic type T, ensuring the struct has an "Id" field. // GetTable returns a new Table instance for the generic type T, ensuring the struct has an "Id" field.