Skip to content

Commit

Permalink
Merge remote-tracking branch 'freecache_master/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
jb0n committed Feb 12, 2018
2 parents 80c67dc + a955dc1 commit e2d3298
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
41 changes: 41 additions & 0 deletions cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,47 @@ func TestIterator(t *testing.T) {
}
}

func TestSetLargerEntryDeletesWrongEntry(t *testing.T) {
cachesize := 512 * 1024
cache := NewCache(cachesize)

value1 := "aaa"
key1 := []byte("key1")
value := value1
cache.Set(key1, []byte(value), 0)

it := cache.NewIterator()
entry := it.Next()
if !bytes.Equal(entry.Key, key1) {
t.Fatalf("key %s not equal to %s", entry.Key, key1)
}
if !bytes.Equal(entry.Value, []byte(value)) {
t.Fatalf("value %s not equal to %s", entry.Value, value)
}
entry = it.Next()
if entry != nil {
t.Fatalf("expected nil entry but got %s %s", entry.Key, entry.Value)
}

value = value1 + "XXXXXX"
cache.Set(key1, []byte(value), 0)

value = value1 + "XXXXYYYYYYY"
cache.Set(key1, []byte(value), 0)
it = cache.NewIterator()
entry = it.Next()
if !bytes.Equal(entry.Key, key1) {
t.Fatalf("key %s not equal to %s", entry.Key, key1)
}
if !bytes.Equal(entry.Value, []byte(value)) {
t.Fatalf("value %s not equal to %s", entry.Value, value)
}
entry = it.Next()
if entry != nil {
t.Fatalf("expected nil entry but got %s %s", entry.Key, entry.Value)
}
}

func TestRace(t *testing.T) {
cache := NewCache(minBufSize)
inUse := 8
Expand Down
3 changes: 2 additions & 1 deletion segment.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ func (seg *segment) set(key, value []byte, hashVal uint64, expireSeconds int) (e
return
}
// avoid unnecessary memory copy.
seg.delEntryPtr(slotId, hash16, seg.slotsData[idx].offset)
seg.delEntryPtr(slotId, hash16, slot[idx].offset)
//seg.delEntryPtr(slotId, hash16, seg.slotsData[idx].offset)
match = false
// increase capacity and limit entry len.
for hdr.valCap < hdr.valLen {
Expand Down

0 comments on commit e2d3298

Please sign in to comment.