Default to using SQLite as the garage metadata db engine
This commit is contained in:
parent
d5323964c6
commit
9407ec23c2
@ -86,6 +86,8 @@ var subCmdDaemon = subCmd{
|
|||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ctx.logger.Info(ctx, "Daemon successfully started up")
|
||||||
|
|
||||||
<-ctx.Done()
|
<-ctx.Done()
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
@ -91,6 +91,11 @@ func garageWriteChildConfig(
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
dbEngine, err := garagesrv.GetDBEngine(alloc.MetaPath)
|
||||||
|
if err != nil {
|
||||||
|
return "", false, fmt.Errorf("getting alloc db engine: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
changed, err := garagesrv.WriteGarageTomlFile(
|
changed, err := garagesrv.WriteGarageTomlFile(
|
||||||
ctx,
|
ctx,
|
||||||
logger,
|
logger,
|
||||||
@ -101,6 +106,7 @@ func garageWriteChildConfig(
|
|||||||
|
|
||||||
RPCSecret: rpcSecret,
|
RPCSecret: rpcSecret,
|
||||||
AdminToken: adminToken,
|
AdminToken: adminToken,
|
||||||
|
DBEngine: dbEngine,
|
||||||
|
|
||||||
LocalNode: node,
|
LocalNode: node,
|
||||||
BootstrapPeers: hostBootstrap.GarageNodes(),
|
BootstrapPeers: hostBootstrap.GarageNodes(),
|
||||||
|
@ -4,11 +4,15 @@ import (
|
|||||||
"isle/bootstrap"
|
"isle/bootstrap"
|
||||||
"isle/daemon/daecommon"
|
"isle/daemon/daecommon"
|
||||||
"isle/garage"
|
"isle/garage"
|
||||||
|
"isle/garage/garagesrv"
|
||||||
"isle/jsonutil"
|
"isle/jsonutil"
|
||||||
"isle/nebula"
|
"isle/nebula"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCreate(t *testing.T) {
|
func TestCreate(t *testing.T) {
|
||||||
@ -136,7 +140,7 @@ func TestNetwork_SetConfig(t *testing.T) {
|
|||||||
return roles
|
return roles
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Run("add storage alloc", func(t *testing.T) {
|
t.Run("add storage alloc/simple", func(t *testing.T) {
|
||||||
var (
|
var (
|
||||||
h = newIntegrationHarness(t)
|
h = newIntegrationHarness(t)
|
||||||
network = h.createNetwork(t, "primus", nil)
|
network = h.createNetwork(t, "primus", nil)
|
||||||
@ -185,6 +189,55 @@ func TestNetwork_SetConfig(t *testing.T) {
|
|||||||
layout, err := network.garageAdminClient(t).GetLayout(h.ctx)
|
layout, err := network.garageAdminClient(t).GetLayout(h.ctx)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.ElementsMatch(t, expRoles, layout.Roles)
|
assert.ElementsMatch(t, expRoles, layout.Roles)
|
||||||
|
|
||||||
|
t.Log("Checking that garage is using the expected db engine")
|
||||||
|
garageConfig, err := os.ReadFile(
|
||||||
|
filepath.Join(network.runtimeDir.Path, "garage-4901.toml"),
|
||||||
|
)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Contains(t,
|
||||||
|
string(garageConfig),
|
||||||
|
`db_engine = "`+garagesrv.DBEngineSqlite+`"`,
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("add storage alloc/lmdb", func(t *testing.T) {
|
||||||
|
var (
|
||||||
|
h = newIntegrationHarness(t)
|
||||||
|
network = h.createNetwork(t, "primus", nil)
|
||||||
|
networkConfig = network.getConfig(t)
|
||||||
|
dataPath = h.mkDir(t, "data").Path
|
||||||
|
metaPath = h.mkDir(t, "meta").Path
|
||||||
|
)
|
||||||
|
|
||||||
|
networkConfig.Storage.Allocations = append(
|
||||||
|
networkConfig.Storage.Allocations,
|
||||||
|
daecommon.ConfigStorageAllocation{
|
||||||
|
DataPath: dataPath,
|
||||||
|
MetaPath: metaPath,
|
||||||
|
Capacity: 1,
|
||||||
|
S3APIPort: 4900,
|
||||||
|
RPCPort: 4901,
|
||||||
|
AdminPort: 4902,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
// Creating the directory is enough to ensure that Isle chooses LMDB as
|
||||||
|
// the db engine.
|
||||||
|
lmdbPath := filepath.Join(metaPath, "db.lmdb")
|
||||||
|
require.NoError(t, os.Mkdir(lmdbPath, 0755))
|
||||||
|
|
||||||
|
assert.NoError(t, network.SetConfig(h.ctx, networkConfig))
|
||||||
|
|
||||||
|
t.Log("Checking that garage is using the expected db engine")
|
||||||
|
garageConfig, err := os.ReadFile(
|
||||||
|
filepath.Join(network.runtimeDir.Path, "garage-4901.toml"),
|
||||||
|
)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Contains(t,
|
||||||
|
string(garageConfig),
|
||||||
|
`db_engine = "`+garagesrv.DBEngineLMDB+`"`,
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("remove storage alloc", func(t *testing.T) {
|
t.Run("remove storage alloc", func(t *testing.T) {
|
||||||
|
@ -14,6 +14,15 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// DBEngine enumerates the garage db engines which are supported by Isle.
|
||||||
|
type DBEngine string
|
||||||
|
|
||||||
|
// Enumeration of DBEngine values.
|
||||||
|
const (
|
||||||
|
DBEngineLMDB DBEngine = "lmdb"
|
||||||
|
DBEngineSqlite DBEngine = "sqlite"
|
||||||
|
)
|
||||||
|
|
||||||
func nodeKeyPath(metaDirPath string) string {
|
func nodeKeyPath(metaDirPath string) string {
|
||||||
return filepath.Join(metaDirPath, "node_key")
|
return filepath.Join(metaDirPath, "node_key")
|
||||||
}
|
}
|
||||||
@ -150,3 +159,21 @@ func InitAlloc(metaDirPath string, initRPCPort int) (string, int, error) {
|
|||||||
|
|
||||||
return pubKeyStr, rpcPort, nil
|
return pubKeyStr, rpcPort, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetDBEngine returns the DBEngine currently being used at a particular meta
|
||||||
|
// data directory. Defaults to DBEngineSqlite if the directory doesn't exist or
|
||||||
|
// hasn't been fully initialized yet.
|
||||||
|
func GetDBEngine(metaDirPath string) (DBEngine, error) {
|
||||||
|
dbLMDBPath := filepath.Join(metaDirPath, "db.lmdb")
|
||||||
|
|
||||||
|
stat, err := os.Stat(dbLMDBPath)
|
||||||
|
if errors.Is(err, fs.ErrNotExist) {
|
||||||
|
return DBEngineSqlite, nil
|
||||||
|
} else if err != nil {
|
||||||
|
return "", fmt.Errorf("checking if %q exists: %w", dbLMDBPath, err)
|
||||||
|
} else if stat.IsDir() {
|
||||||
|
return DBEngineLMDB, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return DBEngineSqlite, nil
|
||||||
|
}
|
||||||
|
@ -22,6 +22,7 @@ type GarageTomlData struct {
|
|||||||
|
|
||||||
RPCSecret string
|
RPCSecret string
|
||||||
AdminToken string
|
AdminToken string
|
||||||
|
DBEngine DBEngine
|
||||||
|
|
||||||
garage.LocalNode
|
garage.LocalNode
|
||||||
BootstrapPeers []garage.RemoteNode
|
BootstrapPeers []garage.RemoteNode
|
||||||
@ -30,6 +31,7 @@ type GarageTomlData struct {
|
|||||||
var garageTomlTpl = template.Must(template.New("").Parse(`
|
var garageTomlTpl = template.Must(template.New("").Parse(`
|
||||||
metadata_dir = "{{ .MetaPath }}"
|
metadata_dir = "{{ .MetaPath }}"
|
||||||
data_dir = "{{ .DataPath }}"
|
data_dir = "{{ .DataPath }}"
|
||||||
|
db_engine = "{{ .DBEngine }}"
|
||||||
|
|
||||||
replication_mode = "` + strconv.Itoa(garage.ReplicationFactor) + `"
|
replication_mode = "` + strconv.Itoa(garage.ReplicationFactor) + `"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user