diff --git a/go/cmd/entrypoint/daemon.go b/go/cmd/entrypoint/daemon.go index 7b7c6e2..5175b80 100644 --- a/go/cmd/entrypoint/daemon.go +++ b/go/cmd/entrypoint/daemon.go @@ -86,6 +86,8 @@ var subCmdDaemon = subCmd{ }() } + ctx.logger.Info(ctx, "Daemon successfully started up") + <-ctx.Done() return nil }, diff --git a/go/daemon/children/garage.go b/go/daemon/children/garage.go index 3cc1a7c..4c83120 100644 --- a/go/daemon/children/garage.go +++ b/go/daemon/children/garage.go @@ -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( ctx, logger, @@ -101,6 +106,7 @@ func garageWriteChildConfig( RPCSecret: rpcSecret, AdminToken: adminToken, + DBEngine: dbEngine, LocalNode: node, BootstrapPeers: hostBootstrap.GarageNodes(), diff --git a/go/daemon/network/network_it_test.go b/go/daemon/network/network_it_test.go index 6123436..f3ffbb8 100644 --- a/go/daemon/network/network_it_test.go +++ b/go/daemon/network/network_it_test.go @@ -4,11 +4,15 @@ import ( "isle/bootstrap" "isle/daemon/daecommon" "isle/garage" + "isle/garage/garagesrv" "isle/jsonutil" "isle/nebula" + "os" + "path/filepath" "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestCreate(t *testing.T) { @@ -136,7 +140,7 @@ func TestNetwork_SetConfig(t *testing.T) { return roles } - t.Run("add storage alloc", func(t *testing.T) { + t.Run("add storage alloc/simple", func(t *testing.T) { var ( h = newIntegrationHarness(t) network = h.createNetwork(t, "primus", nil) @@ -185,6 +189,55 @@ func TestNetwork_SetConfig(t *testing.T) { layout, err := network.garageAdminClient(t).GetLayout(h.ctx) assert.NoError(t, err) 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) { diff --git a/go/garage/garagesrv/garagesrv.go b/go/garage/garagesrv/garagesrv.go index c73a93b..be9a435 100644 --- a/go/garage/garagesrv/garagesrv.go +++ b/go/garage/garagesrv/garagesrv.go @@ -14,6 +14,15 @@ import ( "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 { return filepath.Join(metaDirPath, "node_key") } @@ -150,3 +159,21 @@ func InitAlloc(metaDirPath string, initRPCPort int) (string, int, error) { 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 +} diff --git a/go/garage/garagesrv/tpl.go b/go/garage/garagesrv/tpl.go index ccf031b..1d3e23b 100644 --- a/go/garage/garagesrv/tpl.go +++ b/go/garage/garagesrv/tpl.go @@ -22,6 +22,7 @@ type GarageTomlData struct { RPCSecret string AdminToken string + DBEngine DBEngine garage.LocalNode BootstrapPeers []garage.RemoteNode @@ -30,6 +31,7 @@ type GarageTomlData struct { var garageTomlTpl = template.Must(template.New("").Parse(` metadata_dir = "{{ .MetaPath }}" data_dir = "{{ .DataPath }}" +db_engine = "{{ .DBEngine }}" replication_mode = "` + strconv.Itoa(garage.ReplicationFactor) + `"