From aaef01c0d1cbcee1c59230356c946629dc76c834 Mon Sep 17 00:00:00 2001 From: Alec Thomas Date: Mon, 18 Sep 2023 22:56:50 +1000 Subject: [PATCH] fix: routing table only contained one entry (#395) Thus even with more than one replica, only a single replica would ever receive traffic. --- backend/controller/internal/dal/dal.go | 19 ++++++++++--------- .../services/echo/generated_ftl_module.go | 15 --------------- scripts/psql | 2 +- 3 files changed, 11 insertions(+), 25 deletions(-) diff --git a/backend/controller/internal/dal/dal.go b/backend/controller/internal/dal/dal.go index 24982acb24..7aa4950c5d 100644 --- a/backend/controller/internal/dal/dal.go +++ b/backend/controller/internal/dal/dal.go @@ -832,17 +832,18 @@ func (d *DAL) GetRoutingTable(ctx context.Context, modules []string) (map[string if len(routes) == 0 { return nil, errors.Wrap(ErrNotFound, "no routes found") } - return maps.FromSlice(routes, func(row sql.GetRoutingTableRow) (string, []Route) { + out := make(map[string][]Route, len(routes)) + for _, route := range routes { // This is guaranteed to be non-nil by the query, but sqlc doesn't quite understand that. - moduleName := row.ModuleName.MustGet() - return moduleName, []Route{{ + moduleName := route.ModuleName.MustGet() + out[moduleName] = append(out[moduleName], Route{ Module: moduleName, - Deployment: row.DeploymentName, - Runner: model.RunnerKey(row.RunnerKey), - Endpoint: row.Endpoint, - }} - - }), nil + Deployment: route.DeploymentName, + Runner: model.RunnerKey(route.RunnerKey), + Endpoint: route.Endpoint, + }) + } + return out, nil } func (d *DAL) GetRunnerState(ctx context.Context, runnerKey model.RunnerKey) (RunnerState, error) { diff --git a/examples/online-boutique/services/echo/generated_ftl_module.go b/examples/online-boutique/services/echo/generated_ftl_module.go index 33cf7fd52e..1e6a4c372b 100644 --- a/examples/online-boutique/services/echo/generated_ftl_module.go +++ b/examples/online-boutique/services/echo/generated_ftl_module.go @@ -4,18 +4,3 @@ package echo import ( "context" ) - -type EchoRequest struct { - Name string `json:"name"` -} - -type EchoResponse struct { - Message string `json:"message"` -} - -// Echo returns a greeting with the current time. -// -//ftl:verb -func Echo(context.Context, EchoRequest) (EchoResponse, error) { - panic("Verb stubs should not be called directly, instead use github.com/TBD54566975/ftl/runtime-go/sdk.Call()") -} diff --git a/scripts/psql b/scripts/psql index 0412d6ce36..82e1615b11 100755 --- a/scripts/psql +++ b/scripts/psql @@ -7,4 +7,4 @@ if [ -t 0 ]; then fi # shellcheck disable=SC2086 -docker exec ${flags} ftl-db-1 psql --pset pager=off -U postgres "$@" +docker exec ${flags} ftl-db-1 psql --pset pager=off --pset null='' -U postgres "$@"