Skip to content

Commit

Permalink
client: RouteCache should account for empty Route
Browse files Browse the repository at this point in the history
This can happen if a journal has no current broker assignments.
  • Loading branch information
jgraettinger committed Oct 4, 2019
1 parent ef7098e commit 4c6fa33
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
4 changes: 1 addition & 3 deletions broker/client/route_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ func NewRouteCache(size int, ttl time.Duration) *RouteCache {

// UpdateRoute caches the provided Route for |item|, or invalidates it if |route| is nil.
func (rc *RouteCache) UpdateRoute(item string, route *pb.Route) {
if route == nil {
if route == nil || len(route.Members) == 0 {
rc.cache.Remove(item)
} else if len(route.Members) == 0 {
panic("expected members")
} else {
var cr = cachedRoute{
route: route.Copy(),
Expand Down
3 changes: 2 additions & 1 deletion broker/client/route_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ func (s *RouteCacheSuite) TestCachingCases(c *gc.C) {
// Case: Routes which have fallen out of cache are not.
c.Check(rc.Route(ctx, "A"), gc.DeepEquals, pb.Route{Primary: -1}) // Miss.

// Case: Invalidations remove routes from the cache.
// Case: Nil or empty routes invalidate the cache.
rc.UpdateRoute("C", nil)
rc.UpdateRoute("C", new(pb.Route))
c.Check(rc.Route(ctx, "C"), gc.DeepEquals, pb.Route{Primary: -1}) // Miss.

// Case: TTLs are enforced.
Expand Down

0 comments on commit 4c6fa33

Please # to comment.