Skip to content

Commit

Permalink
[Chore] Fix S3-FIFO node loss
Browse files Browse the repository at this point in the history
  • Loading branch information
maypok86 committed Dec 2, 2023
1 parent 89c86c3 commit 202795d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 23 deletions.
17 changes: 8 additions & 9 deletions internal/s3fifo/ghost.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,20 @@ func newGhost[K comparable, V any](main *main[K, V]) *ghost[K, V] {
}

func (g *ghost[K, V]) insert(deleted []*node.Node[K, V], n *node.Node[K, V]) []*node.Node[K, V] {
if n.Meta.IsGhost() {
return deleted
}

mainLength := g.main.length()
if mainLength == 0 {
return deleted
n.Meta = n.Meta.MarkDeleted()
return append(deleted, n)
}

for g.q.Len() >= mainLength {
v := g.q.PopFront()
v.Meta = v.Meta.UnmarkGhost()
if v.Meta.IsDeleted() {
if !v.Meta.IsSmall() && !v.Meta.IsMain() {
// can remove
deleted = append(deleted, v)
}
continue
}

Expand All @@ -43,10 +44,8 @@ func (g *ghost[K, V]) insert(deleted []*node.Node[K, V], n *node.Node[K, V]) []*
}
}

if !n.Meta.IsGhost() {
g.q.PushBack(n)
n.Meta = n.Meta.MarkGhost()
}
g.q.PushBack(n)
n.Meta = n.Meta.MarkGhost()

return deleted
}
Expand Down
4 changes: 0 additions & 4 deletions internal/s3fifo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ func (m *main[K, V]) evict(deleted []*node.Node[K, V]) []*node.Node[K, V] {
if n.Meta.IsDeleted() {
n.Meta = n.Meta.UnmarkMain()
m.cost -= n.Cost()
if !n.Meta.IsSmall() && !n.Meta.IsGhost() {
// can remove
return append(deleted, n)
}
return deleted
}

Expand Down
12 changes: 2 additions & 10 deletions internal/s3fifo/small.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ func (s *small[K, V]) evict(deleted []*node.Node[K, V]) []*node.Node[K, V] {
s.cost -= n.Cost()
n.Meta = n.Meta.UnmarkSmall()
if n.Meta.IsDeleted() {
if !n.Meta.IsMain() && !n.Meta.IsGhost() {
// can remove
deleted = append(deleted, n)
}
return deleted
}
if n.IsExpired() {
Expand All @@ -58,15 +54,11 @@ func (s *small[K, V]) evict(deleted []*node.Node[K, V]) []*node.Node[K, V] {
deleted = s.main.evict(deleted)
}
n.Meta = n.Meta.ResetFrequency()
continue
}
continue
}

if !n.Meta.IsGhost() {
return s.ghost.insert(deleted, n)
}

return deleted
return s.ghost.insert(deleted, n)
}

return deleted
Expand Down

0 comments on commit 202795d

Please sign in to comment.