Skip to content

Commit

Permalink
Add couple of fields to the cacheEntry.
Browse files Browse the repository at this point in the history
  • Loading branch information
easwars committed Feb 27, 2020
1 parent 8688474 commit 853961d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
20 changes: 16 additions & 4 deletions balancer/rls/internal/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package cache

import (
"container/list"
"sync"
"time"

"google.golang.org/grpc/grpclog"
Expand All @@ -42,20 +43,31 @@ type Key struct {

// Entry wraps all the data to be stored in a cache entry.
type Entry struct {
// Mu synchronizes access to this particular cache entry. The LB policy
// will also hold another mutex to synchornize access to the cache as a
// whole. To avoid holding the top-level mutex for the whole duration for
// which one particular cache entry is acted up, we use this entry mutex.
Mu sync.Mutex
// ExpiryTime is the absolute time at which the data cached as part of this
// entry stops being valid. When an RLS request succeeds, this is set to
// the current time plus the max_age field from the LB policy config. An
// entry with this field in the past is not used to process picks.
ExpiryTime time.Time
// BackoffExpiryTime is the absolute time at which an entry which has gone
// through backoff stops being valid. When an RLS request fails, this is
// set to the current time plus twice the backoff time. The cache expiry
// timer will only delete entries for which both ExpiryTime and
// BackoffExpiryTime are in the past.
BackoffExpiryTime time.Time
// StaleTime is the absolute time after which this entry will be
// proactively refreshed if we receive a request for it. When an RLS
// request succeeds, this is set to the current time plus the stale_age
// from the LB policy config.
StaleTime time.Time
// BackoffExpiryTime is the absolute time at which the backoff period for
// this entry ends. When an RLS request fails, this is set to the current
// time plus twice the backoff time.
BackoffExpiryTime time.Time
// BackoffTime is the absolute time at which the backoff period for this
// entry ends. The backoff timer is setup with this value. No new RLS
// requests are sent out for this entry until the backoff period ends.
BackoffTime time.Time
// EarliestEvictTime is the absolute time before which this entry should
// not be evicted from the cache. This is set to a default value of 5
// seconds when the entry is created. This is required to make sure that a
Expand Down
4 changes: 3 additions & 1 deletion balancer/rls/internal/cache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
package cache

import (
"sync"
"testing"
"time"

"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
)

const testCacheMaxSize = 1000000
Expand Down Expand Up @@ -79,7 +81,7 @@ func TestGet(t *testing.T) {
for i, key := range test.keysToAdd {
lru.Add(key, test.valsToAdd[i])
}
if gotEntry := lru.Get(test.keyToGet); !cmp.Equal(gotEntry, test.wantEntry) {
if gotEntry := lru.Get(test.keyToGet); !cmp.Equal(gotEntry, test.wantEntry, cmpopts.IgnoreInterfaces(struct{ sync.Locker }{})) {
t.Errorf("lru.Get(%+v) = %+v, want %+v", test.keyToGet, gotEntry, test.wantEntry)
}
})
Expand Down

0 comments on commit 853961d

Please sign in to comment.