Skip to content

Commit

Permalink
Add default_route_behaviour setting (#145)
Browse files Browse the repository at this point in the history
To set up failed-to-match logic in router
  • Loading branch information
reshke committed Jun 2, 2023
1 parent 23fd2a9 commit c154e38
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 2 additions & 1 deletion pkg/config/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ type Router struct {
}

type QRouter struct {
MulticastUnroutableInsertStatement bool `json:"multicast_unroutable_insert_statement" toml:"multicast_unroutable_insert_statement" yaml:"multicast_unroutable_insert_statement"`
MulticastUnroutableInsertStatement bool `json:"multicast_unroutable_insert_statement" toml:"multicast_unroutable_insert_statement" yaml:"multicast_unroutable_insert_statement"`
DefaultRouteBehaviour string `json:"default_route_behaviour" toml:"default_route_behaviour" yaml:"default_route_behaviour"`
}

type BackendRule struct {
Expand Down
7 changes: 6 additions & 1 deletion router/pkg/qrouter/proxy_routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,12 @@ func (qr *ProxyQrouter) Route(ctx context.Context, parsedStmt *pgquery.ParseResu
}

if route == nil {
return MultiMatchState{}, nil
switch qr.cfg.DefaultRouteBehaviour {
case "BLOCK":
return SkipRoutingState{}, fmt.Errorf("failed to match query to any sharding rule")
default:
return MultiMatchState{}, nil
}
}

spqrlog.Logger.Printf(spqrlog.DEBUG1, "parsed shard route %+v", route)
Expand Down

0 comments on commit c154e38

Please sign in to comment.