Skip to content

Commit

Permalink
pr feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
sanzmauro committed Nov 27, 2024
1 parent 569561b commit 028f2e3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 6 additions & 4 deletions splitio/proxy/caching/workers.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +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)
}

// remove individual entries for each affected key
Expand Down Expand Up @@ -130,6 +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)
}

for idx := range result.UpdatedKeys {
Expand Down Expand Up @@ -182,7 +184,7 @@ func (c *CacheAwareLargeSegmentSynchronizer) SynchronizeLargeSegment(name string
previous := c.largeSegmentStorage.ChangeNumber(name)
newCN, err := c.wrapped.SynchronizeLargeSegment(name, till)

c.shouldEvictBySurrogate(previous, *newCN)
c.evictByLargeSegmentSurrogate(previous, *newCN)

return newCN, err
}
Expand All @@ -199,7 +201,7 @@ func (c *CacheAwareLargeSegmentSynchronizer) SynchronizeLargeSegments() (map[str

results, err := c.wrapped.SynchronizeLargeSegments()
for name, currentCN := range results {
c.shouldEvictBySurrogate(previousCNs[name], *currentCN)
c.evictByLargeSegmentSurrogate(previousCNs[name], *currentCN)
}

return results, err
Expand All @@ -213,12 +215,12 @@ func (c *CacheAwareLargeSegmentSynchronizer) SynchronizeLargeSegmentUpdate(lsRFD
previous := c.largeSegmentStorage.ChangeNumber(lsRFDResponseDTO.Name)
newCN, err := c.wrapped.SynchronizeLargeSegmentUpdate(lsRFDResponseDTO)

c.shouldEvictBySurrogate(previous, *newCN)
c.evictByLargeSegmentSurrogate(previous, *newCN)

return newCN, err
}

func (c *CacheAwareLargeSegmentSynchronizer) shouldEvictBySurrogate(previousCN int64, currentCN int64) {
func (c *CacheAwareLargeSegmentSynchronizer) evictByLargeSegmentSurrogate(previousCN int64, currentCN int64) {
if currentCN > previousCN || currentCN == -1 {
c.cacheFlusher.EvictBySurrogate(LargeSegmentSurrogate)
}
Expand Down
2 changes: 2 additions & 0 deletions splitio/proxy/caching/workers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +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)

var segmentStorage mocks.SegmentStorageMock
segmentStorage.On("ChangeNumber", "segment1").Return(int64(0), nil).Once()
Expand Down Expand Up @@ -189,6 +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)

var segmentStorage mocks.SegmentStorageMock
segmentStorage.On("ChangeNumber", "segment2").Return(int64(0), nil).Once()
Expand Down

0 comments on commit 028f2e3

Please sign in to comment.