Don't restart garage on config change

This commit is contained in:
Brian Picciano 2025-01-01 13:07:35 +01:00
parent 03f187396b
commit c0ddd24dde
5 changed files with 44 additions and 53 deletions

View File

@ -205,7 +205,7 @@ func (c *Children) reloadGarage(
return nil return nil
} }
var anyChanged bool var anyCreated bool
for _, alloc := range allocs { for _, alloc := range allocs {
var ( var (
procName = garagePmuxProcName(alloc) procName = garagePmuxProcName(alloc)
@ -216,7 +216,7 @@ func (c *Children) reloadGarage(
) )
) )
childConfigPath, changed, err := garageWriteChildConfig( childConfigPath, err := garageWriteChildConfig(
ctx, ctx,
c.logger, c.logger,
c.garageRPCSecret, c.garageRPCSecret,
@ -227,26 +227,22 @@ func (c *Children) reloadGarage(
) )
if err != nil { if err != nil {
return fmt.Errorf("writing child config file for alloc %+v: %w", alloc, err) return fmt.Errorf("writing child config file for alloc %+v: %w", alloc, err)
} else if !changed { }
c.logger.Info(ctx, "No changes to garage config file")
if _, ok := c.garageProcs[procName]; ok {
c.logger.Info(ctx, "Garage instance already exists")
continue continue
} }
anyChanged = true anyCreated = true
if proc, ok := c.garageProcs[procName]; ok { c.logger.Info(ctx, "Garage config has been added, creating process")
c.logger.Info(ctx, "garage config has changed, restarting process")
proc.Restart()
continue
}
c.logger.Info(ctx, "garage config has been added, creating process")
c.garageProcs[procName] = garagePmuxProc( c.garageProcs[procName] = garagePmuxProc(
ctx, c.logger, c.binDirPath, procName, childConfigPath, ctx, c.logger, c.binDirPath, procName, childConfigPath,
) )
} }
if anyChanged { if anyCreated {
if err := waitForGarage( if err := waitForGarage(
ctx, ctx,
c.logger, c.logger,

View File

@ -71,7 +71,7 @@ func garageWriteChildConfig(
hostBootstrap bootstrap.Bootstrap, hostBootstrap bootstrap.Bootstrap,
alloc daecommon.ConfigStorageAllocation, alloc daecommon.ConfigStorageAllocation,
) ( ) (
string, bool, error, string, error,
) { ) {
var ( var (
thisHost = hostBootstrap.ThisHost() thisHost = hostBootstrap.ThisHost()
@ -94,10 +94,10 @@ func garageWriteChildConfig(
dbEngine, err := garagesrv.GetDBEngine(alloc.MetaPath) dbEngine, err := garagesrv.GetDBEngine(alloc.MetaPath)
if err != nil { if err != nil {
return "", false, fmt.Errorf("getting alloc db engine: %w", err) return "", fmt.Errorf("getting alloc db engine: %w", err)
} }
changed, err := garagesrv.WriteGarageTomlFile( err = garagesrv.WriteGarageTomlFile(
ctx, ctx,
logger, logger,
garageTomlPath, garageTomlPath,
@ -115,12 +115,12 @@ func garageWriteChildConfig(
) )
if err != nil { if err != nil {
return "", false, fmt.Errorf( return "", fmt.Errorf(
"creating garage.toml file at %q: %w", garageTomlPath, err, "creating garage.toml file at %q: %w", garageTomlPath, err,
) )
} }
return garageTomlPath, changed, nil return garageTomlPath, nil
} }
func garagePmuxProcName(alloc daecommon.ConfigStorageAllocation) string { func garagePmuxProcName(alloc daecommon.ConfigStorageAllocation) string {
@ -164,7 +164,7 @@ func garagePmuxProcs(
} }
for _, alloc := range allocs { for _, alloc := range allocs {
childConfigPath, _, err := garageWriteChildConfig( childConfigPath, err := garageWriteChildConfig(
ctx, ctx,
logger, logger,
rpcSecret, runtimeDirPath, adminToken, rpcSecret, runtimeDirPath, adminToken,

View File

@ -1,15 +1,15 @@
package garagesrv package garagesrv
import ( import (
"cmp" "bytes"
"context" "context"
"fmt"
"io" "io"
"slices" "os"
"strconv" "strconv"
"text/template" "text/template"
"isle/garage" "isle/garage"
"isle/toolkit"
"dev.mediocregopher.com/mediocre-go-lib.git/mlog" "dev.mediocregopher.com/mediocre-go-lib.git/mlog"
) )
@ -58,26 +58,18 @@ func RenderGarageToml(into io.Writer, data GarageTomlData) error {
} }
// WriteGarageTomlFile renders a garage.toml using the given data to a new file // WriteGarageTomlFile renders a garage.toml using the given data to a new file
// at the given path, returning true if the file changed or didn't // at the given path.
// previously exist.
func WriteGarageTomlFile( func WriteGarageTomlFile(
ctx context.Context, ctx context.Context, logger *mlog.Logger, path string, data GarageTomlData,
logger *mlog.Logger, ) error {
path string, buf := new(bytes.Buffer)
data GarageTomlData, if err := garageTomlTpl.Execute(buf, data); err != nil {
) ( return fmt.Errorf("executing template: %w", err)
bool, error, }
) {
slices.SortFunc(data.BootstrapPeers, func(i, j garage.RemoteNode) int {
return cmp.Or(
cmp.Compare(i.IP, j.IP),
cmp.Compare(i.RPCPort, j.RPCPort),
)
})
return toolkit.WriteFileCheckChanged( if err := os.WriteFile(path, buf.Bytes(), 0600); err != nil {
ctx, logger, path, 0600, func(w io.Writer) error { return fmt.Errorf("writing file: %w", err)
return garageTomlTpl.Execute(w, data) }
},
) return nil
} }

View File

@ -1,11 +0,0 @@
---
type: task
---
# Don't Restart Garage on Peer Change
When the garage configuration has changed, it is not necessary to issue a
restart to the garage processes if only the bootstrap peers have changed. Those
are only necessary on startup of garage.
Implementing this should speed up integration tests a bit.

View File

@ -0,0 +1,14 @@
---
type: task
after:
- ./garage-apply-layout-before-stopping-instance.md
---
I think there is currently a bug related to re-adding a storage allocation on an
RPC port of a garage instance which was previously used:
- Step 1) Remove a storage allocation using RPC port N
- Step 2) Add a new allocation using RPC port N, but with a new data/meta dir
I believe in this case garage will go back to using the old data/meta dir, and
possibly even re-use the old pubkey.