Fix extensionData database errors - make optional
Some checks failed
CI / run (push) Has been cancelled
Some checks failed
CI / run (push) Has been cancelled
This commit is contained in:
@@ -67,7 +67,8 @@ func (s *extensionService) Start() error {
|
||||
table := db.GetTable[extensionData]()
|
||||
extdata, err := table.All()
|
||||
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 {
|
||||
if !data.Enable {
|
||||
|
||||
@@ -4,28 +4,20 @@ import (
|
||||
"bytes"
|
||||
"encoding/gob"
|
||||
"fmt"
|
||||
"log"
|
||||
"reflect"
|
||||
"time"
|
||||
|
||||
"github.com/syndtr/goleveldb/leveldb/opt"
|
||||
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 {
|
||||
const retryAttempts = 100
|
||||
const retryDelay = 100 * time.Microsecond
|
||||
|
||||
for i := 0; i < retryAttempts; i++ {
|
||||
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)
|
||||
db, err := tmdb.NewGoLevelDBWithOpts(name, "./data", &opt.Options{ReadOnly: readOnly})
|
||||
if err != nil {
|
||||
// Extension database is optional, skip silently
|
||||
return nil
|
||||
}
|
||||
return nil
|
||||
return db
|
||||
}
|
||||
|
||||
// GetTable returns a new Table instance for the generic type T, ensuring the struct has an "Id" field.
|
||||
|
||||
Reference in New Issue
Block a user