Skip to content

Commit

Permalink
Merge pull request #296 from splitio/pr-feedback
Browse files Browse the repository at this point in the history
Update Mem surrogate key
  • Loading branch information
sanzmauro authored Nov 28, 2024
2 parents 7d8ee9e + 9a9a54f commit 77ed8ba
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions splitio/proxy/caching/caching.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ const (
// SplitSurrogate key (we only need one, since all splitChanges should be expired when an update is processed)
SplitSurrogate = "sp"

// LargeSegmentSurrogate key (we only need one, since all memberships should be expired when an update is processed)
LargeSegmentSurrogate = "ls"
// MembershipsSurrogate key (we only need one, since all memberships should be expired when an update is processed)
MembershipsSurrogate = "mem"

// AuthSurrogate key (having push disabled, it's safe to cache this and return it on all requests)
AuthSurrogate = "au"
Expand Down
6 changes: 3 additions & 3 deletions splitio/proxy/caching/workers.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (c *CacheAwareSegmentSynchronizer) SynchronizeSegment(name string, till *in
result, err := c.wrapped.SynchronizeSegment(name, till)
if current := result.NewChangeNumber; current > previous || (previous != -1 && current == -1) {
c.cacheFlusher.EvictBySurrogate(MakeSurrogateForSegmentChanges(name))
c.cacheFlusher.EvictBySurrogate(LargeSegmentSurrogate)
c.cacheFlusher.EvictBySurrogate(MembershipsSurrogate)
}

// remove individual entries for each affected key
Expand Down Expand Up @@ -131,7 +131,7 @@ func (c *CacheAwareSegmentSynchronizer) SynchronizeSegments() (map[string]segmen
if pcn, _ := previousCNs[segmentName]; ccn > pcn || (pcn > 0 && ccn == -1) {
// if the segment was updated or the segment was removed, evict it
c.cacheFlusher.EvictBySurrogate(MakeSurrogateForSegmentChanges(segmentName))
c.cacheFlusher.EvictBySurrogate(LargeSegmentSurrogate)
c.cacheFlusher.EvictBySurrogate(MembershipsSurrogate)
}

for idx := range result.UpdatedKeys {
Expand Down Expand Up @@ -222,6 +222,6 @@ func (c *CacheAwareLargeSegmentSynchronizer) SynchronizeLargeSegmentUpdate(lsRFD

func (c *CacheAwareLargeSegmentSynchronizer) evictByLargeSegmentSurrogate(previousCN int64, currentCN int64) {
if currentCN > previousCN || currentCN == -1 {
c.cacheFlusher.EvictBySurrogate(LargeSegmentSurrogate)
c.cacheFlusher.EvictBySurrogate(MembershipsSurrogate)
}
}
8 changes: 4 additions & 4 deletions splitio/proxy/caching/workers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func TestCacheAwareSegmentSyncSingle(t *testing.T) {
cacheFlusher.On("EvictBySurrogate", MakeSurrogateForSegmentChanges("segment1")).Times(2)
cacheFlusher.On("Evict", "/api/mySegments/k1").Times(2)
cacheFlusher.On("Evict", "gzip::/api/mySegments/k1").Times(2)
cacheFlusher.On("EvictBySurrogate", LargeSegmentSurrogate).Times(2)
cacheFlusher.On("EvictBySurrogate", MembershipsSurrogate).Times(2)

var segmentStorage mocks.SegmentStorageMock
segmentStorage.On("ChangeNumber", "segment1").Return(int64(0), nil).Once()
Expand Down Expand Up @@ -190,7 +190,7 @@ func TestCacheAwareSegmentSyncAllSegments(t *testing.T) {
cacheFlusher.On("EvictBySurrogate", MakeSurrogateForSegmentChanges("segment2")).Times(1)
cacheFlusher.On("Evict", "/api/mySegments/k1").Times(3)
cacheFlusher.On("Evict", "gzip::/api/mySegments/k1").Times(3)
cacheFlusher.On("EvictBySurrogate", LargeSegmentSurrogate).Times(3)
cacheFlusher.On("EvictBySurrogate", MembershipsSurrogate).Times(3)

var segmentStorage mocks.SegmentStorageMock
segmentStorage.On("ChangeNumber", "segment2").Return(int64(0), nil).Once()
Expand Down Expand Up @@ -242,7 +242,7 @@ func TestSynchronizeLargeSegment(t *testing.T) {

var splitStorage mocks.SplitStorageMock
var cacheFlusher mocks.CacheFlusherMock
cacheFlusher.On("EvictBySurrogate", LargeSegmentSurrogate).Once()
cacheFlusher.On("EvictBySurrogate", MembershipsSurrogate).Once()

var largeSegmentStorage mocks.LargeSegmentStorageMock
largeSegmentStorage.On("ChangeNumber", lsName).Return(int64(-1)).Once()
Expand Down Expand Up @@ -312,7 +312,7 @@ func TestSynchronizeLargeSegments(t *testing.T) {
splitStorage.On("LargeSegmentNames").Return(set.NewSet("ls1", "ls2"))

var cacheFlusher mocks.CacheFlusherMock
cacheFlusher.On("EvictBySurrogate", LargeSegmentSurrogate).Times(2)
cacheFlusher.On("EvictBySurrogate", MembershipsSurrogate).Times(2)

var cn1 int64 = 100
var cn2 int64 = 200
Expand Down
2 changes: 1 addition & 1 deletion splitio/proxy/controllers/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (c *SdkServerController) Memberships(ctx *gin.Context) {
}

ctx.JSON(http.StatusOK, payoad)
ctx.Set(caching.SurrogateContextKey, []string{caching.LargeSegmentSurrogate})
ctx.Set(caching.SurrogateContextKey, []string{caching.MembershipsSurrogate})
}

// SplitChanges Returns a diff containing changes in feature flags from a certain point in time until now.
Expand Down

0 comments on commit 77ed8ba

Please sign in to comment.