Skip to content

Commit

Permalink
resolves PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ankitaluthra1 committed Jul 5, 2024
1 parent e46ab93 commit d22d1bf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
8 changes: 4 additions & 4 deletions internal/cache/metadata/stat_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func (e entry) Size() (size uint64) {
}

if e.f != nil {
size = size + uint64(util.UnsafeSizeOf(&e.f))
size += uint64(util.UnsafeSizeOf(&e.f))
}

// Convert heap-size to RSS (resident set size).
Expand Down Expand Up @@ -225,7 +225,7 @@ func (sc *statCacheBucketView) LookUp(
objectName string,
now time.Time) (bool, *gcs.MinObject) {
// Look up in the LRU cache.
entry := sc.lruCacheLookup(objectName, now)
entry := sc.sharedcachelookup(objectName, now)
if entry == nil {
return false, nil
}
Expand All @@ -237,15 +237,15 @@ func (sc *statCacheBucketView) LookUpFolder(
folderName string,
now time.Time) (bool, *controlpb.Folder) {
// Look up in the LRU cache.
entry := sc.lruCacheLookup(folderName, now)
entry := sc.sharedcachelookup(folderName, now)
if entry == nil {
return false, nil
}

return true, entry.f
}

func (sc *statCacheBucketView) lruCacheLookup(key string, now time.Time) *entry {
func (sc *statCacheBucketView) sharedcachelookup(key string, now time.Time) *entry {
value := sc.sharedCache.LookUp(sc.key(key))
if value == nil {
return nil
Expand Down
11 changes: 7 additions & 4 deletions internal/cache/metadata/stat_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ func (t *MultiBucketStatCacheTest) Test_ExpiresLeastRecentlyUsed() {
assert.Equal(t.T(), saffron, spices.LookUpOrNil("saffron", someTime))
}

func (t *StatCacheTest) Test_Create_Entry_When_No_Entry_Is_Present() {
func (t *StatCacheTest) Test_InsertFolder_Create_Entry_When_No_Entry_Is_Present() {
const name = "key1"
newEntry := &controlpb.Folder{
Name: name,
Expand All @@ -434,7 +434,7 @@ func (t *StatCacheTest) Test_Create_Entry_When_No_Entry_Is_Present() {
assert.Equal(t.T(), int64(1), entry.Metageneration)
}

func (t *StatCacheTest) Test_Override_Entry_Old_Entry_Is_Already_Present() {
func (t *StatCacheTest) Test_InsertFolder_Override_Entry_Old_Entry_Is_Already_Present() {
const name = "key1"
existingEntry := &controlpb.Folder{
Name: name,
Expand Down Expand Up @@ -477,7 +477,7 @@ func (t *StatCacheTest) Test_Lookup_Return_False_When_Is_Not_Present() {
assert.Nil(t.T(), result)
}

func (t *StatCacheTest) Test_Should_Not_Override_Entry_If_Metageneration_Is_Old() {
func (t *StatCacheTest) Test_InsertFolder_Should_Not_Override_Entry_If_Metageneration_Is_Old() {
const name = "key1"
existingEntry := &controlpb.Folder{
Name: name,
Expand All @@ -497,7 +497,7 @@ func (t *StatCacheTest) Test_Should_Not_Override_Entry_If_Metageneration_Is_Old(
assert.Equal(t.T(), int64(2), entry.Metageneration)
}

func (t *StatCacheTest) Test_Should_Add_Negative_Entry_For_Folder() {
func (t *StatCacheTest) Test_AddNegativeEntryForFolder_Should_Add_Negative_Entry_For_Folder() {
const name = "key1"
existingEntry := &controlpb.Folder{
Name: name,
Expand Down Expand Up @@ -535,10 +535,13 @@ func (t *StatCacheTest) Test_Should_Evict_Entry_On_Full_Capacity_Including_Folde
t.statCache.InsertFolder(folderEntry, expiration) //adds size of 220 and exceeds capacity

hit1, entry1 = t.statCache.LookUp("1", someTime)
hit2, entry2 = t.statCache.LookUp("2", someTime)
hit3, entry3 := t.statCache.LookUpFolder("3", someTime)

assert.False(t.T(), hit1)
assert.Nil(t.T(), entry1)
assert.True(t.T(), hit2)
assert.Equal(t.T(), "2", entry2.Name)
assert.True(t.T(), hit3)
assert.Equal(t.T(), "3", entry3.Name)

Expand Down

0 comments on commit d22d1bf

Please sign in to comment.